Exemplo n.º 1
0
        public ActionResult Add(int ListId, int MovieId)
        {
            bool isOwner = listRepo.Find(l => l.UserId == SessionUserId && l.Id == ListId).Any();
            bool exists = listMovieRepo.Find(l => l.ListId == ListId && l.MovieId == MovieId).Any();

            if (isOwner && !exists)
            {
                // index movie if it doesnt exist in our database
                var m = new MovieController();
                m.Add(MovieId);

                listMovieRepo.Add(new ListMovie()
                {
                    ListId = ListId,
                    MovieId = MovieId,
                    Created = DateTime.Now
                });

                listMovieRepo.Complete();

                return RedirectToRoute("list", new { ListId = ListId });
            }

            return RedirectBack();
        }
Exemplo n.º 2
0
        public JsonResult AjaxDo(int ListId, int MovieId, string Do)
        {
            bool isOwner = listRepo.Find(l => l.UserId == SessionUserId && l.Id == ListId).Any();
            if(!isOwner)
            {
                return Json("false");
            }

            if (Do == "add")
            {
                bool exists = listMovieRepo.Find(l => l.ListId == ListId && l.MovieId == MovieId).Any();
                if (!exists)
                {
                    var m = new MovieController();
                    m.Add(MovieId);

                    listMovieRepo.Add(new ListMovie()
                    {
                        ListId = ListId,
                        MovieId = MovieId,
                        Created = DateTime.Now
                    });

                    listMovieRepo.Complete();
                    return Json("true");
                }
            }

            if (Do == "remove")
            {
                var list = listRepo.Get(ListId);

                if (list.UserId == SessionUserId)
                {
                    var item = listMovieRepo.Find(x => x.ListId == ListId && x.MovieId == MovieId).First();

                    listMovieRepo.Remove(item);

                    listMovieRepo.Complete();
                    return Json("true");
                }
            }

            return Json("false");
        }