public ActionResult Delete(int Id)
        {
            MoviesModel context    = new MoviesModel();
            Users       loggedUser = (Users)Session["loggedUser"];

            MyLibrary item = context.MyLibrary.Where(u => u.MovieLibraryId == Id && u.UserId == loggedUser.UseId).FirstOrDefault();

            if (item != null)
            {
                context.MyLibrary.Remove(item);
                context.SaveChanges();

                return(RedirectToAction("Index", "MyLibrary"));
            }
            else
            {
                return(RedirectToAction("Index", "MyLibrary"));
            }
        }
Exemple #2
0
        public ActionResult AddOrEdit(Users user)
        {
            using (MoviesModel db = new MoviesModel())
            {
                if (db.Users.Any(x => x.Username == user.Username))
                {
                    ViewBag.DuplicateMessage = "Username already exist!";
                    return(View("AddOrEdit", user));
                }
                else
                {
                    db.Users.Add(user);
                    db.SaveChanges();
                }
            }
            ModelState.Clear();
            ViewBag.SuccesMessage = "Registration Successful!!";

            return(RedirectToAction("Index", "Login"));
        }
Exemple #3
0
        public ActionResult AddMovie(MoviesTable movies)
        {
            using (MoviesModel db = new MoviesModel())
            {
                if (db.MoviesTable.Any(x => x.MovieName == movies.MovieName))
                {
                    ViewBag.DuplicateMessage = "Movie already exist!!";
                    return(View("AddMovie", movies));
                }
                else
                {
                    db.MoviesTable.Add(movies);
                    db.SaveChanges();
                }
            }

            ModelState.Clear();
            ViewBag.SuccesMessage = "Add successful!!!";

            return(View("AddMovie", new MoviesTable()));
        }
        public ActionResult Add(int?Id)
        {
            Users       loggedUser = (Users)Session["loggedUser"];
            MoviesModel context    = new MoviesModel();
            MyLibrary   myLib      = new MyLibrary();
            MoviesTable item       = Id == null ? new MoviesTable() : context.MoviesTable.Where(u => u.MovieId == Id.Value).FirstOrDefault();

            if (item == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            myLib.UserId    = loggedUser.UseId;
            myLib.MovieId   = item.MovieId;
            myLib.UserName  = loggedUser.Username;
            myLib.MovieName = item.MovieName;
            context.MyLibrary.Add(myLib);

            context.SaveChanges();

            return(RedirectToAction("Index", "Movies"));
        }