files tree made better.

This commit is contained in:
Paul Schneider 2019-01-01 16:28:47 +00:00
commit ccc91bbf19
1630 changed files with 18209 additions and 41860 deletions

View file

@ -0,0 +1,167 @@
using System.Threading.Tasks;
using Yavsc.ViewModels.Auth;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Mvc;
using Microsoft.Data.Entity;
using Yavsc.Models;
using Yavsc.Models.Messaging;
using Microsoft.Extensions.Localization;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Rendering;
namespace Yavsc.Controllers
{
public class AnnouncesController : Controller
{
private ApplicationDbContext _context;
IStringLocalizer<AnnouncesController> _localizer;
IAuthorizationService _authorizationService;
public AnnouncesController(ApplicationDbContext context,
IAuthorizationService authorizationService,
IStringLocalizer<AnnouncesController> localizer)
{
_context = context;
_authorizationService = authorizationService;
_localizer = localizer;
}
// GET: Announces
public async Task<IActionResult> Index()
{
return View(await _context.Announce.ToListAsync());
}
// GET: Announces/Details/5
public async Task<IActionResult> Details(long? id)
{
if (id == null)
{
return HttpNotFound();
}
Announce announce = await _context.Announce.SingleAsync(m => m.Id == id);
if (announce == null)
{
return HttpNotFound();
}
return View(announce);
}
// GET: Announces/Create
public async Task<IActionResult> Create()
{
var model = new Announce();
await SetupView(model);
return View(model);
}
private async Task SetupView(Announce announce)
{
ViewBag.IsAdmin = User.IsInRole(Constants.AdminGroupName);
ViewBag.IsPerformer = User.IsInRole(Constants.PerformerGroupName);
ViewBag.AllowEdit = (announce!=null && announce.Id>0) ?
await _authorizationService.AuthorizeAsync(User,announce,new EditRequirement()) :
true;
List<SelectListItem> dl = new List<SelectListItem>();
var rnames = System.Enum.GetNames(typeof(Reason));
var rvalues = System.Enum.GetValues(typeof(Reason));
for (int i = 0; i<rnames.Length; i++) {
dl.Add(new SelectListItem { Text =
_localizer[rnames[i]],
Value= rvalues.GetValue(i).ToString() });
}
ViewBag.For = dl.ToArray();
}
// POST: Announces/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(Announce announce)
{
await SetupView(announce);
if (ModelState.IsValid)
{
// Only allow admin to create corporate annonces
if (announce.For == Reason.Corporate && ! ViewBag.IsAdmin)
{
ModelState.AddModelError("For", _localizer["YourNotAdmin"]);
return View(announce);
}
// Only allow performers to create ServiceProposal
if (announce.For == Reason.ServiceProposal && ! ViewBag.IsAdmin)
{
ModelState.AddModelError("For", _localizer["YourNotAPerformer"]);
return View(announce);
}
_context.Announce.Add(announce);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(announce);
}
// GET: Announces/Edit/5
public async Task<IActionResult> Edit(long? id)
{
if (id == null)
{
return HttpNotFound();
}
Announce announce = await _context.Announce.SingleAsync(m => m.Id == id);
if (announce == null)
{
return HttpNotFound();
}
return View(announce);
}
// POST: Announces/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(Announce announce)
{
if (ModelState.IsValid)
{
_context.Update(announce);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(announce);
}
// GET: Announces/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(long? id)
{
if (id == null)
{
return HttpNotFound();
}
Announce announce = await _context.Announce.SingleAsync(m => m.Id == id);
if (announce == null)
{
return HttpNotFound();
}
return View(announce);
}
// POST: Announces/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id)
{
Announce announce = await _context.Announce.SingleAsync(m => m.Id == id);
_context.Announce.Remove(announce);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
}
}

View file

@ -0,0 +1,225 @@
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.AspNet.Authorization;
using Microsoft.Data.Entity;
using Microsoft.Extensions.OptionsModel;
using Yavsc.Models;
using Yavsc.ViewModels.Auth;
using Microsoft.AspNet.Mvc.Rendering;
using Yavsc.Models.Blog;
using Yavsc.Helpers;
// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
namespace Yavsc.Controllers
{
public class BlogspotController : Controller
{
ILogger _logger;
private ApplicationDbContext _context;
private IAuthorizationService _authorizationService;
public BlogspotController(
ApplicationDbContext context,
UserManager<ApplicationUser> userManager,
ILoggerFactory loggerFactory,
IAuthorizationService authorizationService,
IOptions<SiteSettings> siteSettings)
{
_context = context;
_logger = loggerFactory.CreateLogger<AccountController>();
_authorizationService = authorizationService;
}
// GET: Blog
[AllowAnonymous]
public async Task<IActionResult> Index(string id, int skip=0, int maxLen=25)
{
if (!string.IsNullOrEmpty(id)) {
return await UserPosts(id);
}
return View();
}
[Route("/Title/{id?}")]
[AllowAnonymous]
public IActionResult Title(string id)
{
var uid = User.GetUserId();
ViewData["Title"] = id;
return View("Title", _context.Blogspot.Include(
b => b.Author
).Where(x => x.Title == id && (x.Visible || x.AuthorId == uid )).OrderByDescending(
x => x.DateCreated
).ToList());
}
[Route("/Blog/{userName}/{pageLen?}/{pageNum?}")]
[AllowAnonymous]
public async Task<IActionResult> UserPosts(string userName, int pageLen=10, int pageNum=0)
{
string posterId = (await _context.Users.SingleOrDefaultAsync(u=>u.UserName == userName))?.Id ?? null ;
var result = _context.UserPosts(posterId, User.Identity.Name);
return View("Index", result.OrderByDescending(p => p.DateCreated).ToList().Skip(pageLen*pageNum).Take(pageLen).GroupBy(p=> p.Title ));
}
// GET: Blog/Details/5
[AllowAnonymous]
public async Task<IActionResult> Details(long? id)
{
if (id == null)
{
return HttpNotFound();
}
BlogPost blog = _context.Blogspot
.Include(p => p.Author)
.Include(p => p.Tags)
.Include(p => p.Comments)
.Include(p => p.ACL)
.Single(m => m.Id == id);
if (blog == null)
{
return HttpNotFound();
}
if (!await _authorizationService.AuthorizeAsync(User, blog, new ViewRequirement()))
{
return new ChallengeResult();
}
foreach (var c in blog.Comments) {
c.Author = _context.Users.First(u=>u.Id==c.AuthorId);
}
ViewData["apicmtctlr"] = "/api/blogcomments";
ViewData["moderatoFlag"] = User.IsInRole(Constants.BlogModeratorGroupName);
return View(blog);
}
// GET: Blog/Create
[Authorize()]
public IActionResult Create(string title)
{
var result = new BlogPost{Title=title};
ViewData["PostTarget"]="Create";
return View("Edit",result);
}
// POST: Blog/Create
[HttpPost, Authorize, ValidateAntiForgeryToken]
public IActionResult Create(Models.Blog.BlogPost blog)
{
blog.Rate = 0;
blog.AuthorId = User.GetUserId();
blog.Id=0;
if (ModelState.IsValid)
{
_context.Blogspot.Add(blog);
_context.SaveChanges(User.GetUserId());
return RedirectToAction("Index");
}
ModelState.AddModelError("Unknown","Invalid Blog posted ...");
ViewData["PostTarget"]="Create";
return View("Edit",blog);
}
[Authorize()]
// GET: Blog/Edit/5
public async Task<IActionResult> Edit(long? id)
{
if (id == null)
{
return HttpNotFound();
}
ViewData["PostTarget"]="Edit";
BlogPost blog = _context.Blogspot.Include(x => x.Author).Include(x => x.ACL).Single(m => m.Id == id);
if (blog == null)
{
return HttpNotFound();
}
if (await _authorizationService.AuthorizeAsync(User, blog, new EditRequirement()))
{
ViewBag.ACL = _context.Circle.Where(
c=>c.OwnerId == blog.AuthorId)
.Select(
c => new SelectListItem
{
Text = c.Name,
Value = c.Id.ToString(),
Selected = blog.AuthorizeCircle(c.Id)
} 
);
return View(blog);
}
else
{
return new ChallengeResult();
}
}
// POST: Blog/Edit/5
[HttpPost]
[ValidateAntiForgeryToken,Authorize()]
public IActionResult Edit(BlogPost blog)
{
if (ModelState.IsValid)
{
var auth = _authorizationService.AuthorizeAsync(User, blog, new EditRequirement());
if (auth.Result)
{
// saves the change
_context.Update(blog);
_context.SaveChanges(User.GetUserId());
ViewData["StatusMessage"] = "Post modified";
return RedirectToAction("Index");
}
else
{
ViewData["StatusMessage"] = "Accès restreint";
return new ChallengeResult();
}
}
ViewData["PostTarget"]="Edit";
return View(blog);
}
// GET: Blog/Delete/5
[ActionName("Delete"),Authorize()]
public IActionResult Delete(long? id)
{
if (id == null)
{
return HttpNotFound();
}
BlogPost blog = _context.Blogspot.Include(
b => b.Author
).Single(m => m.Id == id);
if (blog == null)
{
return HttpNotFound();
}
return View(blog);
}
// POST: Blog/Delete/5
[HttpPost, ActionName("Delete"), Authorize()]
[ValidateAntiForgeryToken]
public IActionResult DeleteConfirmed(long id)
{
BlogPost blog = _context.Blogspot.Single(m => m.Id == id);
var auth = _authorizationService.AuthorizeAsync(User, blog, new EditRequirement());
if (auth.Result)
{
_context.Blogspot.Remove(blog);
_context.SaveChanges(User.GetUserId());
}
return RedirectToAction("Index");
}
}
}

View file

@ -0,0 +1,122 @@
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.Data.Entity;
using Yavsc.Models;
using Yavsc.Models.Relationship;
namespace Yavsc.Controllers
{
public class CircleController : Controller
{
private ApplicationDbContext _context;
public CircleController(ApplicationDbContext context)
{
_context = context;
}
// GET: Circle
public async Task<IActionResult> Index()
{
return View(await _context.Circle.ToListAsync());
}
// GET: Circle/Details/5
public async Task<IActionResult> Details(long? id)
{
if (id == null)
{
return HttpNotFound();
}
Circle circle = await _context.Circle.SingleAsync(m => m.Id == id);
if (circle == null)
{
return HttpNotFound();
}
return View(circle);
}
// GET: Circle/Create
public IActionResult Create()
{
return View();
}
// POST: Circle/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(Circle circle)
{
if (ModelState.IsValid)
{
_context.Circle.Add(circle);
await _context.SaveChangesAsync(User.GetUserId());
return RedirectToAction("Index");
}
return View(circle);
}
// GET: Circle/Edit/5
public async Task<IActionResult> Edit(long? id)
{
if (id == null)
{
return HttpNotFound();
}
Circle circle = await _context.Circle.SingleAsync(m => m.Id == id);
if (circle == null)
{
return HttpNotFound();
}
return View(circle);
}
// POST: Circle/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(Circle circle)
{
if (ModelState.IsValid)
{
_context.Update(circle);
await _context.SaveChangesAsync(User.GetUserId());
return RedirectToAction("Index");
}
return View(circle);
}
// GET: Circle/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(long? id)
{
if (id == null)
{
return HttpNotFound();
}
Circle circle = await _context.Circle.SingleAsync(m => m.Id == id);
if (circle == null)
{
return HttpNotFound();
}
return View(circle);
}
// POST: Circle/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id)
{
Circle circle = await _context.Circle.SingleAsync(m => m.Id == id);
_context.Circle.Remove(circle);
await _context.SaveChangesAsync(User.GetUserId());
return RedirectToAction("Index");
}
}
}

View file

@ -0,0 +1,135 @@
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.Data.Entity;
using Yavsc.Models;
using Yavsc.Models.Relationship;
namespace Yavsc.Controllers
{
public class CircleMembersController : Controller
{
private ApplicationDbContext _context;
public CircleMembersController(ApplicationDbContext context)
{
_context = context;
}
// GET: CircleMembers
public async Task<IActionResult> Index()
{
var uid = User.GetUserId();
var applicationDbContext = _context.CircleMembers.Include(c => c.Circle).Include(c => c.Member)
.Where(c=>c.Circle.OwnerId == uid);
return View(await applicationDbContext.ToListAsync());
}
// GET: CircleMembers/Details/5
public async Task<IActionResult> Details(long id)
{
var uid = User.GetUserId();
CircleMember circleMember = await _context.CircleMembers
.Include(m=>m.Circle)
.FirstOrDefaultAsync(c=>c.CircleId == id);
if (circleMember == null)
{
return HttpNotFound();
}
return View(circleMember);
}
// GET: CircleMembers/Create
public IActionResult Create()
{
var uid = User.GetUserId();
ViewBag.CircleId = new SelectList(_context.Circle.Where(c=>c.OwnerId == uid), "Id", "Name");
ViewBag.MemberId = new SelectList(_context.Users, "Id", "UserName");
return View();
}
// POST: CircleMembers/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(CircleMember circleMember)
{
var uid = User.GetUserId();
var circle = _context.Circle.SingleOrDefault(c=>c.OwnerId == uid && c.Id == circleMember.CircleId);
if (circle==null)
return new BadRequestResult();
if (ModelState.IsValid)
{
_context.CircleMembers.Add(circleMember);
await _context.SaveChangesAsync(User.GetUserId());
return RedirectToAction("Index");
}
ViewData["CircleId"] = new SelectList(_context.Circle, "Id", "Name", circleMember.CircleId);
ViewData["MemberId"] = new SelectList(_context.Users, "Id", "UserName", circleMember.MemberId);
return View(circleMember);
}
// GET: CircleMembers/Edit/5
public async Task<IActionResult> Edit(long id)
{
var uid = User.GetUserId();
CircleMember circleMember = await _context.CircleMembers
.Include(m=>m.Member)
.SingleOrDefaultAsync(m => m.CircleId == id && m.MemberId == uid);
if (circleMember == null)
{
return HttpNotFound();
}
return View(circleMember);
}
// POST: CircleMembers/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(CircleMember circleMember)
{
if (ModelState.IsValid)
{
_context.Update(circleMember);
await _context.SaveChangesAsync(User.GetUserId());
return RedirectToAction("Index");
}
ViewData["CircleId"] = new SelectList(_context.Circle, "Id", "Circle", circleMember.CircleId);
ViewData["MemberId"] = new SelectList(_context.Users, "Id", "Member", circleMember.MemberId);
return View(circleMember);
}
// GET: CircleMembers/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(long id)
{
var uid = User.GetUserId();
CircleMember circleMember = await _context.CircleMembers
.Include(m=>m.Circle)
.Include(m=>m.Member)
.SingleOrDefaultAsync(m => m.CircleId == id && m.MemberId == uid);
if (circleMember == null)
{
return HttpNotFound();
}
return View(circleMember);
}
// POST: CircleMembers/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id)
{
CircleMember circleMember = await _context.CircleMembers.SingleAsync(m => m.CircleId == id);
_context.CircleMembers.Remove(circleMember);
await _context.SaveChangesAsync(User.GetUserId());
return RedirectToAction("Index");
}
}
}

View file

@ -0,0 +1,129 @@
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.Data.Entity;
using Yavsc.Models;
using Yavsc.Models.Blog;
namespace Yavsc.Controllers
{
public class CommentsController : Controller
{
private ApplicationDbContext _context;
public CommentsController(ApplicationDbContext context)
{
_context = context;
}
// GET: Comments
public async Task<IActionResult> Index()
{
var applicationDbContext = _context.Comment.Include(c => c.Post);
return View(await applicationDbContext.ToListAsync());
}
// GET: Comments/Details/5
public async Task<IActionResult> Details(long? id)
{
if (id == null)
{
return HttpNotFound();
}
Comment comment = await _context.Comment.SingleAsync(m => m.Id == id);
if (comment == null)
{
return HttpNotFound();
}
return View(comment);
}
// GET: Comments/Create
public IActionResult Create()
{
ViewData["PostId"] = new SelectList(_context.Blogspot, "Id", "Post");
return View();
}
// POST: Comments/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(Comment comment)
{
comment.UserCreated = User.GetUserId();
if (ModelState.IsValid)
{
_context.Comment.Add(comment);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
ViewData["PostId"] = new SelectList(_context.Blogspot, "Id", "Post", comment.PostId);
return View(comment);
}
// GET: Comments/Edit/5
public async Task<IActionResult> Edit(long? id)
{
if (id == null)
{
return HttpNotFound();
}
Comment comment = await _context.Comment.SingleAsync(m => m.Id == id);
if (comment == null)
{
return HttpNotFound();
}
ViewData["PostId"] = new SelectList(_context.Blogspot, "Id", "Post", comment.PostId);
return View(comment);
}
// POST: Comments/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(Comment comment)
{
if (ModelState.IsValid)
{
_context.Update(comment);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
ViewData["PostId"] = new SelectList(_context.Blogspot, "Id", "Post", comment.PostId);
return View(comment);
}
// GET: Comments/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(long? id)
{
if (id == null)
{
return HttpNotFound();
}
Comment comment = await _context.Comment.SingleAsync(m => m.Id == id);
if (comment == null)
{
return HttpNotFound();
}
return View(comment);
}
// POST: Comments/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id)
{
Comment comment = await _context.Comment.SingleAsync(m => m.Id == id);
_context.Comment.Remove(comment);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
}
}

View file

@ -0,0 +1,78 @@
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.Data.Entity;
namespace Yavsc.Controllers
{
using Models;
using Models.Identity;
public class GCMDevicesController : Controller
{
private ApplicationDbContext _context;
public GCMDevicesController(ApplicationDbContext context)
{
_context = context;
}
// GET: GCMDevices
public async Task<IActionResult> Index()
{
var uid = User.GetUserId();
var applicationDbContext = _context.GCMDevices.Include(g => g.DeviceOwner).Where(d=>d.DeviceOwnerId == uid);
return View(await applicationDbContext.ToListAsync());
}
// GET: GCMDevices/Details/5
public async Task<IActionResult> Details(string id)
{
if (id == null)
{
return HttpNotFound();
}
GoogleCloudMobileDeclaration googleCloudMobileDeclaration = await _context.GCMDevices.SingleAsync(m => m.DeviceId == id);
if (googleCloudMobileDeclaration == null)
{
return HttpNotFound();
}
return View(googleCloudMobileDeclaration);
}
// GET: GCMDevices/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(string id)
{
if (id == null)
{
return HttpNotFound();
}
GoogleCloudMobileDeclaration googleCloudMobileDeclaration = await _context.GCMDevices.SingleAsync(m => m.DeviceId == id);
if (googleCloudMobileDeclaration == null)
{
return HttpNotFound();
}
return View(googleCloudMobileDeclaration);
}
// POST: GCMDevices/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(string id)
{
GoogleCloudMobileDeclaration googleCloudMobileDeclaration = await _context.GCMDevices.SingleAsync(m => m.DeviceId == id);
_context.GCMDevices.Remove(googleCloudMobileDeclaration);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
}
}

View file

@ -0,0 +1,83 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Net.WebSockets;
using System.Security.Claims;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.Extensions.Logging;
using Yavsc.ViewModels.Streaming;
namespace Yavsc.Controllers.Communicating
{
public class LiveController : Controller
{
ILogger _logger;
public static ConcurrentDictionary<string, LiveCastMeta> Casters = new ConcurrentDictionary<string, LiveCastMeta>();
public LiveController(LoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<LiveController>();
}
public async Task<IActionResult> Cast()
{
var uname = User.GetUserName();
// ensure this request is for a websocket
if (!HttpContext.WebSockets.IsWebSocketRequest) return new BadRequestResult();
// ensure uniqueness of casting stream from this user
var existent = Casters[uname];
if (existent != null) return new BadRequestObjectResult("not supported, you already casting, there's support for one live streaming only");
var meta = new LiveCastMeta { Socket = await HttpContext.WebSockets.AcceptWebSocketAsync() };
using (meta.Socket)
{
if (meta.Socket != null && meta.Socket.State == WebSocketState.Open)
{
Casters[uname] = meta;
// TODO: Handle the socket here.
// Find receivers: others in the chat room
// send them the flow
byte[] buffer = new byte[1024];
WebSocketReceiveResult received = await meta.Socket.ReceiveAsync
(new ArraySegment<byte>(buffer), CancellationToken.None);
// FIXME do we really need to close those one in invalid state ?
Stack<string> ToClose = new Stack<string>();
while (received.MessageType != WebSocketMessageType.Close)
{
_logger.LogInformation($"Echoing {received.Count} bytes received in a {received.MessageType} message; Fin={received.EndOfMessage}");
// Echo anything we receive
// and send to all listner found
foreach (var cliItem in meta.Listeners)
{
var listenningSocket = cliItem.Value;
if (listenningSocket.State == WebSocketState.Open)
await listenningSocket.SendAsync(new ArraySegment<byte>
(buffer, 0, received.Count), received.MessageType, received.EndOfMessage, CancellationToken.None);
else ToClose.Push(cliItem.Key);
}
received = await meta.Socket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
string no;
do
{
no = ToClose.Pop();
WebSocket listenningSocket;
if (meta.Listeners.TryRemove(no, out listenningSocket))
await listenningSocket.CloseAsync(WebSocketCloseStatus.EndpointUnavailable, "State != WebSocketState.Open", CancellationToken.None);
} while (no != null);
}
await meta.Socket.CloseAsync(received.CloseStatus.Value, received.CloseStatusDescription, CancellationToken.None);
Casters[uname] = null;
}
else _logger.LogInformation($"failed (meta.Socket != null && meta.Socket.State == WebSocketState.Open)");
}
return Ok();
}
}
}

View file

@ -0,0 +1,121 @@
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.Data.Entity;
using Yavsc.Models;
using Yavsc.Models.Messaging;
namespace Yavsc.Controllers
{
public class NotificationsController : Controller
{
private ApplicationDbContext _context;
public NotificationsController(ApplicationDbContext context)
{
_context = context;
}
// GET: Notifications
public async Task<IActionResult> Index()
{
return View(await _context.Notification.ToListAsync());
}
// GET: Notifications/Details/5
public async Task<IActionResult> Details(long? id)
{
if (id == null)
{
return HttpNotFound();
}
Notification notification = await _context.Notification.SingleAsync(m => m.Id == id);
if (notification == null)
{
return HttpNotFound();
}
return View(notification);
}
// GET: Notifications/Create
public IActionResult Create()
{
return View();
}
// POST: Notifications/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(Notification notification)
{
if (ModelState.IsValid)
{
_context.Notification.Add(notification);
await _context.SaveChangesAsync(User.GetUserId());
return RedirectToAction("Index");
}
return View(notification);
}
// GET: Notifications/Edit/5
public async Task<IActionResult> Edit(long? id)
{
if (id == null)
{
return HttpNotFound();
}
Notification notification = await _context.Notification.SingleAsync(m => m.Id == id);
if (notification == null)
{
return HttpNotFound();
}
return View(notification);
}
// POST: Notifications/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(Notification notification)
{
if (ModelState.IsValid)
{
_context.Update(notification);
await _context.SaveChangesAsync(User.GetUserId());
return RedirectToAction("Index");
}
return View(notification);
}
// GET: Notifications/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(long? id)
{
if (id == null)
{
return HttpNotFound();
}
Notification notification = await _context.Notification.SingleAsync(m => m.Id == id);
if (notification == null)
{
return HttpNotFound();
}
return View(notification);
}
// POST: Notifications/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id)
{
Notification notification = await _context.Notification.SingleAsync(m => m.Id == id);
_context.Notification.Remove(notification);
await _context.SaveChangesAsync(User.GetUserId());
return RedirectToAction("Index");
}
}
}