/// <summary> /// Validate request /// </summary> /// <param name="request"></param> /// <param name="response"></param> public void Validate(PrivilegeRequest request, out PrivilegeResponse response) { response = new PrivilegeResponse(); if (request.Action != null && request.Action.Equals(ClinicEnums.Action.DELETE.ToString())) { ValidateForDelete(request, out response); } else { bool isHavePrivilege = true; if (request.Data.Privilige_Name == null || String.IsNullOrWhiteSpace(request.Data.Privilige_Name)) { errorFields.Add("Privilege Name"); } if (errorFields.Any()) { response.Status = false; response.Message = string.Format(Messages.ValidationErrorFields, String.Join(",", errorFields)); } else if (request.Data.Privilige_Name.Length > 150) { response.Status = false; response.Message = $"Maximum Character for Privilege Name is 150"; } 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 PrivilegeHandler(_unitOfWork).CreateOrEdit(request); } } }
/// <summary> /// Delete validation /// </summary> /// <param name="request"></param> /// <param name="response"></param> private void ValidateForDelete(PrivilegeRequest request, out PrivilegeResponse response) { response = new PrivilegeResponse(); 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 PrivilegeHandler(_unitOfWork).RemoveData(request); } }