Ejemplo n.º 1
0
 private void Save(List listToSave)
 {
     if (listToSave.Id > 0)
         UpdateExistingList(listToSave);
     else
         SaveNewList(listToSave);
 }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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.
        }
Ejemplo n.º 4
0
 private List Get(List listToShare)
 {
     Guard.NotNull<List>(() => listToShare, listToShare);
     return this.Get(listToShare.Id);
 }
Ejemplo n.º 5
0
 void IListService.Save(List listToSave)
 {
     this.Save(listToSave);
 }
Ejemplo n.º 6
0
 void IListService.ShareList(List listToShare, IEnumerable<ListSecurity> listSecurity)
 {
     this.ShareList(listToShare, listSecurity);
 }
Ejemplo n.º 7
0
 List IListService.Get(List listToShare)
 {
     return this.Get(listToShare);
 }
Ejemplo n.º 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.
        }
Ejemplo n.º 9
0
        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));
        }
Ejemplo n.º 10
0
        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));
        }
Ejemplo n.º 11
0
        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;
        }