Example #1
0
        public int uploadPic(HttpPostedFileBase file, HttpServerUtilityBase Server)
        {
            int id = 0;

            if (file.ContentLength > 0)
            {
                var fileName = Path.GetFileName(file.FileName);
                var path     = Path.Combine(Server.MapPath("../Uploads"), fileName);
                try
                {
                    file.SaveAs(path);
                }
                catch
                {
                    path = Path.Combine(Server.MapPath("../../Uploads"), fileName);
                    file.SaveAs(path);
                }
                MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6();
                PICTURES tempPic = new PICTURES();
                tempPic.PATH  = fileName;
                tempPic.TITLE = fileName;
                id            = entities.PICTURES.OrderByDescending(p => p.ID).First().ID + 1;
                tempPic.ID    = id;
                entities.PICTURES.AddObject(tempPic);
                entities.SaveChanges();
            }
            else
            {
                id = -1;
            }

            return(id);
        }
Example #2
0
        public PersonShow(PERSONS person)
        {
            this.person = person;

            MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6();

            List <PICTURES_PERSONS> tempPicId = entities.PICTURES_PERSONS.Where(pp => pp.PERSON_ID == person.ID).ToList();

            picturesList = new List <PICTURES>();

            foreach (var pic in tempPicId)
            {
                if (!pic.IS_POSTER)
                {
                    picturesList.Add(entities.PICTURES.Where(p => p.ID == pic.PICTURE_ID).First());
                }
                else
                {
                    poster    = entities.PICTURES.Where(p => p.ID == pic.PICTURE_ID).First().PATH;
                    posterId  = entities.PICTURES.Where(p => p.ID == pic.PICTURE_ID).First().ID;
                    altPoster = entities.PICTURES.Where(p => p.ID == pic.PICTURE_ID).First().TITLE;
                }
            }
            List <MOVIES_PERSONS_ROLES> tempMovieId = entities.MOVIES_PERSONS_ROLES.Where(pmr => pmr.PERSON_ID == person.ID).ToList();

            moviesList = new List <Movie>();

            foreach (var movie in tempMovieId)
            {
                moviesList.Add(new Movie(entities.MOVIES.Where(m => m.ID == movie.MOVIE_ID).First()));
                moviesList.Last().SetRole(person);
            }

            comments = entities.PERSONS_COMMENTS.Where(pc => pc.PERSON_ID == person.ID).ToList();
        }
Example #3
0
        public ActionResult Show(int id)
        {
            MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6();
            MovieShow             model    = new MovieShow(entities.MOVIES.Where(m => m.ID == id).FirstOrDefault());

            return(View(model));
        }
Example #4
0
        public ActionResult Show(int id)
        {
            MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6();
            PersonShow            model    = new PersonShow(entities.PERSONS.Where(p => p.ID == id).FirstOrDefault());

            return(View(model));
        }
Example #5
0
        public void RemoveMovie(MOVIES movie)
        {
            MOVIEADVISOREntities6 entities1 = new MOVIEADVISOREntities6();
            int tempId = movie.ID;

            foreach (var pm in entities1.PICTURES_MOVIES.Where(p => p.MOVIE_ID == movie.ID))
            {
                entities1.PICTURES_MOVIES.DeleteObject(pm);
            }
            entities1.SaveChanges();
            foreach (var mpr in entities1.MOVIES_PERSONS_ROLES.Where(p => p.MOVIE_ID == movie.ID))
            {
                entities1.MOVIES_PERSONS_ROLES.DeleteObject(mpr);
            }
            entities1.SaveChanges();
            foreach (var mpr in entities1.MOVIES_COMMENTS.Where(p => p.MOVIE_ID == movie.ID))
            {
                entities1.MOVIES_COMMENTS.DeleteObject(mpr);
            }
            entities1.SaveChanges();

            var tempGenres = entities1.MOVIES_GENRES.Where(mg => mg.MOVIE_ID == movie.ID);

            foreach (var gen in tempGenres)
            {
                entities1.MOVIES_GENRES.DeleteObject(gen);
            }

            entities1.SaveChanges();
            entities1.MOVIES.DeleteObject(entities1.MOVIES.Where(m => m.ID == tempId).First());
            entities1.SaveChanges();
        }
