public EditDialogModel ToEditDialog(IUserProvider userProvider) { var outcome = new EditDialogModel() { Name = Name, Creator = Creator, Participants = Participants.ToList().ConvertAll(x => userProvider.GetUser(Guid.Parse(x))), }; return(outcome); }
public ActionResult Edit(string id, EditDialogModel model) { try { var status = _dialogProvider.ChangeDialog(Guid.Parse(id), model); if (status.StatusCode == System.Net.HttpStatusCode.OK) { return(RedirectToAction(nameof(Index))); } else { return(View(model)); } } catch { return(View(model)); } }
public StatusExecution ChangeDialog(Guid uuid, EditDialogModel edDialog) { var dialog = _dialogsProvider.GetQueryable().FirstOrDefault(x => x.Uuid == uuid); if (dialog == null) { return(new StatusExecution() { StatusCode = HttpStatusCode.BadRequest, Message = "Диалога не существует" }); } if (dialog.Creator != edDialog.Creator) { return(new StatusExecution() { StatusCode = HttpStatusCode.BadRequest, Message = "Данный пользователь не может изменить диалог" }); } dialog.Name = edDialog.Name; edDialog.EmailParticipants.RemoveAll(x => x == null); dialog.Participants = edDialog.EmailParticipants.ConvertAll(x => _userProvider.GetUser(x).Uuid); dialog.Participants.Add(edDialog.Creator.ToString()); try { _dialogsProvider.UpdateAsync(dialog).Wait(); } catch { return(new StatusExecution() { StatusCode = HttpStatusCode.BadRequest, Message = "Диалог не изменён" }); } return(new StatusExecution() { StatusCode = HttpStatusCode.OK, Message = "Диалог успешно изменён" }); }