示例#1
0
        /// <summary>
        /// Insert đối tượng vào database
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        public string Insert(StaffProducttypeContract staffproducttype, SqlTransaction tran = null)
        {
            DataTable dtResult = null;
            string    query    = string.Format(@"INSERT INTO Staff_ProductType
                                        VALUES ({0},{1},{2})",

                                               (staffproducttype.Producttypeid != null? staffproducttype.Producttypeid.ToString() : "null").ToString(),
                                               (staffproducttype.Salestaffid != null? staffproducttype.Salestaffid.ToString() : "null").ToString(),
                                               (staffproducttype.Seeall != null? "'" + SQLHelper.RejectInjection(staffproducttype.Seeall.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("");
        }
示例#2
0
 override public void RegistInstants(params object[] instants)
 {
     if (instants.Length > 0)
     {
         this.staffproducttypeContract = (StaffProducttypeContract)(instants[0]);
     }
 }
示例#3
0
        public HttpResponseMessage SaveProduct(string staffJson, string groupJson, string productTypeJson)
        {
            string         staffId = "";
            SqlTransaction tran    = DataProvider.beginTrans();

            try
            {
                CatSalestaffContract staff          = JsonConvert.DeserializeObject <CatSalestaffContract>(staffJson);
                string[]             mgntGroupIds   = JsonConvert.DeserializeObject <string[]>(groupJson);
                string[]             productTypeIds = JsonConvert.DeserializeObject <string[]>(productTypeJson);
                if (staff.Id > 0)
                {
                    staffId = staffDT.Update(staff, tran);
                }
                else
                {
                    staffId = staffDT.Insert(staff, tran);
                }
                deleteOldStaffGroup(staffId, tran);
                foreach (string groupID in mgntGroupIds)
                {
                    StaffMgntgroupContract staffMgntGroup = new StaffMgntgroupContract()
                    {
                        Salestaffid = Converter.ToInt32(staffId), Managementgroupid = Converter.ToInt32(groupID)
                    };
                    staffMgntGroupDT.Insert(staffMgntGroup, tran);
                }
                deleteOldProductType(staffId, tran);
                foreach (string productTypeId in productTypeIds)
                {
                    StaffProducttypeContract staffProductypeContract = new StaffProducttypeContract()
                    {
                        Producttypeid = Converter.ToInt32(productTypeId), Salestaffid = Converter.ToInt32(staffId)
                    };
                    staffProductTypeDT.Insert(staffProductypeContract, tran);
                }
                DataProvider.CommitTrans(tran);
            }
            catch (Exception e)
            {
                DataProvider.RollbackTrans(tran);
                ExceptionHandler.Log(e);
                return(null);
            }
            return(Request.CreateResponse <string>(HttpStatusCode.OK, staffId));
        }
示例#4
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(StaffProducttypeContract staffproducttype, SqlTransaction tran = null)
        {
            string query = String.Format("UPDATE " + TableName + @" SET ProductTypeID={0},SaleStaffID={1},SeeAll={2}
                            WHERE ID=" + staffproducttype.Id.ToString(),
                                         (staffproducttype.Producttypeid != null? staffproducttype.Producttypeid.ToString() : "null").ToString(),
                                         (staffproducttype.Salestaffid != null? staffproducttype.Salestaffid.ToString() : "null").ToString(),
                                         (staffproducttype.Seeall != null? "'" + SQLHelper.RejectInjection(staffproducttype.Seeall.ToString()) + "'" : "null").ToString());

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

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