Ejemplo n.º 1
0
 override public void RegistInstants(params object[] instants)
 {
     if (instants.Length > 0)
     {
         this.catproducttypeContract = (CatProducttypeContract)(instants[0]);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Insert đối tượng vào database
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        public string Insert(CatProducttypeContract catproducttype, SqlTransaction tran = null)
        {
            DataTable dtResult = null;
            string    query    = string.Format(@"INSERT INTO Cat_ProductType
                                        VALUES ({0},{1},{2},{3})",

                                               (catproducttype.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catproducttype.Code.ToString()) + "'" : "null").ToString(),
                                               (catproducttype.Name.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catproducttype.Name.ToString()) + "'" : "null").ToString(),
                                               (catproducttype.Description.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catproducttype.Description.ToString()) + "'" : "null").ToString(),
                                               (catproducttype.Ordernum.Trim() != String.Empty ? catproducttype.Ordernum.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("");
        }
Ejemplo n.º 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(CatProducttypeContract catproducttype, SqlTransaction tran = null)
        {
            string query = String.Format("UPDATE " + TableName + @" SET Code={0},Name={1},Description={2},OrderNum={3}
                            WHERE ID=" + catproducttype.Id.ToString(),
                                         (catproducttype.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catproducttype.Code.ToString()) + "'" : "null").ToString(),
                                         (catproducttype.Name.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catproducttype.Name.ToString()) + "'" : "null").ToString(),
                                         (catproducttype.Description.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catproducttype.Description.ToString()) + "'" : "null").ToString(),
                                         (catproducttype.Ordernum.Trim() != String.Empty ? catproducttype.Ordernum.ToString() : "null").ToString());

            if (tran == null)
            {
                DataProvider.ExecuteNonQuery(query);
            }
            else
            {
                DataProvider.ExecuteNonQueryWithTransaction(query, tran);
            }
            return(catproducttype.Id.ToString());
        }
Ejemplo n.º 4
0
        public HttpResponseMessage Save(string catproducttypeJson)
        {
            string errMessage = string.Empty;

            try
            { CatProducttypeContract catproducttype = JsonConvert.DeserializeObject <CatProducttypeContract>(catproducttypeJson);
              businessRule.RegistInstants(catproducttype);
              if (catproducttype.Id == 0)
              {
                  businessRule.RegistRule("Insert");
                  if (businessRule.CheckRules(out errMessage))
                  {
                      return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(catproducttype)));
                  }
                  else
                  {
                      return(handleBRFailed(errMessage));
                  }
              }
              else
              {
                  businessRule.RegistRule("Update");
                  if (businessRule.CheckRules(out errMessage))
                  {
                      return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(catproducttype)));
                  }
                  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."));
            }
        }
Ejemplo n.º 5
0
 public CatProducttypeRule ValidateInstant(CatProducttypeContract dto)
 {
     return(this);
 }