/// <summary> /// Soft-deletes the user. /// </summary> /// <returns></returns> public async Task <bool> DeleteAsync(ChatContext chatContext) { FirstName = null; LastName = null; ProfileDescription = null; IsEnabled = false; foreach (Membership m in Memberships) { chatContext.Remove(m); } foreach (GroupJoinInvitation i in GroupJoinInvitations) { chatContext.Remove(i); } foreach (PersonalChatInvitation i in PersonalChatInvitations) { chatContext.Remove(i); } foreach (Notification n in Notifications) { chatContext.Remove(n); } await chatContext.SaveChangesAsync(); return(true); }
public Message Delete(Message message) { var messageDeleted = _context.Remove(message); _context.SaveChanges(); return(messageDeleted.Entity); }
public override async Task OnDisconnectedAsync(Exception exception) { User user = await _context.Users.Include(i => i.Role) .FirstOrDefaultAsync(u => u.UserId == Guid.Parse(Context.UserIdentifier)); var dialog = _context.Dialogs .FirstOrDefault(f => f.ClientUserUserId == Guid.Parse(Context.UserIdentifier) || f.EmployeeUserUserId == Guid.Parse(Context.UserIdentifier)); if (dialog != null) { var userOnline = dialog.ClientUserUserId.ToString() == Context.UserIdentifier ? dialog.EmployeeUserUserId : dialog.ClientUserUserId; if (userOnline != _botId) { await Clients.User(userOnline.ToString()).Receive(new Message() { Text = "Disconected", DialogId = dialog.DialogId }); } _context.Remove(dialog); _usersDialog.Remove(dialog.DialogId); } if (user != null && user.Role.Name == "EMPLOYEE") { _context.Employees.FirstOrDefault(f => f.UserUserId == user.UserId).StatusOnline = false; } _context.SaveChanges(); await base.OnDisconnectedAsync(exception); }
public async Task <IActionResult> UserPage(string link, string info, string sourceLink, string targetLink, string buttonType) { UserInfo user = context.Users.SingleOrDefault(u => u.Username == User.Identity.Name); if (buttonType == "Добавить") { IQueryable <Link> findLink = from contextLink in context.Links where (user.Username == contextLink.Sender.Username) && (contextLink.Text == link) select contextLink; if (!findLink.Any() && !link.IsNullOrEmpty()) { Link msg = new Link() { Text = link, Sender = user, Info = info }; await context.Links.AddAsync(msg); await context.SaveChangesAsync(); } else { ViewBag.message = "<script>alert('Введите корректную и неповторяющуюся ссылку')</script>"; } } if (buttonType == "Удалить") { IQueryable <Link> findLink = from contextLink in context.Links where (user.Username == contextLink.Sender.Username) && (contextLink.Text == link) select contextLink; if (findLink.Any()) { try { foreach (var line in findLink) { context.Remove(line); } } catch (Exception e) { ViewBag.message = "<script>alert('Ошибка при удалении')</script>"; Console.WriteLine("Ошибка при удалении"); throw; } } await context.SaveChangesAsync(); } if (buttonType == "Изменить") { IQueryable <Link> findLink = from contextLink in context.Links where (user.Username == contextLink.Sender.Username) && (contextLink.Text == sourceLink) select contextLink; IQueryable <Link> repeatLink = from contextLink in context.Links where (user.Username == contextLink.Sender.Username) && (contextLink.Text == targetLink) select contextLink; if (findLink.Any() && !repeatLink.Any()) { try { foreach (var line in findLink) { line.Text = targetLink; } } catch (Exception e) { ViewBag.message = "<script>alert('Ошибка при изменении')</script>"; Console.WriteLine("Ошибка при изменении"); throw; } } else { ViewBag.message = "<script>alert('Ошибка при изменении')</script>"; Console.WriteLine("Ошибка при изменении"); } await context.SaveChangesAsync(); } return(View(context.Links.ToList())); }