Beispiel #1
0
        public HttpResponseMessage Save(string sellInvoceJson, string invoiceDetailsJson)
        {
            string             invoiceId  = "";
            string             errMessage = "";
            SelInvoiceContract invoiceDTO = JsonConvert.DeserializeObject <SelInvoiceContract>(sellInvoceJson);

            SelInvoiceDetailContract[] invoiceDetailDTOs = JsonConvert.DeserializeObject <SelInvoiceDetailContract[]>(invoiceDetailsJson);
            SqlTransaction             tran = DataProvider.beginTrans();

            try
            {
                businessRule.RegistInstants(invoiceDTO);
                if (invoiceDTO.Id > 0)
                {
                    invoiceId = invoiceDT.Update(invoiceDTO, tran);
                    changeDetail(invoiceDTO.Id, invoiceDTO.Code, (int)invoiceDTO.Storeid, invoiceDetailDTOs, 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)
                {
                    invoiceDetailDT.DeleteViaCond("InvoiceId=" + invoiceId);
                    foreach (SelInvoiceDetailContract invoiceDetailDTO in invoiceDetailDTOs)
                    {
                        invoiceDetailDTO.Invoiceid = Converter.ToInt32(invoiceId);
                        invoiceDetailDT.Insert(invoiceDetailDTO, tran);
                        errMessage = StoreModel.Export(invoiceDTO.Storeid.ToString(), invoiceDTO.Code, Converter.ToInt32(invoiceDetailDTO.Quantity), invoiceDetailDTO.Productid.ToString(), tran);
                        if (errMessage != "")
                        {
                            DataProvider.RollbackTrans(tran);
                            return(Request.CreateResponse <string>(HttpStatusCode.OK, errMessage));
                        }
                    }
                }
                DataProvider.CommitTrans(tran);
            }
            catch (Exception e)
            {
                DataProvider.RollbackTrans(tran);
                ExceptionHandler.Log(e);
            }
            return(Request.CreateResponse <string>(HttpStatusCode.OK, errMessage != string.Empty ? errMessage : invoiceId));
        }
 void SaveInvReceipt(int receiptId, string invReceiptJson, SqlTransaction tran)
 {
     try
     {
         SelInvoiceDT invDT = new SelInvoiceDT();
         List <SelInvoiceReceiptContract> invReceipts = JsonConvert.DeserializeObject <List <SelInvoiceReceiptContract> >(invReceiptJson);
         foreach (SelInvoiceReceiptContract invReceipt in invReceipts)
         {
             invReceipt.Receiptid = receiptId;
             invDT.Update(new string[] { " TotalDebt" }, new string[] { " TotalDebt-" + invReceipt.Total }, " ID=" + invReceipt.Invoiceid);
             invReceiptDT.Insert(invReceipt, tran);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public HttpResponseMessage Save(string selinvoiceJson)
        {
            string errMessage = string.Empty;

            try
            { SelInvoiceContract selinvoice = JsonConvert.DeserializeObject <SelInvoiceContract>(selinvoiceJson);
              businessRule.RegistInstants(selinvoice);
              if (selinvoice.Id == 0)
              {
                  businessRule.RegistRule("Insert");
                  if (businessRule.CheckRules(out errMessage))
                  {
                      return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(selinvoice)));
                  }
                  else
                  {
                      return(handleBRFailed(errMessage));
                  }
              }
              else
              {
                  businessRule.RegistRule("Update");
                  if (businessRule.CheckRules(out errMessage))
                  {
                      return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(selinvoice)));
                  }
                  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."));
            }
        }