/// <summary> /// Validate request /// </summary> /// <param name="request"></param> /// <param name="response"></param> public void Validate(RoleRequest request, out RoleResponse response) { response = new RoleResponse(); if (request.Action != null && request.Action.Equals(ClinicEnums.Action.DELETE.ToString())) { ValidateForDelete(request, out response); } else { bool isHavePrivilege = true; if (request.Data.RoleName == null || String.IsNullOrWhiteSpace(request.Data.RoleName)) { errorFields.Add("Role Name"); } if (request.Data.OrgID == 0) { errorFields.Add("Organization"); } if (errorFields.Any()) { response.Status = false; response.Message = string.Format(Messages.ValidationErrorFields, String.Join(",", errorFields)); } else if (request.Data.RoleName.Length > 30) { response.Status = false; response.Message = $"Maximum Character for Role Name is 30"; } if (request.Data.Id == 0) { isHavePrivilege = IsHaveAuthorization(ADD_PRIVILEGE_NAME, request.Data.Account.Privileges.PrivilegeIDs); } else { isHavePrivilege = IsHaveAuthorization(EDIT_PRIVILEGE_NAME, request.Data.Account.Privileges.PrivilegeIDs); } if (!isHavePrivilege) { response.Status = false; response.Message = Messages.UnauthorizedAccess; } if (response.Status) { response = new RoleHandler(_unitOfWork).CreateOrEdit(request); } } }
/// <summary> /// Delete validation /// </summary> /// <param name="request"></param> /// <param name="response"></param> private void ValidateForDelete(RoleRequest request, out RoleResponse response) { response = new RoleResponse(); if (request.Action == ClinicEnums.Action.DELETE.ToString()) { bool isHavePrivilege = IsHaveAuthorization(DELETE_PRIVILEGE_NAME, request.Data.Account.Privileges.PrivilegeIDs); if (!isHavePrivilege) { response.Status = false; response.Message = Messages.UnauthorizedAccess; } } if (response.Status) { response = new RoleHandler(_unitOfWork).RemoveData(request); } }