Пример #1
0
        public override void DoCustomBinding()
        {
            if (MemberType == UserMemberType)
            {
                GroupId = null;
            }
            else if (MemberType == GroupMemberType)
            {
                UserId = null;
            }
            else
            {
                GroupId = null;
                UserId  = null;
            }

            if (IsNew)
            {
                if (MemberType == UserMemberType && UserId.HasValue)
                {
                    User = UserRepository.GetById(UserId.Value, true);
                }
                else if (MemberType == GroupMemberType && GroupId.HasValue)
                {
                    Group = UserGroupRepository.GetById(GroupId.Value);
                }
            }
        }
Пример #2
0
        public MessageResult Remove(int id)
        {
            var group = UserGroupRepository.GetById(id);

            if (group == null)
            {
                throw new ApplicationException(string.Format(UserGroupStrings.GroupNotFound, id));
            }

            if (group.BuiltIn)
            {
                return(MessageResult.Error(UserGroupStrings.CannotRemoveBuitInGroup));
            }

            var notifications = new NotificationRepository().GetUserGroupNotifications(id).ToList();

            if (notifications.Any())
            {
                var message = string.Join(",", notifications.Select(w => $"({w.Id}) \"{w.Name}\""));
                return(MessageResult.Error(string.Format(UserGroupStrings.NotificationsExist, message)));
            }

            var workflows = WorkflowRepository.GetUserGroupWorkflows(id).ToList();

            if (workflows.Any())
            {
                var message = string.Join(",", workflows.Select(w => $"({w.Id}) \"{w.Name}\""));
                return(MessageResult.Error(string.Format(UserGroupStrings.WorkflowsExist, message)));
            }

            UserGroupRepository.Delete(id);
            return(null);
        }
Пример #3
0
        public void GetByIdTest()
        {
            IUserGroupRepository target = new UserGroupRepository();
            var fromDb = target.GetById(item.Id);

            Assert.IsNotNull(fromDb);
            Assert.AreNotSame(item, fromDb);
            Assert.AreEqual(item.Descricao, fromDb.Descricao);
            Assert.AreEqual(item.Tipo, fromDb.Tipo);
        }
Пример #4
0
        public UserGroup Read(int id)
        {
            var group = UserGroupRepository.GetById(id);

            if (group == null)
            {
                throw new ApplicationException(string.Format(UserGroupStrings.GroupNotFound, id));
            }

            return(group);
        }
Пример #5
0
 public UserGroup GetById(object id)
 {
     return(_userGroupRepository.GetById(id));
 }