示例#1
0
 public bool UpdateJoke(T_Joke joke)
 {
     return jokeData.Update(joke);
 }
示例#2
0
 public int AddJoke(T_Joke joke)
 {
     int jokeid = jokeData.Add(joke);
     return jokeid;
 }
示例#3
0
        public ActionResult PostJoke(string joketitle, string jokecontent, int joketype, int jokecategory,HttpPostedFileBase jokeImgFile)
        {
            string content = "";
            if(joketype==0)
            {
                content = jokecontent;
            }
            else if(joketype==1)
            {
                FileInfoHelper.GetFileName(jokeImgFile.FileName);
                FileInfoHelper.GetFileExtend(jokeImgFile.FileName);
                string newName = FileInfoHelper.GetNewName(jokeImgFile.FileName);
                if (Request.IsLocal)
                {
                    newName = string.Format("local_{0}",newName);
                }
                else
                {
                    newName = string.Format("online_{0}", newName);
                }
                string uploadFolder = string.Format("{3}\\{0}\\{1}\\{2}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, JokeImgUpload);
                if (!Directory.Exists(uploadFolder))
                {
                    Directory.CreateDirectory(uploadFolder);
                }
                //
                jokeImgFile.SaveAs(uploadFolder + "\\" + newName);
                Thread.Sleep(1);
                string fileName = jokeImgFile.FileName;
                content = string.Format("{0}\\{1}\\{2}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day) + "\\" + newName;
                if(AppConfig.IsQiniuUpload>0)
                {
                    bool updateResult = QiniuUpload.PutFile(newName, uploadFolder + "\\" + newName);
                }

            }

            T_Joke jokeinfo = new T_Joke()
            {
                AddDate = DateTime.Now,
                Category = jokecategory,
                CheckDate = DateTime.Parse("1900-01-01"),
                CheckUserId = 0,
                CommentCount = 0,
                Content = content,
                HateCount = 0,
                LikeCount = 0,
                PostID = user.UserId,
                State = 0,
                Title = joketitle,
                Type = joketype
            };

            if(user.IsAdmin>0)
            {
                jokeinfo.State = 1;
                jokeinfo.CheckDate = DateTime.Now;
                jokeinfo.CheckUserId = user.UserId;
            }
            int jokeId=jokeBusinessLogic.AddJoke(jokeinfo);
            PostJokeResult postResult = new PostJokeResult() {
                Success = jokeId>0?true:false,
                Message = jokeId>0?"发表成功":"发表失败"
            };

            return RedirectToAction("PostJokeResult", postResult);
        }