private void InitTableView() { _tableViewSource = new ObservableTableViewSource <ChatUserViewModel> { DataSource = ViewModel.PaginationViewModel.Items, BindCellDelegate = (cell, viewModel, index) => { if (cell is IBindableViewCell <ChatUserViewModel> memberCell) { memberCell.Bind(viewModel); } }, ReuseId = FilteredContactViewCell.Key }; _tableViewHeader = new NewGroupView(new CGRect(0, 0, TableView.Frame.Width, 60)); _tableViewHeader.SetCommand(ViewModel.CreateGroupChatCommand); _tableViewHeader.SetText(ViewModel.LocalizedStrings.NewGroup); TableView.TableHeaderView = _tableViewHeader; TableView.TableFooterView = new UIView(); TableView.RegisterNibForCellReuse(FilteredContactViewCell.Nib, FilteredContactViewCell.Key); TableView.Source = _tableViewSource; TableView.AddGestureRecognizer(new UITapGestureRecognizer((obj) => View.EndEditing(true)) { CancelsTouchesInView = false }); TableView.BackgroundView = new SearchNoResultView() { NoResultText = ViewModel.LocalizedStrings.SearchNoResults }; }
public IActionResult NewGroup() { NewGroupView model = new NewGroupView(); model.Users = _departmentsService.GetAllUsersForDepartment(DepartmentId); model.Groups = _departmentGroupsService.GetAllGroupsForDepartmentUnlimited(DepartmentId); List <DepartmentGroup> groups = new List <DepartmentGroup>(); groups.Add(new DepartmentGroup { DepartmentGroupId = -1, Name = "None" }); groups.AddRange(model.Groups.Where(x => x.Type.HasValue && x.Type.Value == (int)DepartmentGroupTypes.Station)); model.StationGroups = new SelectList(groups, "DepartmentGroupId", "Name"); return(View(model)); }
public IActionResult NewGroup(NewGroupView model, IFormCollection collection) { model.Users = _departmentsService.GetAllUsersForDepartment(DepartmentId); model.Groups = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId); var groups = new List <DepartmentGroup>(); groups.Add(new DepartmentGroup { DepartmentGroupId = -1, Name = "None" }); groups.AddRange(model.Groups.Where(x => x.Type.HasValue && x.Type.Value == (int)DepartmentGroupTypes.Station)); model.StationGroups = new SelectList(groups, "DepartmentGroupId", "Name"); var groupAdmins = new List <string>(); var groupUsers = new List <string>(); var allUsers = new List <string>(); if (collection.ContainsKey("groupAdmins")) { groupAdmins.AddRange(collection["groupAdmins"].ToString().Split(char.Parse(","))); } if (collection.ContainsKey("groupUsers")) { groupUsers.AddRange(collection["groupUsers"].ToString().Split(char.Parse(","))); } allUsers.AddRange(groupAdmins); allUsers.AddRange(groupUsers); foreach (var groupUser in allUsers) { if (_departmentGroupsService.IsUserInAGroup(groupUser, DepartmentId)) { var profile = _userProfileService.GetProfileByUserId(groupUser); ModelState.AddModelError("", string.Format("{0} Is already in a group. Cannot add to another.", profile.FullName.AsFirstNameLastName)); } } if (model.NewGroup.Type.HasValue && model.NewGroup.Type.Value == (int)DepartmentGroupTypes.Station) { if (String.IsNullOrWhiteSpace(model.What3Word)) { if (String.IsNullOrEmpty(model.Latitude) && String.IsNullOrEmpty(model.Longitude)) { if (String.IsNullOrEmpty(model.Address1)) { ModelState.AddModelError("Address1", string.Format("The Address field is required for station groups")); } if (String.IsNullOrEmpty(model.City)) { ModelState.AddModelError("City", string.Format("The City field is required for station groups")); } if (String.IsNullOrEmpty(model.Country)) { ModelState.AddModelError("Country", string.Format("The Country field is required for station groups")); } if (String.IsNullOrEmpty(model.PostalCode)) { ModelState.AddModelError("PostalCode", string.Format("The Postal Code field is required for station groups")); } if (String.IsNullOrEmpty(model.State)) { ModelState.AddModelError("State", string.Format("The State field is required for station groups")); } } } else { var result = _geoLocationProvider.GetCoordinatesFromW3W(model.What3Word); if (result == null) { ModelState.AddModelError("What3Word", string.Format("The What3Words address entered was incorrect.")); } else { model.Latitude = result.Latitude.ToString(); model.Longitude = result.Longitude.ToString(); } } } if (ModelState.IsValid) { model.NewGroup.DepartmentId = DepartmentId; var users = new List <DepartmentGroupMember>(); foreach (var user in allUsers) { if (users.All(x => x.UserId != user)) { var dgm = new DepartmentGroupMember(); dgm.DepartmentId = DepartmentId; dgm.UserId = user; if (groupAdmins.Contains(user)) { dgm.IsAdmin = true; } users.Add(dgm); } } if (model.NewGroup.Type.HasValue && model.NewGroup.Type.Value == (int)DepartmentGroupTypes.Station) { if (String.IsNullOrEmpty(model.Latitude) && String.IsNullOrEmpty(model.Longitude)) { model.NewGroup.Address.Address1 = model.Address1; model.NewGroup.Address.City = model.City; model.NewGroup.Address.Country = model.Country; model.NewGroup.Address.PostalCode = model.PostalCode; model.NewGroup.Address.State = model.State; } else { model.NewGroup.Address = null; model.NewGroup.Latitude = model.Latitude; model.NewGroup.Longitude = model.Longitude; } if (!String.IsNullOrWhiteSpace(model.What3Word)) { model.NewGroup.What3Words = model.What3Word; } } else { model.NewGroup.Address = null; } if (model.NewGroup.ParentDepartmentGroupId <= 0) { model.NewGroup.ParentDepartmentGroupId = null; } if (!String.IsNullOrWhiteSpace(model.PrinterApiKey) && !String.IsNullOrWhiteSpace(model.PrinterId)) { var printer = new DepartmentGroupPrinter(); printer.PrinterId = int.Parse(model.PrinterId); printer.PrinterName = model.PrinterName; printer.ApiKey = SymmetricEncryption.Encrypt(model.PrinterApiKey, Config.SystemBehaviorConfig.ExternalLinkUrlParamPassphrase); model.NewGroup.DispatchToPrinter = true; model.NewGroup.PrinterData = JsonConvert.SerializeObject(printer); } model.NewGroup.Members = users; model.NewGroup.DispatchEmail = RandomGenerator.GenerateRandomString(6, 6, false, true, false, true, true, false, null); model.NewGroup.MessageEmail = RandomGenerator.GenerateRandomString(6, 6, false, true, false, true, true, false, null); _departmentGroupsService.Save(model.NewGroup); var auditEvent = new AuditEvent(); auditEvent.DepartmentId = DepartmentId; auditEvent.UserId = UserId; auditEvent.Type = AuditLogTypes.GroupAdded; auditEvent.After = model.NewGroup.CloneJson(); _eventAggregator.SendMessage <AuditEvent>(auditEvent); return(RedirectToAction("Index", "Groups", new { Area = "User" })); } return(View("NewGroup", model)); }