public ActionResult View(int id) { var model = new ViewBoardModel(); using (var db = new lookatmyskateboardEntities()) { var board = db.Skateboards.Include(x => x.User).Include(x => x.Comments).First(x => x.id == id); model.Board = new BoardModel { Id = board.id, Name = board.name, Description = board.description, ImageUrl = board.imageUrl, UploadedBy = board.User.username }; model.Comments = board.Comments.Select(x => new CommentModel { User = x.User.username, Text = x.Text }).ToList(); model.NewComment = new CommentModel { Text = string.Empty, UserId = Session["User"] != null ? (Session["User"] as UserAccount).UserId : new int?(), User = Session["User"] != null ? (Session["User"] as UserAccount).Username : string.Empty }; if (Session["User"] != null) { model.Liked = board.Likes.Contains(db.Users.Find((Session["User"] as UserAccount).UserId)); } } return(View(model)); }
public ActionResult Like(int boardId, int userId) { using (var db = new lookatmyskateboardEntities()) { db.Users.Find(userId).Likes.Add(db.Skateboards.Find(boardId)); db.SaveChanges(); } return(RedirectToAction("View", new { id = boardId })); }
// GET: Boards public ActionResult Index() { var model = new List <BoardModel>(); using (var db = new lookatmyskateboardEntities()) { model.AddRange(db.Skateboards.Select(skateboard => new BoardModel { Id = skateboard.id, Name = skateboard.name, ImageUrl = skateboard.imageUrl, Description = skateboard.description, UploadedBy = skateboard.User.username })); } return(View(model)); }
public ActionResult Register(User model) { if (!ModelState.IsValid) { return(View(model)); } using (var db = new lookatmyskateboardEntities()) { db.Users.Add(model); db.SaveChanges(); } return(RedirectToAction("Login", "Account")); }
public ActionResult ResetAdminPassword(ResetAdminPassword model) { if (Session["User"] == null || (Session["User"] as UserAccount).Username != "admin") { return(Content("Not authorised")); } using (var db = new lookatmyskateboardEntities()) { var user = db.Users.Find(1); user.password = model.Password; db.SaveChanges(); } Session.Abandon(); return(RedirectToAction("Index", "Home")); }