public HttpResponseMessage Save(string importInvoceJson, string invoiceDetailsJson) { string invoiceId = ""; string errMessage = ""; BuyImportinvoiceContract invoiceDTO = JsonConvert.DeserializeObject <BuyImportinvoiceContract>(importInvoceJson); BuyImportinvoiceDetailContract[] invoiceDetailDTOs = JsonConvert.DeserializeObject <BuyImportinvoiceDetailContract[]>(invoiceDetailsJson); SqlTransaction tran = DataProvider.beginTrans(); try { businessRule.RegistInstants(invoiceDTO); if (invoiceDTO.Id > 0) { invoiceId = invoiceDT.Update(invoiceDTO, tran); } else { businessRule.RegistRule("Insert"); if (businessRule.CheckRules(out errMessage)) { invoiceId = invoiceDT.Insert(invoiceDTO, tran); } else { return(handleBRFailed(errMessage, tran)); } } if (Converter.ToInt32(invoiceId) > 0) { foreach (BuyImportinvoiceDetailContract invoiceDetailDTO in invoiceDetailDTOs) { invoiceDetailDTO.Importinvoiceid = Converter.ToInt32(invoiceId); invoiceDetailDT.Insert(invoiceDetailDTO, tran); StoreModel.Import(invoiceDTO, invoiceDetailDTO, tran); } } DataProvider.CommitTrans(tran); } catch (Exception e) { DataProvider.RollbackTrans(tran); ExceptionHandler.Log(e); } return(Request.CreateResponse <string>(HttpStatusCode.OK, errMessage != string.Empty ? errMessage : invoiceId)); }
public HttpResponseMessage Save(string buyimportinvoiceJson) { string errMessage = string.Empty; try { BuyImportinvoiceContract buyimportinvoice = JsonConvert.DeserializeObject <BuyImportinvoiceContract>(buyimportinvoiceJson); businessRule.RegistInstants(buyimportinvoice); if (buyimportinvoice.Id == 0) { businessRule.RegistRule("Insert"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(buyimportinvoice))); } else { return(handleBRFailed(errMessage)); } } else { businessRule.RegistRule("Update"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(buyimportinvoice))); } 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.")); } }