public ActionResult BannedPage() { Entity.User user = aService.GetUser(User.Identity.GetUserId <int>()); BanAccount model = user.BannedAccounts.Where(b => b.UnBanedDate > DateTime.Now).FirstOrDefault(); return(View(model)); }
public HttpResponseMessage Post([FromBody] BanAccountModel ba) { try { using (WebbanhangDBEntities entities = new WebbanhangDBEntities()) { entities.Configuration.ProxyCreationEnabled = false; BanAccount banacc = new BanAccount(); banacc.UserID = ba.UserID; banacc.Reason = ba.Reason; banacc.LiftDate = Convert.ToDateTime(ba.LiftDate); entities.BanAccounts.Add(banacc); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, "POST OK")); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public ActionResult BlockUser(BlockUserViewModel model) { BanAccount banAccount = new BanAccount(); banAccount.BannedDate = DateTime.Now; banAccount.Duration = model.Duration; banAccount.UnBanedDate = DateTime.Now.AddDays(banAccount.Duration); banAccount.BannedUser = cService.GetUser(model.BannedUserId); banAccount.BannedUser.Status = UserStatusEnum.Banned; banAccount.BanUser = cService.GetUser(User.Identity.GetUserId <int>()); banAccount.Description = model.Description; banAccount.BanReasons = aService.GetListBanReason(model.Reasons); aService.BlockUser(banAccount); Notification notification = new Notification(); notification.AuthorId = _currentUserId; notification.CreatedDate = DateTime.Now; notification.Content = banAccount.Duration + " ngày. Bắt đầu từ ngày " + banAccount.BannedDate.ToShortDateString(); notification.Seen = false; notification.Type = NotificationSettingEnum.Banned; notification.UserId = model.BannedUserId; notification.Link = Url.Action("BannedPage", "Account"); cService.AddNotification(notification); using (RealTimeService rService = new RealTimeService(new CPMathHubModelContainer(), notification.UserId)) { IEnumerable <string> connectionIds = RealTimeHub.Connections.GetConnections(notification.UserId); foreach (string conId in connectionIds) { _hub.Clients.Client(conId).notifyNewActivity(rService.CountNewActivityNotification()); } } return(PartialView("Partials/_HistoryBlockUserPartialView", banAccount.BannedUser)); }
public void BlockUser(BanAccount banAccount) { dal.Repository <BanAccount>().Insert(banAccount); dal.Save(); //aService.UpdateUser(banAccount.BannedUser); }