コード例 #1
0
ファイル: MovieCreator.cs プロジェクト: terdened/movieadvisor
        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();
        }
コード例 #2
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);
        }
コード例 #3
0
        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));
        }
コード例 #4
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 }));
        }
コード例 #5
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 }));
        }
コード例 #6
0
        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));
        }
コード例 #7
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 }));
        }
コード例 #8
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();
        }
コード例 #9
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);
        }
コード例 #10
0
ファイル: MovieCreator.cs プロジェクト: terdened/movieadvisor
        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);
        }