コード例 #1
0
        public HttpResponseMessage Save(string exchangeJson, string exchangeDetailsJson)
        {
            string exchangeId = "";
            string errMessage = "";
            StoExchangeContract exchangeDTO = JsonConvert.DeserializeObject <StoExchangeContract>(exchangeJson);

            StoExchangeDetailContract[] exchangeDetailDTOs = JsonConvert.DeserializeObject <StoExchangeDetailContract[]>(exchangeDetailsJson);
            SqlTransaction tran = DataProvider.beginTrans();

            try
            {
                businessRule.RegistInstants(exchangeDTO);
                if (exchangeDTO.Id > 0)
                {
                    exchangeId = exchangeDT.Update(exchangeDTO, tran);
                }
                else
                {
                    businessRule.RegistRule("Insert");
                    if (businessRule.CheckRules(out errMessage))
                    {
                        exchangeId = exchangeDT.Insert(exchangeDTO, tran);
                    }
                    else
                    {
                        return(handleBRFailed(errMessage, tran));
                    }
                }
                if (Converter.ToInt32(exchangeId) > 0)
                {
                    foreach (StoExchangeDetailContract exchangeDetailDTO in exchangeDetailDTOs)
                    {
                        exchangeDetailDTO.Exchangeid = Converter.ToInt32(exchangeId);
                        exchangeDetailDT.Insert(exchangeDetailDTO, tran);
                        errMessage = StoreModel.Exchange(exchangeDTO, exchangeDetailDTO, 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 : exchangeId));
        }
コード例 #2
0
        public HttpResponseMessage Save(string stoexchangeJson)
        {
            string errMessage = string.Empty;

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