public HttpResponseMessage Save(string recvProductJson, string recvProductDetailsJson) { string recvProductId = ""; string errMessage = ""; SelReceiveproductContract recvProductDTO = JsonConvert.DeserializeObject <SelReceiveproductContract>(recvProductJson); SelReceiveproductDetailContract[] suppReturnDetailDTOs = JsonConvert.DeserializeObject <SelReceiveproductDetailContract[]>(recvProductDetailsJson); SqlTransaction tran = DataProvider.beginTrans(); try { businessRule.RegistInstants(recvProductDTO); if (recvProductDTO.Id > 0) { recvProductId = recvProductDT.Update(recvProductDTO, tran); } else { businessRule.RegistRule("Insert"); if (businessRule.CheckRules(out errMessage)) { recvProductId = recvProductDT.Insert(recvProductDTO, tran); } else { return(handleBRFailed(errMessage, tran)); } } if (Converter.ToInt32(recvProductId) > 0) { foreach (SelReceiveproductDetailContract invoiceDetailDTO in suppReturnDetailDTOs) { invoiceDetailDTO.Receiveproductid = Converter.ToInt32(recvProductId); rvcProductDetailDT.Insert(invoiceDetailDTO, tran); StoreModel.ReceiveProduct(recvProductDTO, invoiceDetailDTO, tran); } } DataProvider.CommitTrans(tran); } catch (Exception e) { DataProvider.RollbackTrans(tran); ExceptionHandler.Log(e); } return(Request.CreateResponse <string>(HttpStatusCode.OK, errMessage != string.Empty ? errMessage : recvProductId)); }
void SaveSuppReceipt(int moneyslipId, string invPaymentJson, SqlTransaction tran) { try { SelReceiveproductDT rcvProductDT = new SelReceiveproductDT(); List <FinReceivepaymentContract> rcvPayments = JsonConvert.DeserializeObject <List <FinReceivepaymentContract> >(invPaymentJson); foreach (FinReceivepaymentContract rcvPayment in rcvPayments) { rcvPayment.Moneyslipid = moneyslipId; rcvProductDT.Update(new string[] { " TotalReturn" }, new string[] { " TotalReturn-" + rcvPayment.Total }, " ID=" + rcvPayment.Receiveproductid); revPaymentDT.Insert(rcvPayment, tran); } } catch (Exception e) { throw e; } }
public HttpResponseMessage Save(string selreceiveproductJson) { string errMessage = string.Empty; try { SelReceiveproductContract selreceiveproduct = JsonConvert.DeserializeObject <SelReceiveproductContract>(selreceiveproductJson); businessRule.RegistInstants(selreceiveproduct); if (selreceiveproduct.Id == 0) { businessRule.RegistRule("Insert"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(selreceiveproduct))); } else { return(handleBRFailed(errMessage)); } } else { businessRule.RegistRule("Update"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(selreceiveproduct))); } 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.")); } }