示例#1
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);
        }
示例#2
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);
        }