示例#1
0
 private void Save(List listToSave)
 {
     if (listToSave.Id > 0)
         UpdateExistingList(listToSave);
     else
         SaveNewList(listToSave);
 }
示例#2
0
        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;
            }
        }
示例#3
0
        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.
        }
示例#4
0
 private List Get(List listToShare)
 {
     Guard.NotNull<List>(() => listToShare, listToShare);
     return this.Get(listToShare.Id);
 }
示例#5
0
 void IListService.Save(List listToSave)
 {
     this.Save(listToSave);
 }
示例#6
0
 void IListService.ShareList(List listToShare, IEnumerable<ListSecurity> listSecurity)
 {
     this.ShareList(listToShare, listSecurity);
 }
示例#7
0
 List IListService.Get(List listToShare)
 {
     return this.Get(listToShare);
 }
示例#8
0
        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.
        }
示例#9
0
文件: List.cs 项目: brunchey/BenNote
        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));
        }
示例#10
0
文件: List.cs 项目: brunchey/BenNote
        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));
        }
示例#11
0
文件: List.cs 项目: brunchey/BenNote
        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;
        }