Exemplo n.º 1
0
        public HttpResponseMessage Save(string guarReturnJson, string guarReturnDetailsJson)
        {
            string             guarReturnId  = "";
            string             errMessage    = "";
            GuarReturnContract guarReturnDTO = JsonConvert.DeserializeObject <GuarReturnContract>(guarReturnJson);

            GuarReturnDetailContract[] guarReturnDetailDTOs = JsonConvert.DeserializeObject <GuarReturnDetailContract[]>(guarReturnDetailsJson);
            SqlTransaction             tran = DataProvider.beginTrans();

            try
            {
                businessRule.RegistInstants(guarReturnDTO);
                if (guarReturnDTO.Id > 0)
                {
                    guarReturnId = guarReturnDT.Update(guarReturnDTO, tran);
                }
                else
                {
                    businessRule.RegistRule("Insert");
                    if (businessRule.CheckRules(out errMessage))
                    {
                        guarReturnId = guarReturnDT.Insert(guarReturnDTO, tran);
                    }
                    else
                    {
                        return(handleBRFailed(errMessage, tran));
                    }
                }
                if (Converter.ToInt32(guarReturnId) > 0)
                {
                    deleteDetail(guarReturnId, tran);
                    foreach (GuarReturnDetailContract invoiceDetailDTO in guarReturnDetailDTOs)
                    {
                        invoiceDetailDTO.Guarreturnid = Converter.ToInt32(guarReturnId);
                        guarReturnDetailDT.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 : guarReturnId));
        }
Exemplo n.º 2
0
        public HttpResponseMessage Save(string guarreturnJson)
        {
            string errMessage = string.Empty;

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