Example #6
0
        public MoviesListItem(MOVIES movie)
        {
            isRaited = false;
            MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6();
            var tempPosterId = entities.PICTURES_MOVIES.Where(pm => pm.MOVIE_ID == movie.ID && pm.IS_POSTER == true).ToList();

            if (tempPosterId.Count > 0)
            {
                int tempId = tempPosterId[0].PICTURES_ID;
                poster = entities.PICTURES.Where(p => p.ID == tempId).First().PATH;
                alt    = entities.PICTURES.Where(p => p.ID == tempId).First().TITLE;
            }
            else
            {
                poster = entities.PICTURES.Where(p => p.ID == 9).First().PATH;
                alt    = entities.PICTURES.Where(p => p.ID == 9).First().TITLE;
            }

            this.movie = movie;
            genres     = new List <GENRES>();
            foreach (var genre in movie.MOVIES_GENRES)
            {
                genres.Add(entities.GENRES.Where(g => g.ID == genre.GENRE_ID).First());
            }
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Попытка зарегистрировать пользователя
                using (MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6())
                {
                    if (model.Password == model.ConfirmPassword)
                    {
                        USERS tempUser = new USERS();

                        if (entities.USERS.Count() > 0)
                        {
                            int tempId = entities.USERS.OrderByDescending(u => u.ID).FirstOrDefault().ID;
                            tempUser.ID = tempId + 1;
                        }
                        else
                        {
                            tempUser.ID = 0;
                        }

                        tempUser.USERNAME = model.UserName;
                        tempUser.PASSWORD = model.Password;
                        tempUser.ROLES    = "user";
                        tempUser.EMAIL    = model.Email;

                        entities.USERS.AddObject(tempUser);
                        int createStatus;

                        try
                        {
                            createStatus = entities.SaveChanges();
                        }
                        catch
                        {
                            createStatus = -1;
                        }

                        if (createStatus == 1)
                        {
                            FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            ModelState.AddModelError("", createStatus.ToString());
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Введеные пароли не совпадают.");
                    }
                }
            }

            // Появление этого сообщения означает наличие ошибки; повторное отображение формы
            return(View(model));
        }
Example #8
0
        public ActionResult New()
        {
            MOVIEADVISOREntities6 entities   = new MOVIEADVISOREntities6();
            List <MoviesListItem> model      = new List <MoviesListItem>();
            List <MOVIES>         tempHolder = entities.MOVIES.ToList();

            if (tempHolder.Count > 20)
            {
                foreach (var movie in tempHolder.GetRange(tempHolder.Count - 20, 20))
                {
                    model.Add(new MoviesListItem(movie));
                    var    tempRating = movie.MOVIES_COMMENTS.Where(mc => mc.MARK != null);
                    double raiting    = 0;
                    foreach (var rai in tempRating)
                    {
                        raiting += (double)rai.MARK;
                        if (User.Identity.Name != "")
                        {
                            if (rai.USER_ID == entities.USERS.Where(u => u.USERNAME == User.Identity.Name).First().ID)
                            {
                                model.Last().isRaited = true;
                                model.Last().yourMark = (int)rai.MARK;
                            }
                        }
                    }
                    raiting /= tempRating.Count();

                    model.Last().raiting = raiting;
                }
            }
            else
            {
                foreach (var movie in tempHolder)
                {
                    model.Add(new MoviesListItem(movie));
                    var    tempRating = movie.MOVIES_COMMENTS.Where(mc => mc.MARK != null);
                    double raiting    = 0;
                    foreach (var rai in tempRating)
                    {
                        raiting += (double)rai.MARK;
                        if (User.Identity.Name != "")
                        {
                            if (rai.USER_ID == entities.USERS.Where(u => u.USERNAME == User.Identity.Name).First().ID)
                            {
                                model.Last().isRaited = true;
                                model.Last().yourMark = (int)rai.MARK;
                            }
                        }
                    }
                    raiting /= tempRating.Count();

                    model.Last().raiting = raiting;
                }
            }
            model = model.OrderByDescending(m => m.movie.ID).ToList();
            return(View(model));
        }
Example #9
0
        public ActionResult DelMovie(int id = 0)
        {
            MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6();
            MovieCreator          creator  = new MovieCreator();

            creator.RemoveMovie(entities.MOVIES.Where(m => m.ID == id).First());

            return(RedirectToAction("New"));
        }
Example #10
0
        public ActionResult respond(int id, int prewId)
        {
            MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6();

            ViewBag.prewComment = entities.MOVIES_COMMENTS.Where(mc => mc.ID == prewId).First();
            MovieShow model = new MovieShow(entities.MOVIES.Where(m => m.ID == id).FirstOrDefault());

            return(View("Show", model));
        }
Example #11
0
        public ActionResult DelPerson(int id = 0)
        {
            MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6();
            PersonCreator         creator  = new PersonCreator();

            creator.RemovePerson(entities.PERSONS.Where(m => m.ID == id).First());

            return(RedirectToAction("Index"));
        }
