Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. [Table("Post")]
  2. public partial class Post
  3. {
  4. public int PostID { get; set; }
  5.  
  6. [Required]
  7. [StringLength(256)]
  8. public string Title { get; set; }
  9.  
  10. [StringLength(256)]
  11. public string Description { get; set; }
  12.  
  13. [StringLength(256)]
  14. public string Picture { get; set; }
  15.  
  16. public int CategoryID { get; set; }
  17.  
  18. [StringLength(10)]
  19. public string ViewNumber { get; set; }
  20.  
  21. public int UserID { get; set; }
  22.  
  23. public DateTime CreateDate { get; set; }
  24.  
  25. public int LikeNumber { get; set; }
  26.  
  27. public int? CommentID { get; set; }
  28. }
  29.  
  30. [HttpPost]
  31. public ActionResult UpPost(Post model, HttpPostedFileBase txtImg)
  32. {
  33. var db = new ShareImageDbContext();
  34.  
  35. if (ModelState.IsValid)
  36. {
  37. if (txtImg != null)
  38. {
  39. txtImg.SaveAs(HttpContext.Server.MapPath("~/Images/")
  40. + txtImg.FileName);
  41. var post = new Post();
  42. post.PostID = model.PostID;
  43. post.Title = model.Title;
  44. post.Description = model.Description;
  45. post.CategoryID = model.CategoryID;
  46. var userSession = new UserLogin();
  47. userSession = (UserLogin)Session[ShareImage.Common.CommonConstants.USER_SESSION];
  48. post.UserID = userSession.UserID;
  49. post.CreateDate = DateTime.Now;
  50. post.Picture = txtImg.FileName;
  51. db.Posts.Add(post);
  52. db.SaveChanges();
  53.  
  54. return RedirectToAction("Index", "Homeuser");
  55. }
  56.  
  57. else
  58. {
  59. ModelState.AddModelError("", "Đăng ảnh thất bại!");
  60. }
  61. }
  62. return View(txtImg);
  63. }
  64.  
  65. @model IEnumerable<Model.EF.Post>
  66.  
  67. @foreach (var item in Model)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement