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); } } }
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); }
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); }
public UserGroup Read(int id) { var group = UserGroupRepository.GetById(id); if (group == null) { throw new ApplicationException(string.Format(UserGroupStrings.GroupNotFound, id)); } return(group); }
public UserGroup GetById(object id) { return(_userGroupRepository.GetById(id)); }