private void Save(List listToSave) { if (listToSave.Id > 0) UpdateExistingList(listToSave); else SaveNewList(listToSave); }
private void SaveNewList(List listToSave) { var newList = new List(listToSave.Name, this.currentUser); newList.CurrentVersion.Items = listToSave.Items; //TODO use fluent validation here. newList.CurrentVersion.ValidateItems(); try { this.listRepository.Save(newList); } catch (Exception ex) { throw; } }
private void ShareList(List listToShare, IEnumerable<ListSecurity> listSecurity) { Guard.NotNull<List>(() => listToShare, listToShare); Guard.NotNull<IEnumerable<ListSecurity>>(() => listSecurity, listSecurity); var list = this.listRepository.Get(listToShare.Id); list.Share(listSecurity); try { this.listRepository.Save(list); } catch (Exception ex) { throw; } //TODO: Raise event to bus here for sending out notifications about new invites //or updates to existing security. }
private List Get(List listToShare) { Guard.NotNull<List>(() => listToShare, listToShare); return this.Get(listToShare.Id); }
void IListService.Save(List listToSave) { this.Save(listToSave); }
void IListService.ShareList(List listToShare, IEnumerable<ListSecurity> listSecurity) { this.ShareList(listToShare, listSecurity); }
List IListService.Get(List listToShare) { return this.Get(listToShare); }
private void UpdateExistingList(List listToSave) { var existingList = this.listRepository.Get(listToSave); existingList.CurrentVersion.Items = listToSave.Items; //todo use fluent validations here instead. existingList.CurrentVersion.ValidateItems(); try { this.listRepository.Save(existingList); } catch (Exception ex) { throw; } //TODO: Raise event to bus here for sending out notifications about new invites //or updates to existing security. }
private void VerifyUniqueUserNamesInSecurityList(List<ListSecurity> listSecurityUpdates) { //verify that listSecurity contains only unique list of users var userGroups = from s in listSecurityUpdates group s by s.User.UserName into u where u.Count() > 1 select new { UserName = u.Key, Something = u }; if (userGroups.FirstOrDefault() != null) throw new ShareListException(string.Format("The user {0} is specified twice", userGroups.First().UserName)); }
private void VerifyExistingOwnerNotChanged(List<ListSecurity> listSecurityUpdates) { var existingOwner = from s in this.Security where s.Role == ListRoleType.Owner select s.User; var proposedOwnerResult = from s in listSecurityUpdates where s.User.UserName == existingOwner.FirstOrDefault().UserName select s; var proposedOwnerChanges = proposedOwnerResult.FirstOrDefault(); if (proposedOwnerChanges != null) if (proposedOwnerChanges.Role != ListRoleType.Owner) throw new ShareListException(string.Format("Cannot change the security role of the existing owner", proposedOwnerChanges.User.UserName)); }
private void UpdateExistingSecurityList(List<ListSecurity> listSecurityUpdates) { //add/update security based on UserName var CurrentListSecurity = this.Security.ToList<ListSecurity>(); foreach (var securityItem in listSecurityUpdates) { var existingItem = CurrentListSecurity.Where(s => s.User.UserName == securityItem.User.UserName).FirstOrDefault(); if (existingItem == null) { CurrentListSecurity.Add(securityItem); } else { existingItem.Role = securityItem.Role; existingItem.IsActive = securityItem.IsActive; existingItem.LastUpdated = DateTime.Now; } } this.Security = CurrentListSecurity; }