Esempio n. 1
0
 public IHttpActionResult UploadCostPhoto()
 {
     try
     {
         int Height = Convert.ToInt32(requestHelper.GetRequsetForm("Height", ""));
         int Weight = Convert.ToInt32(requestHelper.GetRequsetForm("Weight", ""));
         WebApi_BLL.T_Forum_Photo bll = new WebApi_BLL.T_Forum_Photo();
         string         Path          = HttpContext.Current.Server.MapPath("/Content/User_Photo/");
         HttpPostedFile file          = HttpContext.Current.Request.Files[0];
         //if(file.ContentLength >)
         string fileExtName = file.FileName.Substring(file.FileName.LastIndexOf("."));
         string newName     = Guid.NewGuid().ToString() + fileExtName;
         string savePath    = Path + newName;
         file.SaveAs(savePath);
         WebApi_Model.T_Forum_Photo model = new WebApi_Model.T_Forum_Photo();
         model.Photo      = newName;
         model.UploadTime = DateTime.Now;
         model.Height     = Height;
         model.Weight     = Weight;
         int key = bll.Add(model);
         model.ForumPhotoID = key;
         return(Ok(ReturnJsonResult.GetJsonResult(1, "OK", JsonConvert.SerializeObject(model))));
     }
     catch (SystemException ex)
     {
         return(Ok(ReturnJsonResult.GetJsonResult(-1, "Error", ex.Message)));
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(WebApi_Model.T_Forum_Photo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update T_Forum_Photo set ");
            strSql.Append("ForumID=@ForumID,");
            strSql.Append("Photo=@Photo,");
            strSql.Append("UploadTime=@UploadTime,");
            strSql.Append("PayType=@PayType,");
            strSql.Append("Height=@Height,");
            strSql.Append("Weight=@Weight");
            strSql.Append(" where ForumPhotoID=@ForumPhotoID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ForumID",      SqlDbType.Int,        4),
                new SqlParameter("@Photo",        SqlDbType.NVarChar,  50),
                new SqlParameter("@UploadTime",   SqlDbType.DateTime),
                new SqlParameter("@PayType",      SqlDbType.Int,        4),
                new SqlParameter("@Height",       SqlDbType.Int,        4),
                new SqlParameter("@Weight",       SqlDbType.Int,        4),
                new SqlParameter("@ForumPhotoID", SqlDbType.Int, 4)
            };
            parameters[0].Value = model.ForumID;
            parameters[1].Value = model.Photo;
            parameters[2].Value = model.UploadTime;
            parameters[3].Value = model.PayType;
            parameters[4].Value = model.Height;
            parameters[5].Value = model.Weight;
            parameters[6].Value = model.ForumPhotoID;

            int rows = DBHelper.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(WebApi_Model.T_Forum_Photo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into T_Forum_Photo(");
            strSql.Append("ForumID,Photo,UploadTime,PayType,Height,Weight)");
            strSql.Append(" values (");
            strSql.Append("@ForumID,@Photo,@UploadTime,@PayType,@Height,@Weight)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ForumID",    SqlDbType.Int,        4),
                new SqlParameter("@Photo",      SqlDbType.NVarChar,  50),
                new SqlParameter("@UploadTime", SqlDbType.DateTime),
                new SqlParameter("@PayType",    SqlDbType.Int,        4),
                new SqlParameter("@Height",     SqlDbType.Int,        4),
                new SqlParameter("@Weight",     SqlDbType.Int, 4)
            };
            parameters[0].Value = model.ForumID;
            parameters[1].Value = model.Photo;
            parameters[2].Value = model.UploadTime;
            parameters[3].Value = model.PayType;
            parameters[4].Value = model.Height;
            parameters[5].Value = model.Weight;

            object obj = DBHelper.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Esempio n. 4
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public WebApi_Model.T_Forum_Photo DataRowToModel(DataRow row)
 {
     WebApi_Model.T_Forum_Photo model = new WebApi_Model.T_Forum_Photo();
     if (row != null)
     {
         if (row["ForumPhotoID"] != null && row["ForumPhotoID"].ToString() != "")
         {
             model.ForumPhotoID = int.Parse(row["ForumPhotoID"].ToString());
         }
         if (row["ForumID"] != null && row["ForumID"].ToString() != "")
         {
             model.ForumID = int.Parse(row["ForumID"].ToString());
         }
         if (row["Photo"] != null)
         {
             model.Photo = row["Photo"].ToString();
         }
         if (row["UploadTime"] != null && row["UploadTime"].ToString() != "")
         {
             model.UploadTime = DateTime.Parse(row["UploadTime"].ToString());
         }
         if (row["PayType"] != null && row["PayType"].ToString() != "")
         {
             model.PayType = int.Parse(row["PayType"].ToString());
         }
         if (row["Height"] != null && row["Height"].ToString() != "")
         {
             model.Height = int.Parse(row["Height"].ToString());
         }
         if (row["Weight"] != null && row["Weight"].ToString() != "")
         {
             model.Weight = int.Parse(row["Weight"].ToString());
         }
     }
     return(model);
 }
Esempio n. 5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public WebApi_Model.T_Forum_Photo GetModel(int ForumPhotoID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ForumPhotoID,ForumID,Photo,UploadTime,PayType,Height,Weight from T_Forum_Photo ");
            strSql.Append(" where ForumPhotoID=@ForumPhotoID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ForumPhotoID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ForumPhotoID;

            WebApi_Model.T_Forum_Photo model = new WebApi_Model.T_Forum_Photo();
            DataSet ds = DBHelper.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }