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

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

            if (tran == null)
            {
                DataProvider.ExecuteNonQuery(query);
            }
            else
            {
                DataProvider.ExecuteNonQueryWithTransaction(query, tran);
            }
            return(catmanagementgroup.Id.ToString());
        }
        public HttpResponseMessage Save(string catmanagementgroupJson)
        {
            string errMessage = string.Empty;

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