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

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

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

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