public HttpResponseMessage Save(string type, string receiptJson, string receiptDetailJson) { SqlTransaction tran = DataProvider.beginTrans(); try { FinReceiptContract receiptDTO = JsonConvert.DeserializeObject <FinReceiptContract>(receiptJson); int receiptId = receiptDTO.Id; if (receiptId == 0) { { receiptId = Converter.ToInt32(receiptDT.Insert(receiptDTO, tran)); } if (type == "SellInvoice") { SaveInvReceipt(receiptId, receiptDetailJson, tran); } if (type == "SuppReturn") { SaveSuppReceipt(receiptId, receiptDetailJson, tran); } } tran.Commit(); return(Request.CreateResponse <string>(HttpStatusCode.OK, receiptId.ToString())); } catch (Exception e) { ExceptionHandler.Log(e); tran.Rollback(); return(Request.CreateResponse <string>(HttpStatusCode.OK, "Lỗi: Không lưu thành công."));; } }
public HttpResponseMessage Save(string finreceiptJson) { string errMessage = string.Empty; try { FinReceiptContract finreceipt = JsonConvert.DeserializeObject <FinReceiptContract>(finreceiptJson); businessRule.RegistInstants(finreceipt); if (finreceipt.Id == 0) { businessRule.RegistRule("Insert"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(finreceipt))); } else { return(handleBRFailed(errMessage)); } } else { businessRule.RegistRule("Update"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(finreceipt))); } 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.")); } }