public DTO.Restriction Save(bool isRKAdmin, Guid clientId, DTO.Restriction restriction) { restriction.IsValid(); var _restriction = restriction.Transfer(); var _role = roleRepository.Get(_restriction.RoleCode, null); if (_role.IsNull()) { throw new ArgumentException("Grupo não encontrado"); } if (!isRKAdmin) { var appStore = applicationStoreRepository.GetByClientId(clientId); if (appStore.StoreCode != _role.Store.Code) { throw new ArgumentException("Usuário não possui permissão para realizar essa operação"); } } _restriction.Role = null; _restriction.RoleCode = _role.Code; Restriction result; using (var transaction = Connection.BeginTransaction()) result = restrictionRepository.Save(_restriction); return(result.GetResult()); }
public ModifyRestrictionResponse ModifyRestriction(ModifyRestrictionRequest request) { ModifyRestrictionResponse response = new ModifyRestrictionResponse(); Restriction restriction = _restrictionRepository .FindBy(request.RestrictionId); restriction.Id = request.RestrictionId; restriction.RestrictionName = request.RestrictionName; restriction.RequirePermission = request.RequirePermission; restriction.RestrictionDescription = request.RestrictionDescription; if (restriction.GetBrokenRules().Count() > 0) { response.Errors = restriction.GetBrokenRules().ToList(); } else { try { _restrictionRepository.Save(restriction); _uow.Commit(); response.Errors = new List <BusinessRule>(); } catch (Exception ex) { response.Errors = new List <BusinessRule>(); response.Errors.Add(new BusinessRule("DAL", "DAL_ERROR: " + ex.Message)); } } return(response); }
public Role Save(Role role) { var roleOld = roleRepository.Get(role.Code, role.StoreCode); if (!roleOld.IsNull() && !role.Permissions.IsNull()) { permissionRepository.Delete(roleOld.Permissions); } if (!roleOld.IsNull() && !role.AccountRoles.IsNull()) { accountRoleRepository.Delete(roleOld.AccountRoles); } if (!roleOld.IsNull() && !role.Restrictions.IsNull()) { restrictionRepository.Delete(roleOld.Restrictions); } if (!role.Permissions.IsNull()) { role.Permissions.ForEach(p => { p.RoleCode = role.Code; p.SaveDate = DateTime.Now; p.UpdateDate = DateTime.Now; permissionRepository.Save(p); }); } if (!role.AccountRoles.IsNull()) { role.AccountRoles.ForEach(a => { a.RoleCode = role.Code; a.SaveDate = DateTime.Now; a.UpdateDate = DateTime.Now; accountRoleRepository.Save(a); }); } if (!role.Restrictions.IsNull()) { role.Restrictions.ForEach(a => { a.RoleCode = role.Code; a.SaveDate = DateTime.Now; a.UpdateDate = DateTime.Now; restrictionRepository.Save(a); }); } return(roleRepository.Save(role)); }