public ActionResult Add(AddGroupModel model) { Account account = GetAccount(); model.Contacts = contactRepository.GetAllContactsForAccount(account.AccountId); if (ModelState.IsValid) // Values need to be filled in { if (!model.SelectedContacts.Contains(null)) // Selected contacts must all exist { Group group = new Group(); // Needed to Redirect To Action int?[] selectedContacts = model.SelectedContacts; string groupName = model.GroupName; string initialMessage = model.InitialMessage; // Create group, including initial message: groupLogic.CreateGroup(group, selectedContacts, initialMessage, model.GroupName, account.AccountId); return(RedirectToAction("ViewChat", "Group", new { groupId = group.GroupId })); } else { ModelState.AddModelError("", "One or more of the contacts you tried to add don't have a WhatsUp-account yet."); } } else { ModelState.AddModelError("", "Please enter a groupname and initial message."); } return(View(model)); }
public async Task <IActionResult> CreateGroup(GroupModel model) { bool isGroupCreated = await _groupLogic.CreateGroup(model, User.Identity.Name); if (isGroupCreated) { GroupModel group = _groupLogic.FormGroupModel(model.Id, User.Identity.Name); return(View("~/Views/Group/GroupDetails.cshtml", group)); } else { ModelState.AddModelError("error_message", "Такая группа уже существует"); GroupModel group = _groupLogic.FormGroupModel(model.Id, User.Identity.Name); return(View("~/Views/Group/GroupDetails.cshtml", group)); } }
public ActionResult AddGroup(CreateGroupViewModel group) { groupLogic.CreateGroup(group.Title, (string)Session["UserName"], group.IsPrivate); return(RedirectToAction("Index", "Home")); }