Example #12
0
        public ActionResult AddPerson(PersonShow model, string action, string movie = null, string role = null, HttpPostedFileBase foto = null, HttpPostedFileBase poster = null)
        {
            MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6();
            PersonCreator         creator  = new PersonCreator();

            model = creator.update(model, action, foto, poster, Server, movie, role);


            List <SelectListItem> movies           = new List <SelectListItem>();
            List <SelectListItem> roles            = new List <SelectListItem>();
            List <MOVIES>         tempMoviesHolder = entities.MOVIES.ToList();

            foreach (var mov in tempMoviesHolder)
            {
                bool isFree = true;
                foreach (var mov1 in model.moviesList)
                {
                    if (mov.ID == mov1.movie.ID)
                    {
                        isFree = false;
                    }
                }

                if (isFree)
                {
                    movies.Add(new SelectListItem()
                    {
                        Text = mov.TITLE, Value = mov.ID.ToString()
                    });
                }
            }

            ViewBag.movies = movies.AsEnumerable();

            List <ROLES> tempRolesHolder = entities.ROLES.ToList();

            foreach (var rol in tempRolesHolder)
            {
                roles.Add(new SelectListItem()
                {
                    Text = rol.TITLE, Value = rol.ID.ToString()
                });
            }

            ViewBag.roles = roles.AsEnumerable();

            if (action == "Сохранить")
            {
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Example #13
0
        public void SetRole(PERSONS person)
        {
            MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6();

            roles = new List <ROLES>();
            List <MOVIES_PERSONS_ROLES> tempRoles = entities.MOVIES_PERSONS_ROLES.
                                                    Where(mpr => mpr.MOVIE_ID == movie.ID && mpr.PERSON_ID == person.ID).ToList();

            foreach (var role in tempRoles)
            {
                roles.Add(entities.ROLES.Where(r => r.ID == role.ROLE_ID).First());
            }
        }
Example #14
0
        public ActionResult UpdateRatingFind(string value, string keyWord = "", int genre = 0, int year = 0)
        {
            MOVIEADVISOREntities6 entities    = new MOVIEADVISOREntities6();
            MOVIES_COMMENTS       tempComment = new MOVIES_COMMENTS();
            int rating = Int32.Parse(value.Split('/').Last());

            tempComment.ID       = entities.MOVIES_COMMENTS.OrderByDescending(mc => mc.ID).First().ID + 1;
            tempComment.MARK     = rating;
            tempComment.USER_ID  = entities.USERS.Where(u => u.USERNAME == User.Identity.Name).First().ID;
            tempComment.MOVIE_ID = Int32.Parse(value.Split('/').First());
            entities.MOVIES_COMMENTS.AddObject(tempComment);
            entities.SaveChanges();

            return(RedirectToAction("FindPost", new { keyWord = keyWord, genre = genre, year = year }));
        }
Example #15
0
        public ActionResult AddComment(string commentText, int personId)
        {
            MOVIEADVISOREntities6 entities    = new MOVIEADVISOREntities6();
            PERSONS_COMMENTS      tempComment = new PERSONS_COMMENTS();

            tempComment.PERSON_ID = personId;
            tempComment.TEXT      = commentText;
            tempComment.USER_ID   = entities.USERS.Where(u => u.USERNAME == User.Identity.Name).First().ID;
            tempComment.MARK      = 10;
            tempComment.DATE      = DateTime.Now;
            tempComment.ID        = entities.PERSONS_COMMENTS.OrderByDescending(pc => pc.ID).First().ID + 1;
            entities.PERSONS_COMMENTS.AddObject(tempComment);
            entities.SaveChanges();

            return(RedirectToAction("Show", new { id = personId }));
        }
Example #16
0
        public ActionResult Find(string keyWord = "")
        {
            MOVIEADVISOREntities6  entities          = new MOVIEADVISOREntities6();
            List <PERSONS>         tempPersonsHolder = entities.PERSONS.OrderByDescending(p => p.MOVIES_PERSONS_ROLES.Count()).ToList();
            List <PersonsListItem> model             = new List <PersonsListItem>();

            foreach (var person in tempPersonsHolder)
            {
                if ((person.NAME.ToLower().IndexOf(keyWord.ToLower()) > -1) && (model.Count < 20))
                {
                    model.Add(new PersonsListItem(person));
                }
            }

            return(View(model));
        }
Example #17
0
        public PersonsListItem(PERSONS person)
        {
            MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6();
            int tempPosterId = entities.PICTURES_PERSONS.Where(pp => pp.PERSON_ID == person.ID && pp.IS_POSTER == true).FirstOrDefault().PICTURE_ID;

            if (tempPosterId > 0)
            {
                poster = entities.PICTURES.Where(p => p.ID == tempPosterId).First().PATH;
                alt    = entities.PICTURES.Where(p => p.ID == tempPosterId).First().TITLE;
            }
            else
            {
                poster = entities.PICTURES.Where(p => p.ID == 9).First().PATH;
                alt    = entities.PICTURES.Where(p => p.ID == 9).First().TITLE;
            }

            this.person = person;
        }
Example #18
0
        public Person(PERSONS person)
        {
            this.person = person;

            MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6();

            List <PICTURES_PERSONS> tempPicturesHolder = entities.PICTURES_PERSONS.Where(pp => pp.PERSON_ID == person.ID && pp.IS_POSTER == true).ToList();

            if (tempPicturesHolder.Count > 0)
            {
                int tempPicId = tempPicturesHolder.First().PICTURE_ID;
                picture = entities.PICTURES.Where(p => p.ID == tempPicId).First();
            }
            else
            {
                picture = entities.PICTURES.Where(p => p.ID == 9).First();
            }
        }
Example #19
0
        public Movie(MOVIES movie)
        {
            this.movie = movie;

            MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6();

            List <PICTURES_MOVIES> tempPicturesHolder = entities.PICTURES_MOVIES.Where(pm => pm.MOVIE_ID == movie.ID && pm.IS_POSTER == true).ToList();

            if (tempPicturesHolder.Count > 0)
            {
                int tempPicId = tempPicturesHolder.First().PICTURES_ID;
                picture = entities.PICTURES.Where(p => p.ID == tempPicId).First();
            }
            else
            {
                picture = entities.PICTURES.Where(p => p.ID == 9).First();
            }
        }
Example #20
0
        public MovieShow(MOVIES movie)
        {
            this.movie = movie;

            MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6();

            List <PICTURES_MOVIES> tempPicId = entities.PICTURES_MOVIES.Where(pm => pm.MOVIE_ID == movie.ID).ToList();

            picturesList = new List <PICTURES>();

            foreach (var pic in tempPicId)
            {
                if (!pic.IS_POSTER)
                {
                    picturesList.Add(entities.PICTURES.Where(p => p.ID == pic.PICTURES_ID).First());
                }
                else
                {
                    poster    = entities.PICTURES.Where(p => p.ID == pic.PICTURES_ID).First().PATH;
                    posterId  = entities.PICTURES.Where(p => p.ID == pic.PICTURES_ID).First().ID;
                    altPoster = entities.PICTURES.Where(p => p.ID == pic.PICTURES_ID).First().TITLE;
                }
            }

            List <MOVIES_PERSONS_ROLES> tempPerId = entities.MOVIES_PERSONS_ROLES.Where(pmr => pmr.MOVIE_ID == movie.ID).ToList();

            personsList = new List <Person>();

            foreach (var per in tempPerId)
            {
                personsList.Add(new Person(entities.PERSONS.Where(p => p.ID == per.PERSON_ID).First()));
                personsList.Last().SetRole(movie);
            }

            comments = entities.MOVIES_COMMENTS.Where(mc => mc.MOVIE_ID == movie.ID && mc.TEXT != null).ToList();
            genres   = new List <GENRES>();
            foreach (var gen in this.movie.MOVIES_GENRES)
            {
                genres.Add(entities.GENRES.Where(g => g.ID == gen.GENRE_ID).First());
            }
        }
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {
                // При некоторых сценариях сбоя операция смены пароля ChangePassword вызывает исключение,
                // а не возвращает значение false (ложь).
                int changePasswordSucceeded;
                try
                {
                    using (MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6())
                    {
                        if (entities.USERS.Where(u => u.USERNAME == User.Identity.Name).Where(u => u.PASSWORD == model.OldPassword).ToList().Count > 0)
                        {
                            entities.USERS.Where(u => u.USERNAME == User.Identity.Name).First().PASSWORD = model.NewPassword;
                            changePasswordSucceeded = entities.SaveChanges();
                        }
                        else
                        {
                            changePasswordSucceeded = -1;
                        }
                    }
                }
                catch (Exception)
                {
                    changePasswordSucceeded = -1;
                }

                if (changePasswordSucceeded == 1)
                {
                    return(RedirectToAction("ChangePasswordSuccess"));
                }
                else
                {
                    ModelState.AddModelError("", "Неправильный текущий пароль или недопустимый новый пароль.");
                }
            }

            // Появление этого сообщения означает наличие ошибки; повторное отображение формы
            return(View(model));
        }
Example #22
0
        public ActionResult AddComment(string commentText, int movieId, int prevComment = 0)
        {
            MOVIEADVISOREntities6 entities    = new MOVIEADVISOREntities6();
            MOVIES_COMMENTS       tempComment = new MOVIES_COMMENTS();

            tempComment.MOVIE_ID = movieId;
            tempComment.TEXT     = commentText;
            tempComment.USER_ID  = entities.USERS.Where(u => u.USERNAME == User.Identity.Name).First().ID;
            tempComment.MARK     = 10;
            tempComment.DATE     = DateTime.Now;

            if (prevComment > 0)
            {
                tempComment.PREV_COMMENT_ID = prevComment;
            }

            tempComment.ID = entities.MOVIES_COMMENTS.OrderByDescending(mc => mc.ID).First().ID + 1;
            entities.MOVIES_COMMENTS.AddObject(tempComment);
            entities.SaveChanges();

            return(RedirectToAction("Show", new { id = movieId }));
        }
Example #23
0
        public ActionResult AddPerson(int id = 0)
        {
            PersonShow            model            = new PersonShow();
            List <SelectListItem> movies           = new List <SelectListItem>();
            List <SelectListItem> roles            = new List <SelectListItem>();
            MOVIEADVISOREntities6 entities         = new MOVIEADVISOREntities6();
            List <MOVIES>         tempMoviesHolder = entities.MOVIES.ToList();

            model.person.NAME        = "Имя";
            model.person.DESCRIPTION = "Описание";

            if (id != 0)
            {
                model = new PersonShow(entities.PERSONS.Where(m => m.ID == id).First());
            }

            foreach (var mov in tempMoviesHolder)
            {
                movies.Add(new SelectListItem()
                {
                    Text = mov.TITLE, Value = mov.ID.ToString()
                });
            }

            ViewBag.movies = movies.AsEnumerable();
            List <ROLES> tempRolesHolder = entities.ROLES.ToList();

            foreach (var role in tempRolesHolder)
            {
                roles.Add(new SelectListItem()
                {
                    Text = role.TITLE, Value = role.ID.ToString()
                });
            }
            ViewBag.roles = roles.AsEnumerable();

            return(View(model));
        }
Example #24
0
        public void RemovePerson(PERSONS person)
        {
            MOVIEADVISOREntities6 entities1 = new MOVIEADVISOREntities6();
            int tempId = person.ID;

            foreach (var pm in entities1.PICTURES_PERSONS.Where(p => p.PERSON_ID == person.ID))
            {
                entities1.PICTURES_PERSONS.DeleteObject(pm);
            }

            foreach (var mpr in entities1.MOVIES_PERSONS_ROLES.Where(p => p.PERSON_ID == person.ID))
            {
                entities1.MOVIES_PERSONS_ROLES.DeleteObject(mpr);
            }

            foreach (var mpr in entities1.PERSONS_COMMENTS.Where(p => p.PERSON_ID == person.ID))
            {
                entities1.PERSONS_COMMENTS.DeleteObject(mpr);
            }

            entities1.PERSONS.DeleteObject(entities1.PERSONS.Where(m => m.ID == tempId).First());
            entities1.SaveChanges();
        }
        public ActionResult LogOn(USERS model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                using (MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6())
                {
                    bool userValid = entities.USERS.Any(user => user.USERNAME == model.USERNAME && user.PASSWORD == model.PASSWORD);

                    if (userValid)
                    {
                        FormsAuthentication.SetAuthCookie(model.USERNAME, false);
                        if (!Roles.IsUserInRole(model.USERNAME, entities.USERS.Where(user => user.USERNAME == model.USERNAME && user.PASSWORD == model.PASSWORD).FirstOrDefault().ROLES))
                        {
                            Roles.AddUserToRole(model.USERNAME, entities.USERS.Where(user => user.USERNAME == model.USERNAME && user.PASSWORD == model.PASSWORD).FirstOrDefault().ROLES);
                        }

                        if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                            !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                        {
                            return(Redirect(returnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Имя пользователя или пароль указаны неверно.");
                    }
                }
            }

            // Появление этого сообщения означает наличие ошибки; повторное отображение формы
            return(View(model));
        }
Example #26
0
        public ActionResult AddMovie(int id = 0)
        {
            MovieShow             model             = new MovieShow();
            List <SelectListItem> persons           = new List <SelectListItem>();
            List <SelectListItem> roles             = new List <SelectListItem>();
            List <SelectListItem> genres            = new List <SelectListItem>();
            MOVIEADVISOREntities6 entities          = new MOVIEADVISOREntities6();
            List <PERSONS>        tempPersonsHolder = entities.PERSONS.ToList();

            model.movie.TITLE       = "Название";
            model.movie.DESCRIPTION = "Описание";

            if (id != 0)
            {
                model = new MovieShow(entities.MOVIES.Where(m => m.ID == id).First());
            }

            foreach (var per in tempPersonsHolder)
            {
                persons.Add(new SelectListItem()
                {
                    Text = per.NAME, Value = per.ID.ToString()
                });
            }
            ViewBag.persons = persons.AsEnumerable();

            List <GENRES> tempGenresHolder = entities.GENRES.ToList();

            foreach (var gen in tempGenresHolder)
            {
                bool isFree = true;
                foreach (var gen1 in model.movie.MOVIES_GENRES)
                {
                    if (gen.ID == gen1.GENRE_ID)
                    {
                        isFree = false;
                    }
                }

                if (isFree)
                {
                    genres.Add(new SelectListItem()
                    {
                        Text = gen.TITLE, Value = gen.ID.ToString()
                    });
                }
            }
            ViewBag.genres = genres.AsEnumerable();


            List <ROLES> tempRolesHolder = entities.ROLES.ToList();

            foreach (var role in tempRolesHolder)
            {
                roles.Add(new SelectListItem()
                {
                    Text = role.TITLE, Value = role.ID.ToString()
                });
            }
            ViewBag.roles = roles.AsEnumerable();

            return(View(model));
        }
Example #27
0
        public PersonShow update(PersonShow model, string action, HttpPostedFileBase foto, HttpPostedFileBase poster, HttpServerUtilityBase Server, string movie, string role)
        {
            MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6();
            PersonShow            result   = new PersonShow();

            result.person.ID    = model.person.ID;
            result.person       = model.person;
            result.picturesList = new List <PICTURES>();
            foreach (var pic in model.picturesList)
            {
                result.picturesList.Add(entities.PICTURES.Where(p => p.ID == pic.ID).First());
            }
            result.moviesList = new List <Movie>();
            foreach (var per in model.moviesList)
            {
                result.moviesList.Add(new Movie(entities.MOVIES.Where(p => p.ID == per.movie.ID).First()));
                result.moviesList.Last().roles = new List <ROLES>();
                result.moviesList.Last().roles.Add(per.roles[0]);
            }

            result.poster    = model.poster;
            result.posterId  = model.posterId;
            result.altPoster = model.altPoster;

            result.comments = new List <PERSONS_COMMENTS>();

            if (action == "Добавить фильм")
            {
                int idHolder   = Int32.Parse(movie);
                int roleHolder = Int32.Parse(role);
                result.moviesList.Add(new Movie(entities.MOVIES.Where(p => p.ID == idHolder).First()));
                result.moviesList.Last().roles = new List <ROLES>();
                result.moviesList.Last().roles.Add(entities.ROLES.Where(r => r.ID == roleHolder).First());
            }
            else
            if (action == "Загрузить фото")
            {
                int id = this.uploadPic(foto, Server);
                if (id > -1)
                {
                    result.picturesList.Add(entities.PICTURES.OrderByDescending(p => p.ID).First());
                }
            }
            else
            if (action == "Загрузить постер")
            {
                int id = uploadPic(poster, Server);
                if (id > -1)
                {
                    result.poster   = entities.PICTURES.OrderByDescending(p => p.ID).First().PATH;
                    result.posterId = entities.PICTURES.OrderByDescending(p => p.ID).First().ID;
                }
            }
            else
            if (action == "Сохранить")
            {
                PERSONS tempPersons = new PERSONS();
                tempPersons.DESCRIPTION = result.person.DESCRIPTION;
                tempPersons.NAME        = result.person.NAME;

                if (result.person.ID > 0)
                {
                    tempPersons.ID = result.person.ID;
                    RemovePerson(tempPersons);
                }
                else
                {
                    tempPersons.ID = entities.PERSONS.OrderByDescending(m => m.ID).First().ID + 1;
                }

                foreach (var per in result.moviesList)
                {
                    MOVIES_PERSONS_ROLES tempMPR = new MOVIES_PERSONS_ROLES();
                    tempMPR.MOVIE_ID  = per.movie.ID;
                    tempMPR.PERSON_ID = result.person.ID;
                    tempMPR.ROLE_ID   = per.roles.First().ID;
                    tempPersons.MOVIES_PERSONS_ROLES.Add(tempMPR);
                }

                foreach (var photo in result.picturesList)
                {
                    PICTURES_PERSONS tempPM = new PICTURES_PERSONS();
                    tempPM.PERSON_ID  = result.person.ID;
                    tempPM.PICTURE_ID = photo.ID;
                    tempPM.IS_POSTER  = false;
                    tempPersons.PICTURES_PERSONS.Add(tempPM);
                }

                if (model.posterId > 0)
                {
                    PICTURES_PERSONS tempPoster = new PICTURES_PERSONS();
                    tempPoster.PERSON_ID  = model.person.ID;
                    tempPoster.PICTURE_ID = model.posterId;
                    tempPoster.IS_POSTER  = true;
                    tempPersons.PICTURES_PERSONS.Add(tempPoster);
                }

                entities.PERSONS.AddObject(tempPersons);
                try
                {
                    entities.SaveChanges();
                }
                catch
                {
                }
            }
            else
            if (action.IndexOf("УдалитьФото") > -1)
            {
                int tempId = Int32.Parse(action.Substring(11, action.Length - 11));
                result.picturesList.Remove(result.picturesList.Where(p => p.ID == tempId).First());
            }
            else
            if (action.IndexOf("Удалить") > -1)
            {
                int tempId = Int32.Parse(action.Substring(7, action.Length - 7));
                result.moviesList.Remove(result.moviesList.Where(p => p.movie.ID == tempId).First());
            }

            return(result);
        }
Example #28
0
        public ActionResult FindPost(string keyWord = "", int genre = 0, int year = 0)
        {
            MOVIEADVISOREntities6 entities         = new MOVIEADVISOREntities6();
            List <MOVIES>         tempMoviesHolder = entities.MOVIES.OrderByDescending(m => m.YEAR).ToList();
            List <MoviesListItem> model            = new List <MoviesListItem>();
            List <SelectListItem> genres           = new List <SelectListItem>();
            var tempGenresHolder = entities.GENRES;

            genres.Add(new SelectListItem()
            {
                Text = "Любой", Value = "0"
            });

            foreach (var gen in tempGenresHolder)
            {
                genres.Add(new SelectListItem()
                {
                    Text = gen.TITLE, Value = gen.ID.ToString()
                });
            }
            ViewBag.genres = genres;
            foreach (var movie in tempMoviesHolder)
            {
                bool match = true;
                if (keyWord != "")
                {
                    if (movie.TITLE.ToLower().IndexOf(keyWord.ToLower()) > -1)
                    {
                        match = true;
                    }
                    else
                    {
                        match = false;
                    }
                }
                if (year != 0)
                {
                    if ((movie.YEAR == year) && (match))
                    {
                        match = true;
                    }
                    else
                    {
                        match = false;
                    }
                }
                if (genre != 0)
                {
                    bool mathc1 = false;
                    foreach (var gen in movie.MOVIES_GENRES)
                    {
                        if (gen.GENRE_ID == genre)
                        {
                            mathc1 = true;
                        }
                    }

                    if ((mathc1) && (match))
                    {
                        match = true;
                    }
                    else
                    {
                        match = false;
                    }
                }
                if ((match) && (model.Count < 20))
                {
                    model.Add(new MoviesListItem(movie));
                    var    tempRating = movie.MOVIES_COMMENTS.Where(mc => mc.MARK != null);
                    double raiting    = 0;
                    foreach (var rai in tempRating)
                    {
                        raiting += (double)rai.MARK;
                        if (User.Identity.Name != "")
                        {
                            if (rai.USER_ID == entities.USERS.Where(u => u.USERNAME == User.Identity.Name).First().ID)
                            {
                                model.Last().isRaited = true;
                                model.Last().yourMark = (int)rai.MARK;
                            }
                        }
                    }
                    raiting /= tempRating.Count();

                    model.Last().raiting = raiting;
                }
            }

            return(View("Find", model));
        }
Example #29
0
        public MovieShow update(MovieShow model, string action, HttpPostedFileBase foto, HttpPostedFileBase poster, HttpServerUtilityBase Server, string person, string role, string genre)
        {
            MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6();
            MovieShow             result   = new MovieShow();

            result.movie.ID     = model.movie.ID;
            result.movie        = model.movie;
            result.picturesList = new List <PICTURES>();
            foreach (var pic in model.picturesList)
            {
                result.picturesList.Add(entities.PICTURES.Where(p => p.ID == pic.ID).First());
            }
            result.personsList = new List <Person>();
            foreach (var per in model.personsList)
            {
                result.personsList.Add(new Person(entities.PERSONS.Where(p => p.ID == per.person.ID).First()));
                result.personsList.Last().roles = new List <ROLES>();
                result.personsList.Last().roles.Add(per.roles[0]);
            }

            foreach (var gen in model.genres)
            {
                result.genres.Add(new GENRES());
                result.genres.Last().ID    = entities.GENRES.Where(g => g.ID == gen.ID).First().ID;
                result.genres.Last().TITLE = entities.GENRES.Where(g => g.ID == gen.ID).First().TITLE;
            }

            result.poster    = model.poster;
            result.posterId  = model.posterId;
            result.altPoster = model.altPoster;

            result.comments = new List <MOVIES_COMMENTS>();

            if (action == "Добавить жанр")
            {
                int idHolder = Int32.Parse(genre);
                result.genres.Add(new GENRES());
                result.genres.Last().ID    = idHolder;
                result.genres.Last().TITLE = entities.GENRES.Where(g => g.ID == idHolder).First().TITLE;
            }
            else
            if (action == "Добавить личность")
            {
                int idHolder   = Int32.Parse(person);
                int roleHolder = Int32.Parse(role);
                result.personsList.Add(new Person(entities.PERSONS.Where(p => p.ID == idHolder).First()));
                result.personsList.Last().roles = new List <ROLES>();
                result.personsList.Last().roles.Add(entities.ROLES.Where(r => r.ID == roleHolder).First());
            }
            else
            if (action == "Загрузить фото")
            {
                int id = uploadPic(foto, Server);
                if (id > -1)
                {
                    result.picturesList.Add(entities.PICTURES.OrderByDescending(p => p.ID).First());
                }
            }
            else
            if (action == "Загрузить постер")
            {
                int id = uploadPic(poster, Server);
                if (id > -1)
                {
                    result.poster   = entities.PICTURES.OrderByDescending(p => p.ID).First().PATH;
                    result.posterId = entities.PICTURES.OrderByDescending(p => p.ID).First().ID;
                }
            }
            else
            if (action == "Сохранить")
            {
                MOVIES tempMovie = new MOVIES();
                tempMovie.DESCRIPTION = result.movie.DESCRIPTION;
                tempMovie.TITLE       = result.movie.TITLE;
                tempMovie.YEAR        = result.movie.YEAR;
                if (result.movie.ID > 0)
                {
                    tempMovie.ID = result.movie.ID;
                    //tempMovie.ID = entities.MOVIES.OrderByDescending(m => m.ID).First().ID + 1;
                    RemoveMovie(tempMovie);
                }
                else
                {
                    tempMovie.ID = entities.MOVIES.OrderByDescending(m => m.ID).First().ID + 1;
                }

                foreach (var per in result.personsList)
                {
                    MOVIES_PERSONS_ROLES tempMPR = new MOVIES_PERSONS_ROLES();
                    tempMPR.MOVIE_ID  = result.movie.ID;
                    tempMPR.PERSON_ID = per.person.ID;
                    tempMPR.ROLE_ID   = per.roles.First().ID;
                    tempMovie.MOVIES_PERSONS_ROLES.Add(tempMPR);
                }

                foreach (var photo in result.picturesList)
                {
                    PICTURES_MOVIES tempPM = new PICTURES_MOVIES();
                    tempPM.MOVIE_ID    = result.movie.ID;
                    tempPM.PICTURES_ID = photo.ID;
                    tempPM.IS_POSTER   = false;
                    tempMovie.PICTURES_MOVIES.Add(tempPM);
                }

                foreach (var gen in result.genres)
                {
                    MOVIES_GENRES tempGen = new MOVIES_GENRES();
                    tempGen.MOVIE_ID = result.movie.ID;
                    tempGen.GENRE_ID = gen.ID;
                    tempMovie.MOVIES_GENRES.Add(tempGen);
                }

                if (model.posterId > 0)
                {
                    PICTURES_MOVIES tempPoster = new PICTURES_MOVIES();
                    tempPoster.MOVIE_ID    = model.movie.ID;
                    tempPoster.PICTURES_ID = model.posterId;
                    tempPoster.IS_POSTER   = true;
                    tempMovie.PICTURES_MOVIES.Add(tempPoster);
                }

                entities.MOVIES.AddObject(tempMovie);
                try
                {
                    entities.SaveChanges();
                }
                catch
                {
                }
            }
            else
            if (action.IndexOf("УдалитьФото") > -1)
            {
                int tempId = Int32.Parse(action.Substring(11, action.Length - 11));
                result.picturesList.Remove(result.picturesList.Where(p => p.ID == tempId).First());
            }
            else
            if (action.IndexOf("УдалитьЖанр") > -1)
            {
                int tempId = Int32.Parse(action.Substring(11, action.Length - 11));
                result.genres.Remove(result.genres.Where(p => p.ID == tempId).First());
            }
            else
            if (action.IndexOf("Удалить") > -1)
            {
                int tempId = Int32.Parse(action.Substring(7, action.Length - 7));
                result.personsList.Remove(result.personsList.Where(p => p.person.ID == tempId).First());
            }


            return(result);
        }
Example #30
0
        public ActionResult AddMovie(MovieShow model, string action, string person = null, string role = null, string genre = null, HttpPostedFileBase foto = null, HttpPostedFileBase poster = null)
        {
            MOVIEADVISOREntities6 entities = new MOVIEADVISOREntities6();
            MovieCreator          creator  = new MovieCreator();

            model = creator.update(model, action, foto, poster, Server, person, role, genre);


            List <SelectListItem> persons           = new List <SelectListItem>();
            List <SelectListItem> genres            = new List <SelectListItem>();
            List <SelectListItem> roles             = new List <SelectListItem>();
            List <PERSONS>        tempPersonsHolder = entities.PERSONS.ToList();

            foreach (var per in tempPersonsHolder)
            {
                bool isFree = true;
                foreach (var per1 in model.personsList)
                {
                    if (per.ID == per1.person.ID)
                    {
                        isFree = false;
                    }
                }

                if (isFree)
                {
                    persons.Add(new SelectListItem()
                    {
                        Text = per.NAME, Value = per.ID.ToString()
                    });
                }
            }
            ViewBag.persons = persons.AsEnumerable();

            List <GENRES> tempGenresHolder = entities.GENRES.ToList();

            foreach (var gen in tempGenresHolder)
            {
                bool isFree = true;
                foreach (var gen1 in model.genres)
                {
                    if (gen.ID == gen1.ID)
                    {
                        isFree = false;
                    }
                }

                if (isFree)
                {
                    genres.Add(new SelectListItem()
                    {
                        Text = gen.TITLE, Value = gen.ID.ToString()
                    });
                }
            }
            ViewBag.genres = genres.AsEnumerable();


            List <ROLES> tempRolesHolder = entities.ROLES.ToList();

            foreach (var rol in tempRolesHolder)
            {
                roles.Add(new SelectListItem()
                {
                    Text = rol.TITLE, Value = rol.ID.ToString()
                });
            }

            ViewBag.roles = roles.AsEnumerable();

            if (action == "Сохранить")
            {
                return(RedirectToAction("New"));
            }

            return(View(model));
        }