public void MarkNotificationSeen([FromBody] NotificationDto dto) { var notification = _context.Notifications.Find(dto.NotificationId); notification.Status = NotificationStatus.Seen; _context.Update(notification); _context.SaveChanges(); }
public void NotifyEnsembleMembers(int userId, int ensembleId, string text, string url) { var memberIds = _context.EnsembleMembers .Where(em => em.EnsembleId == ensembleId && em.Status == RequestStatus.Accepted) .Select(em => em.UserIdRecipient) .ToArray(); foreach (var memberId in memberIds) { if (userId == memberId) { continue; } var oldNotification = _context.Notifications .FirstOrDefault(n => n.UserId == memberId && n.Url == url); if (oldNotification != null) { oldNotification.Status = NotificationStatus.Unseen; oldNotification.Text = text; oldNotification.Timestamp = DateTime.Now; _context.Update(oldNotification); } else { _context.Notifications.Add(new Notification { UserId = memberId, Text = text, Url = url }); } } }
public OkObjectResult ChangePassword([FromBody] PasswordChangeDto dto) { var userId = GetUserId(); var user = _context.Users.Find(userId); if (!BCrypt.Net.BCrypt.Verify(dto.OldPassword, user.Password) || dto.OldPassword != dto.OldPasswordConfirm) { return(new OkObjectResult(new { success = false, error = "Password mismatch" })); } user.Password = dto.NewPassword; _context.Update(user); _context.SaveChanges(); return(new OkObjectResult(new { success = true })); }