Example #1
0
        /// <summary>
        /// Insert đối tượng vào database
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        public string Insert(ProducttypeCustomerContract producttypecustomer, SqlTransaction tran = null)
        {
            DataTable dtResult = null;
            string    query    = string.Format(@"INSERT INTO ProductType_Customer
                                        VALUES ({0},{1},convert(datetime,{2},103))",

                                               (producttypecustomer.Producttypeid != null? producttypecustomer.Producttypeid.ToString() : "null").ToString(),
                                               (producttypecustomer.Customerid != null? producttypecustomer.Customerid.ToString() : "null").ToString(),
                                               (producttypecustomer.Getindate != null? "'" + SQLHelper.RejectInjection(producttypecustomer.Getindate.ToString()) + "'" : "null").ToString());

            query += " ; select SCOPE_IDENTITY();";
            if (tran == null)
            {
                dtResult = DataProvider.ExecuteQuery(query);
            }
            else
            {
                dtResult = DataProvider.ExecuteQueryWithTransaction(query, tran);
            }
            if (dtResult != null && dtResult.Rows.Count > 0)
            {
                return(dtResult.Rows[0][0].ToString());
            }
            return("");
        }
Example #2
0
 override public void RegistInstants(params object[] instants)
 {
     if (instants.Length > 0)
     {
         this.producttypecustomerContract = (ProducttypeCustomerContract)(instants[0]);
     }
 }
Example #3
0
        /// <summary>
        /// Cập nhật thông tin đối tượng
        /// </summary>
        /// <param name="menu"></param>
        /// <param name="tran"></param>
        /// <returns></returns>
        public string Update(ProducttypeCustomerContract producttypecustomer, SqlTransaction tran = null)
        {
            string query = String.Format("UPDATE " + TableName + @" SET ProductTypeID={0},CustomerID={1},GetinDate=convert(datetime,{2},103)
                            WHERE ID=" + producttypecustomer.Id.ToString(),
                                         (producttypecustomer.Producttypeid != null? producttypecustomer.Producttypeid.ToString() : "null").ToString(),
                                         (producttypecustomer.Customerid != null? producttypecustomer.Customerid.ToString() : "null").ToString(),
                                         (producttypecustomer.Getindate != null? "'" + SQLHelper.RejectInjection(producttypecustomer.Getindate.ToString()) + "'" : "null").ToString());

            if (tran == null)
            {
                DataProvider.ExecuteNonQuery(query);
            }
            else
            {
                DataProvider.ExecuteNonQueryWithTransaction(query, tran);
            }
            return(producttypecustomer.Id.ToString());
        }
Example #4
0
        public HttpResponseMessage Save(string producttypecustomerJson)
        {
            string errMessage = string.Empty;

            try
            { ProducttypeCustomerContract producttypecustomer = JsonConvert.DeserializeObject <ProducttypeCustomerContract>(producttypecustomerJson);
              businessRule.RegistInstants(producttypecustomer);
              if (producttypecustomer.Id == 0)
              {
                  businessRule.RegistRule("Insert");
                  if (businessRule.CheckRules(out errMessage))
                  {
                      return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(producttypecustomer)));
                  }
                  else
                  {
                      return(handleBRFailed(errMessage));
                  }
              }
              else
              {
                  businessRule.RegistRule("Update");
                  if (businessRule.CheckRules(out errMessage))
                  {
                      return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(producttypecustomer)));
                  }
                  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."));
            }
        }
Example #5
0
 public ProducttypeCustomerRule ValidateInstant(ProducttypeCustomerContract dto)
 {
     return(this);
 }