public ActionResult Create(StructurePost data, ObjFile doc)
        {
            var filePath = "";

            if (Session["uid"] != null)
            {
                data.userid = Session["uid"].ToString();
            }
            foreach (var file in doc.files)
            {
                if (file != null)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    filePath = Path.Combine(Server.MapPath("~/Files"), fileName);
                    file.SaveAs(filePath);
                }
                else
                {
                    filePath = "";
                }
            }

            PostBLL.Post_CreateNewPost(data, filePath);
            return(RedirectToAction("Index", "Home"));
        }
 /// <summary>
 /// Tạo mới bài post
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public bool CreateNewPost(StructurePost data, string filePath)
 {
     try
     {
         Post pst = new Post()
         {
             //postid = 0,
             title        = data.title,
             anonymous    = data.anonymous == "on",
             tag          = data.tag,
             userid       = Convert.ToInt32(data.userid),
             content      = data.content,
             view         = 0,
             like         = 0,
             dislike      = 0,
             datetimepost = DateTime.Now,
             filePath     = filePath
         };
         db.Posts.Add(pst);
         db.SaveChanges();
         Email(data.content, "", "");
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Exemple #3
0
 /// <summary>
 /// Tạo mới bài post
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public static bool Post_CreateNewPost(StructurePost data, string filePath)
 {
     return(pstDAL.CreateNewPost(data, filePath));
 }