Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Table("Post")]
- public partial class Post
- {
- public int PostID { get; set; }
- [Required]
- [StringLength(256)]
- public string Title { get; set; }
- [StringLength(256)]
- public string Description { get; set; }
- [StringLength(256)]
- public string Picture { get; set; }
- public int CategoryID { get; set; }
- [StringLength(10)]
- public string ViewNumber { get; set; }
- public int UserID { get; set; }
- public DateTime CreateDate { get; set; }
- public int LikeNumber { get; set; }
- public int? CommentID { get; set; }
- }
- [HttpPost]
- public ActionResult UpPost(Post model, HttpPostedFileBase txtImg)
- {
- var db = new ShareImageDbContext();
- if (ModelState.IsValid)
- {
- if (txtImg != null)
- {
- txtImg.SaveAs(HttpContext.Server.MapPath("~/Images/")
- + txtImg.FileName);
- var post = new Post();
- post.PostID = model.PostID;
- post.Title = model.Title;
- post.Description = model.Description;
- post.CategoryID = model.CategoryID;
- var userSession = new UserLogin();
- userSession = (UserLogin)Session[ShareImage.Common.CommonConstants.USER_SESSION];
- post.UserID = userSession.UserID;
- post.CreateDate = DateTime.Now;
- post.Picture = txtImg.FileName;
- db.Posts.Add(post);
- db.SaveChanges();
- return RedirectToAction("Index", "Homeuser");
- }
- else
- {
- ModelState.AddModelError("", "Đăng ảnh thất bại!");
- }
- }
- return View(txtImg);
- }
- @model IEnumerable<Model.EF.Post>
- @foreach (var item in Model)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement