public ActionResult <Operation> UpdateOperation(int id, OperationsUpdateDto operationsUpdateDto) { var operation = _operationsRepository.GetById(id); if (operation == null) { return(NotFound()); } _mapper.Map(operationsUpdateDto, operation); _operationsRepository.Update(operation); // Best practice _operationsRepository.SaveChanges(); _notificationHub.Clients.All.SendAsync("SendMessage", "OperationUpdated"); _notificationHub.Clients.All.SendAsync("Notification", "Всем спасибо! Все свободны!"); return(NoContent()); }
public ActionResult <IEnumerable <User> > AddUsersToOperations() { //var activeOperation = _operationRepository.GetActiveOperation(UserId); var activeOperationId = _operationRepository.GetActiveOperationId(UserId); var activeOperation = _operationRepository.GetById(activeOperationId); var users = _userRepository.Get(UserRoleId: 4, UserStatusId: 2).ToList(); users.AddRange(_userRepository.Get(UserRoleId: 4, UserStatusId: 3).ToList()); var activeOperationUsers = _userRepository.Get(activeOperationId).ToList(); var usersToAdd = activeOperationUsers; foreach (var user in users) { if (!activeOperationUsers.Any(c => c.Id == user.Id)) { usersToAdd.Add(user); } } activeOperation.Users = usersToAdd; //foreach (var user in users) //{ // activeOperation.Users.Append(user); //} _operationRepository.Update(activeOperation); // Best practice _operationRepository.SaveChanges(); _notificationHub.Clients.All.SendAsync("SendMessage", "У вас новая операция"); _notificationHub.Clients.All.SendAsync("Notification", "Вам назначена новая операция"); return(Ok()); }