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

                                               (admcontext.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(admcontext.Code.ToString()) + "'" : "null").ToString(),
                                               (admcontext.Name.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(admcontext.Name.ToString()) + "'" : "null").ToString(),
                                               (admcontext.Devname.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(admcontext.Devname.ToString()) + "'" : "null").ToString(),
                                               (admcontext.Mapid != null? admcontext.Mapid.ToString() : "null").ToString(),
                                               (admcontext.Type.Trim() != String.Empty ? admcontext.Type.ToString() : "null").ToString(),
                                               (admcontext.Rootmap.Trim() != String.Empty ? admcontext.Rootmap.ToString() : "null").ToString(),
                                               (admcontext.Ordernum.Trim() != String.Empty ? admcontext.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(AdmContextContract admcontext, SqlTransaction tran = null)
        {
            string query = String.Format("UPDATE " + TableName + @" SET Code={0},Name={1},DevName={2},MapID={3},Type={4},RootMap={5},OrderNum={6}
                            WHERE ID=" + admcontext.Id.ToString(),
                                         (admcontext.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(admcontext.Code.ToString()) + "'" : "null").ToString(),
                                         (admcontext.Name.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(admcontext.Name.ToString()) + "'" : "null").ToString(),
                                         (admcontext.Devname.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(admcontext.Devname.ToString()) + "'" : "null").ToString(),
                                         (admcontext.Mapid != null? admcontext.Mapid.ToString() : "null").ToString(),
                                         (admcontext.Type.Trim() != String.Empty ? admcontext.Type.ToString() : "null").ToString(),
                                         (admcontext.Rootmap.Trim() != String.Empty ? admcontext.Rootmap.ToString() : "null").ToString(),
                                         (admcontext.Ordernum.Trim() != String.Empty ? admcontext.Ordernum.ToString() : "null").ToString());

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

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