Exemple #1
0
        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"));
        }
Exemple #2
0
        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"));
        }