public ActionResult AddToFav([ModelBinder(typeof(UserModelBinder))] User user, Guid id) { var film = FilmsDao.Find(id); user.FavFilms.Add(film); var cookie = new HttpCookie(nameof(User)) { Value = JsonConvert.SerializeObject(user), Expires = DateTime.Now.AddYears(1), Path = "/" }; Response.Cookies.Add(cookie); return(RedirectToAction("Index", "Films")); }
public ActionResult DoDelete([ModelBinder(typeof(UserModelBinder))] User user, Guid id) { var toRemove = FilmsDao.Find(id); if (user.HasFavourite(id)) { user.FavFilms.RemoveAll(f => f.ID == id); var cookie = new HttpCookie(nameof(User)) { Value = JsonConvert.SerializeObject(user), Expires = DateTime.Now.AddYears(1), Path = "/" }; Response.Cookies.Add(cookie); } FilmsDao.Delete(toRemove); return(RedirectToAction("Index")); }