public async Task <string> DeleteProductCategory(int productId, int categoryId) { try { using var sqlCon = new SqlConnection(_options.connectionString); await sqlCon.OpenAsync(); var dynamicParameters = new DynamicParameters(); dynamicParameters.Add("@productId", productId); dynamicParameters.Add("@categoryId", categoryId); var res = new ProductCategoryResponse(); await sqlCon.ExecuteAsync( "spDeleteProductCategory", dynamicParameters, commandType : CommandType.StoredProcedure ); return(res.Messages = Enumhelper.GetEnumDescription(StatusHandlersEnum.StatusHandle.DeleteSuccess)); } catch (Exception ex) { var res = new ProductCategoryResponse(); return(res.Messages = ex.Message); } }
public ProductCategoryResponse GetProductCategoryResponse(int?id) { ProductCategoryResponse prodCateResp = new ProductCategoryResponse(); if (id != null) { prodCateResp.ProductCategory = prodCategoryRepository.Find((int)id); } prodCateResp.ProductCategories = prodCategoryRepository.GetAll(); return(prodCateResp); }
/// <summary> /// Validate request /// </summary> /// <param name="request"></param> /// <param name="response"></param> public void Validate(ProductCategoryRequest request, out ProductCategoryResponse response) { response = new ProductCategoryResponse(); if (request.Action != null && request.Action.Equals(ClinicEnums.Action.DELETE.ToString())) { ValidateForDelete(request, out response); } else { bool isHavePrivilege = true; if (request.Data.Name == null || String.IsNullOrWhiteSpace(request.Data.Name)) { errorFields.Add("ProductCategory Name"); } if (errorFields.Any()) { response.Status = false; response.Message = string.Format(Messages.ValidationErrorFields, String.Join(",", errorFields)); } 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 ProductCategoryHandler(_unitOfWork).CreateOrEdit(request); } } }
public async Task <IActionResult> GetProductCategory(Guid?ProductGameId) { var result = new ProductCategoryResponse(); var productCategory = await _context.ProductCategory.Where(p => ProductGameId == null || p.Id == ProductGameId).Select(pc => new ProductCategory { ProductCategoryId = pc.Id, ProductCategoryName = pc.Name }).ToListAsync(); if (productCategory.Count == 0) { result.Code = -100; result.Message = "Can't get products with given parameters."; return(Ok(result)); } result.Code = 100; result.Message = "Success"; result.ProductCategory = productCategory; return(Ok(result)); }
/// <summary> /// Delete validation /// </summary> /// <param name="request"></param> /// <param name="response"></param> private void ValidateForDelete(ProductCategoryRequest request, out ProductCategoryResponse response) { response = new ProductCategoryResponse(); 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 ProductCategoryHandler(_unitOfWork).RemoveData(request); } }