public CRUD_Product_Response CreateProduct(CRUD_Product_Request request) { var response = new CRUD_Product_Response(); try { var product = Mapper.Map <CRUD_Product_Request, PRODUCT>(request); this._IProductRepository.Add(product); int saveStatus = this._IUnitOfWork.Commit(); if (request.Product_Group_ID == 0) { product.Product_Group_ID = product.Product_ID; } this._IProductRepository.Update(product); saveStatus = this._IUnitOfWork.Commit(); var data = Mapper.Map <PRODUCT, Product_DTO>(product); if (saveStatus > 0) { response.StatusCode = (int)RESULT_STATUS_CODE.SUCCESS; response.Results = data; } else { response.StatusCode = (int)RESULT_STATUS_CODE.DATABASE_ERROR; } } catch (Exception ex) { response.StatusCode = (int)RESULT_STATUS_CODE.SYSTEM_ERROR; response.StatusMessage = ex.ToString(); } return(response); }
public CRUD_Product_Response UpdateProduct(CRUD_Product_Request request) { var response = new CRUD_Product_Response(); try { var product = this._IProductRepository.GetById(request.Product_ID)?.Results; if (product != null) { if (request.Product_Group_ID == 0) { request.Product_Group_ID = product.Product_Group_ID; } if (request.Unit_ID == "") { request.Unit_ID = product.Unit_ID; } } var productParam = Mapper.Map <CRUD_Product_Request, Product_Update_Parameter>(request); var saveStatus = this._IProductRepository.Update_Product(productParam); if (saveStatus > 0) { response.StatusCode = (int)RESULT_STATUS_CODE.SUCCESS; } else { response.StatusCode = (int)RESULT_STATUS_CODE.DATABASE_ERROR; } } catch (Exception ex) { response.StatusCode = (int)RESULT_STATUS_CODE.SYSTEM_ERROR; response.StatusMessage = ex.ToString(); } return(response); }