예제 #1
0
        public HttpResponseMessage Save(string guaranteeJson, string guaranteeDetailsJson)
        {
            string guaranteeId = "";
            string errMessage  = "";
            BuyGuaranteeContract guaranteeDTO = JsonConvert.DeserializeObject <BuyGuaranteeContract>(guaranteeJson);

            BuyGuaranteeDetailContract[] guaranteeDetailDTOs = JsonConvert.DeserializeObject <BuyGuaranteeDetailContract[]>(guaranteeDetailsJson);
            SqlTransaction tran = DataProvider.beginTrans();

            try
            {
                businessRule.RegistInstants(guaranteeDTO);
                if (guaranteeDTO.Id > 0)
                {
                    guaranteeId = guaranteeDT.Update(guaranteeDTO, tran);
                }
                else
                {
                    businessRule.RegistRule("Insert");
                    if (businessRule.CheckRules(out errMessage))
                    {
                        guaranteeId = guaranteeDT.Insert(guaranteeDTO, tran);
                    }
                    else
                    {
                        return(handleBRFailed(errMessage, tran));
                    }
                }
                if (Converter.ToInt32(guaranteeId) > 0)
                {
                    deleteDetail(guaranteeId, tran);
                    foreach (BuyGuaranteeDetailContract invoiceDetailDTO in guaranteeDetailDTOs)
                    {
                        invoiceDetailDTO.Guaranteeid = Converter.ToInt32(guaranteeId);
                        guaranteeDetailDT.Insert(invoiceDetailDTO, tran);
                    }
                }
                DataProvider.CommitTrans(tran);
            }
            catch (Exception e)
            {
                DataProvider.RollbackTrans(tran);
                ExceptionHandler.Log(e);
            }
            return(Request.CreateResponse <string>(HttpStatusCode.OK, errMessage != string.Empty ? errMessage : guaranteeId));
        }
예제 #2
0
        public HttpResponseMessage Save(string buyguaranteeJson)
        {
            string errMessage = string.Empty;

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