Example #1
0
        /// <summary>
        /// Insert đối tượng vào database
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        public string Insert(AdmMapContract admmap, SqlTransaction tran = null)
        {
            DataTable dtResult = null;
            string    query    = string.Format(@"INSERT INTO Adm_Map
                                        VALUES ({0},{1},{2},{3},{4},{5})",

                                               (admmap.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(admmap.Code.ToString()) + "'" : "null").ToString(),
                                               (admmap.Name.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(admmap.Name.ToString()) + "'" : "null").ToString(),
                                               (admmap.Path.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(admmap.Path.ToString()) + "'" : "null").ToString(),
                                               (admmap.Parentid != null? admmap.Parentid.ToString() : "null").ToString(),
                                               (admmap.Pathlevel.Trim() != String.Empty ? admmap.Pathlevel.ToString() : "null").ToString(),
                                               (admmap.Ordernum.Trim() != String.Empty ? admmap.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("");
        }
Example #2
0
 override public void RegistInstants(params object[] instants)
 {
     if (instants.Length > 0)
     {
         this.admmapContract = (AdmMapContract)(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(AdmMapContract admmap, SqlTransaction tran = null)
        {
            string query = String.Format("UPDATE " + TableName + @" SET Code={0},Name={1},Path={2},ParentID={3},PathLevel={4},OrderNum={5}
                            WHERE ID=" + admmap.Id.ToString(),
                                         (admmap.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(admmap.Code.ToString()) + "'" : "null").ToString(),
                                         (admmap.Name.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(admmap.Name.ToString()) + "'" : "null").ToString(),
                                         (admmap.Path.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(admmap.Path.ToString()) + "'" : "null").ToString(),
                                         (admmap.Parentid != null? admmap.Parentid.ToString() : "null").ToString(),
                                         (admmap.Pathlevel.Trim() != String.Empty ? admmap.Pathlevel.ToString() : "null").ToString(),
                                         (admmap.Ordernum.Trim() != String.Empty ? admmap.Ordernum.ToString() : "null").ToString());

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

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