public HttpResponseMessage Save(string suppReturnJson, string suppReturnDetailsJson) { string suppReturnId = ""; string errMessage = ""; BuySupplierreturnContract suppReturnDTO = JsonConvert.DeserializeObject <BuySupplierreturnContract>(suppReturnJson); BuySupplierreturnDetailContract[] suppReturnDetailDTOs = JsonConvert.DeserializeObject <BuySupplierreturnDetailContract[]>(suppReturnDetailsJson); SqlTransaction tran = DataProvider.beginTrans(); try { businessRule.RegistInstants(suppReturnDTO); if (suppReturnDTO.Id > 0) { suppReturnId = suppReturnDT.Update(suppReturnDTO, tran); } else { businessRule.RegistRule("Insert"); if (businessRule.CheckRules(out errMessage)) { suppReturnId = suppReturnDT.Insert(suppReturnDTO, tran); } else { return(handleBRFailed(errMessage, tran)); } } if (Converter.ToInt32(suppReturnId) > 0) { foreach (BuySupplierreturnDetailContract invoiceDetailDTO in suppReturnDetailDTOs) { invoiceDetailDTO.Supplierreturnid = Converter.ToInt32(suppReturnId); suppReturnDetailDT.Insert(invoiceDetailDTO, tran); //StoreModel.Import(invoiceDetailDTO.Productid.ToString(), invoiceDetailDTO.Quantity, invoiceDetailDTO.Price, tran); } } DataProvider.CommitTrans(tran); } catch (Exception e) { DataProvider.RollbackTrans(tran); ExceptionHandler.Log(e); } return(Request.CreateResponse <string>(HttpStatusCode.OK, errMessage != string.Empty ? errMessage : suppReturnId)); }
public HttpResponseMessage Save(string buysupplierreturnJson) { string errMessage = string.Empty; try { BuySupplierreturnContract buysupplierreturn = JsonConvert.DeserializeObject <BuySupplierreturnContract>(buysupplierreturnJson); businessRule.RegistInstants(buysupplierreturn); if (buysupplierreturn.Id == 0) { businessRule.RegistRule("Insert"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(buysupplierreturn))); } else { return(handleBRFailed(errMessage)); } } else { businessRule.RegistRule("Update"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(buysupplierreturn))); } else { return(handleBRFailed(errMessage)); } } } catch (Exception e) { ExceptionHandler.Log(e); return(Request.CreateResponse <string>(HttpStatusCode.OK, "Có lỗi xảy ra trên chương trình.")); } }