Ejemplo n.º 1
0
        /// <summary>
        /// Insert đối tượng vào database
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        public string Insert(CatDistrictContract catdistrict, SqlTransaction tran = null)
        {
            DataTable dtResult = null;
            string    query    = string.Format(@"INSERT INTO Cat_District
                                        VALUES ({0},{1},{2},{3},{4})",

                                               (catdistrict.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catdistrict.Code.ToString()) + "'" : "null").ToString(),
                                               (catdistrict.Name.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catdistrict.Name.ToString()) + "'" : "null").ToString(),
                                               (catdistrict.Provinceid != null? catdistrict.Provinceid.ToString() : "null").ToString(),
                                               (catdistrict.Description.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catdistrict.Description.ToString()) + "'" : "null").ToString(),
                                               (catdistrict.Ordernum.Trim() != String.Empty ? catdistrict.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.º 2
0
 override public void RegistInstants(params object[] instants)
 {
     if (instants.Length > 0)
     {
         this.catdistrictContract = (CatDistrictContract)(instants[0]);
     }
 }
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(CatDistrictContract catdistrict, SqlTransaction tran = null)
        {
            string query = String.Format("UPDATE " + TableName + @" SET Code={0},Name={1},ProvinceID={2},Description={3},OrderNum={4}
                            WHERE ID=" + catdistrict.Id.ToString(),
                                         (catdistrict.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catdistrict.Code.ToString()) + "'" : "null").ToString(),
                                         (catdistrict.Name.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catdistrict.Name.ToString()) + "'" : "null").ToString(),
                                         (catdistrict.Provinceid != null? catdistrict.Provinceid.ToString() : "null").ToString(),
                                         (catdistrict.Description.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catdistrict.Description.ToString()) + "'" : "null").ToString(),
                                         (catdistrict.Ordernum.Trim() != String.Empty ? catdistrict.Ordernum.ToString() : "null").ToString());

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

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