Example #1
0
        public void Add(IBusiness business, ILocation location, IUserBusiness userBusiness, IGroup group)
        {
            try
            {
                Lock();

                _businessRepository.Add(business);
                _locationRepository.Add(location);
                _groupRepository.Add(group);

                foreach (var email in business.Members)
                {
                    var userGroup = new UserGroup
                    {
                        Id   = group.Id,
                        Name = group.Name,
                        Role = GroupRoles.Admin
                    };

                    _userRepository.AddBusinessWithEmail(userBusiness, email);
                    _userRepository.AddGroupWithEmail(userGroup, email);
                }
            }
            catch (Exception)
            {
                //TODO: Rollback logic
                throw new Exception("Failed to perform atomic action - " + Desc);
            }
            finally
            {
                Unlock();
            }
        }
Example #2
0
        public void Add(IGroup group)
        {
            _groupRepository.Add(group);

            var currentUser = _userRepository.GetCurrent;

            foreach (var memberEmail in group.Members)
            {
                var userGroup = new UserGroup
                {
                    Id   = @group.Id,
                    Name = @group.Name,
                    Role = memberEmail == currentUser.Email ? GroupRoles.Admin : GroupRoles.Member,
                };

                _userRepository.AddGroupWithEmail(userGroup, memberEmail);
            }
        }