public ActionResult Edit([Bind(Include = "ID,ID_Czytelnika,ID_Filmu,Data_Wypozyczenia,Data_Zwrotu,Stan")] Wypozyczenia_Filmu wypozyczenia_Filmu, int bstan)
        {
            FilmValidator    validator = new FilmValidator();
            ValidationResult result    = validator.Validate(wypozyczenia_Filmu);

            if (!result.IsValid)
            {
                ViewBag.Stan  = new SelectList(db.Stan, "ID", "Opis", wypozyczenia_Filmu.Stan);
                ViewBag.Error = result.Errors[0].ErrorMessage;
                return(View(wypozyczenia_Filmu));
            }


            if (ModelState.IsValid)
            {
                db.Entry(wypozyczenia_Filmu).State = EntityState.Modified;
                if (bstan != wypozyczenia_Filmu.Stan && wypozyczenia_Filmu.Stan == 3)
                {
                    db.Film.Find(wypozyczenia_Filmu.ID_Filmu).Stan_Magazynowy++;
                }
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.Stan = new SelectList(db.Stan, "ID", "Opis", wypozyczenia_Filmu.Stan);
            return(View(wypozyczenia_Filmu));
        }
        public ResultModel <Film> FilmUpdate(Film model)
        {
            FilmValidator    validator = new FilmValidator();
            ValidationResult result    = validator.Validate(model);

            if (result.IsValid)
            {
                _filmRepository.Update(model, model.FilmID);
                return(new ResultModel <Film>
                {
                    Errors = null,
                    IsValid = true,
                    Message = "Update Başarılı"
                });
            }
            return(new ResultModel <Film>
            {
                Errors = result.Errors.Select(x => x.ErrorMessage).ToList(),
                IsValid = false,
                Message = "Update Başarısız"
            });
        }
        public ResultModel <Film> SaveFilm(Film f)
        {
            FilmValidator validator = new FilmValidator();
            var           result    = validator.Validate(f);

            if (result.IsValid)
            {
                _filmRepo.Add(f);
                _filmRepo.Save();

                return(new ResultModel <Film>
                {
                    Errors = null,
                    IsValid = true,
                    Message = "Başarıyla kayıt edildi!"
                });
            }
            return(new ResultModel <Film>
            {
                Errors = result.Errors.Select(x => x.ErrorMessage).ToList(),
                IsValid = false,
                Message = "Kayıt işlemi başarısız!"
            });
        }
Exemple #4
0
        public bool Execute()
        {
            var mayCommit = true;

            var nhSession = NhContext.GetSession();
            using (var tx = nhSession.BeginTransaction())
            {
                var newFilms = new List<Film>();

                foreach (var film in Films)
                {
                    var realNewFilm = new Film();
                    if(GetFilmFromCache(film.IMDBId) != null || nhSession.Query<Film>().Where(x => x.IMDBId == film.IMDBId).Any())
                        continue;
                    AddFilmToCache(film);
                    realNewFilm.FilmPath = film.FilmPath;
                    realNewFilm.IMDBId = film.IMDBId;
                    realNewFilm.ReleaseYear = film.ReleaseYear;
                    realNewFilm.RunTime = film.RunTime;
                    realNewFilm.Synopsis = film.Synopsis;
                    realNewFilm.Title = film.Title;
                    realNewFilm.Keywords = film.Keywords;
                    realNewFilm.DirectorIndexing = film.DirectorIndexing;
                    realNewFilm.GenreIndexing = film.GenreIndexing;
                    realNewFilm.CharIndexing = film.CharIndexing;
                    realNewFilm.PersonIndexing = film.PersonIndexing;
                    realNewFilm.PicURL = film.PicURL;
                    realNewFilm.IMDBRating = film.IMDBRating;

                    foreach (var person in film.Director)
                    {
                        var director = GetPersonFromCache(person.IMDBID) ??
                                       nhSession.Query<Person>().Where(x => x.IMDBID == person.IMDBID).
                                           SingleOrDefault() ?? person;
                        AddPersonToCache(director);
                        realNewFilm.Director.Add(director);
                    }

                    foreach (var person in film.Writers)
                    {
                        var writer = GetPersonFromCache(person.IMDBID) ??
                                     nhSession.Query<Person>().Where(x => x.IMDBID == person.IMDBID).
                                         SingleOrDefault() ?? person;
                        AddPersonToCache(writer);
                        realNewFilm.Writers.Add(writer);
                    }

                    foreach (var genre in film.Genre)
                    {
                        var type = GetTypeFromCache(genre.Type) ??
                                   nhSession.Query<FilmType>().Where(x => x.Type == genre.Type).
                                       SingleOrDefault() ?? genre;
                        AddTypeToCache(type);
                        realNewFilm.Genre.Add(type);
                    }

                    foreach (var role in film.Cast)
                    {
                        var actor = GetPersonFromCache(role.Person.IMDBID)
                                    ??
                                    nhSession.Query<Person>().Where(x => x.IMDBID == role.Person.IMDBID).
                                        SingleOrDefault()
                                    ?? role.Person;
                        AddPersonToCache(actor);
                        var role2 = new Role
                                        {
                                            Character = role.Character,
                                            Person = actor
                                        };
                        realNewFilm.Cast.Add(role2);
                    }
                    newFilms.Add(realNewFilm);
                }

                var validator = new FilmValidator();
                foreach (var newFilm in newFilms)
                {
                    var results = validator.Validate(newFilm);
                    if (results.IsValid)
                    {
                        nhSession.Save(newFilm);
                    }
                    else
                    {
                        ValidationErrors.Add(newFilm.IMDBId, results.Errors);
                        mayCommit = false;
                    }
                }

                if (mayCommit)
                    tx.Commit();
            }
            return mayCommit;
        }
Exemple #5
0
        public bool AddFilm(Film film)
        {
            if (film == null)
                throw new ArgumentNullException("film");

            var mayCommit = true;
            Film filmToAdd;
            using(var tx = _session.BeginTransaction())
            {
                if (_session.Query<Film>().Where(x => x.Title == film.Title).SingleOrDefault() != null)
                    return false;
                filmToAdd = new Film
                                    {
                                        Title = film.Title,
                                        Synopsis = film.Synopsis,
                                        ReleaseDate = film.ReleaseDate,
                                        Url = film.Url,
                                        Files = film.Files
                                    };

                FilterPersonCollection(film.Directors,filmToAdd);
                FilterPersonCollection(film.Writers, filmToAdd);

                foreach (var genre in film.Genres)
                {
                    var genre1 = genre;
                    var gen = GetFromGenreCache(genre1.GenreName) ??
                              _session.Query<Genre>().Where(x => x.GenreName == genre1.GenreName).SingleOrDefault() ??
                              genre;
                    AddToGenreCache(gen);
                    filmToAdd.Genres.Add(gen);
                }

                foreach (var keyWord in film.KeyWords)
                {
                    var keyWord1 = keyWord;
                    var key = GetFromKeyWordCache(keyWord1.Word) ??
                              _session.Query<KeyWord>().Where(x => x.Word == keyWord1.Word).SingleOrDefault() ??
                              keyWord;
                    AddToKeyWordCache(key);
                    filmToAdd.KeyWords.Add(key);
                }

                foreach (var role in film.Cast)
                {
                    var role1 = role;
                    var act = GetFromPersonCache(role1.Actor.Name) ??
                             _session.Query<Person>().Where(x => x.Name == role1.Actor.Name).SingleOrDefault() ??
                             role.Actor;
                    AddToPersonCache(act);
                    filmToAdd.Cast.Add(new Role{Actor = act,CharacterName = role1.CharacterName,Id = role1.Id});
                }

                var validator = new FilmValidator();
                var results = validator.Validate(filmToAdd);
                if (results.IsValid)
                {
                    _session.Save(filmToAdd);
                }
                else
                    mayCommit = false;
                if(mayCommit)
                    tx.Commit();
            }
            Index.Indexer.Index(filmToAdd);
            return mayCommit;
        }
Exemple #6
0
        public bool Execute()
        {
            var mayCommit = true;

            var nhSession = NhContext.GetSession();

            using (var tx = nhSession.BeginTransaction())
            {
                var newFilms = new List <Film>();

                foreach (var film in Films)
                {
                    var realNewFilm = new Film();
                    if (GetFilmFromCache(film.IMDBId) != null || nhSession.Query <Film>().Where(x => x.IMDBId == film.IMDBId).Any())
                    {
                        continue;
                    }
                    AddFilmToCache(film);
                    realNewFilm.FilmPath         = film.FilmPath;
                    realNewFilm.IMDBId           = film.IMDBId;
                    realNewFilm.ReleaseYear      = film.ReleaseYear;
                    realNewFilm.RunTime          = film.RunTime;
                    realNewFilm.Synopsis         = film.Synopsis;
                    realNewFilm.Title            = film.Title;
                    realNewFilm.Keywords         = film.Keywords;
                    realNewFilm.DirectorIndexing = film.DirectorIndexing;
                    realNewFilm.GenreIndexing    = film.GenreIndexing;
                    realNewFilm.CharIndexing     = film.CharIndexing;
                    realNewFilm.PersonIndexing   = film.PersonIndexing;
                    realNewFilm.PicURL           = film.PicURL;
                    realNewFilm.IMDBRating       = film.IMDBRating;

                    foreach (var person in film.Director)
                    {
                        var director = GetPersonFromCache(person.IMDBID) ??
                                       nhSession.Query <Person>().Where(x => x.IMDBID == person.IMDBID).
                                       SingleOrDefault() ?? person;
                        AddPersonToCache(director);
                        realNewFilm.Director.Add(director);
                    }

                    foreach (var person in film.Writers)
                    {
                        var writer = GetPersonFromCache(person.IMDBID) ??
                                     nhSession.Query <Person>().Where(x => x.IMDBID == person.IMDBID).
                                     SingleOrDefault() ?? person;
                        AddPersonToCache(writer);
                        realNewFilm.Writers.Add(writer);
                    }

                    foreach (var genre in film.Genre)
                    {
                        var type = GetTypeFromCache(genre.Type) ??
                                   nhSession.Query <FilmType>().Where(x => x.Type == genre.Type).
                                   SingleOrDefault() ?? genre;
                        AddTypeToCache(type);
                        realNewFilm.Genre.Add(type);
                    }

                    foreach (var role in film.Cast)
                    {
                        var actor = GetPersonFromCache(role.Person.IMDBID)
                                    ??
                                    nhSession.Query <Person>().Where(x => x.IMDBID == role.Person.IMDBID).
                                    SingleOrDefault()
                                    ?? role.Person;
                        AddPersonToCache(actor);
                        var role2 = new Role
                        {
                            Character = role.Character,
                            Person    = actor
                        };
                        realNewFilm.Cast.Add(role2);
                    }
                    newFilms.Add(realNewFilm);
                }

                var validator = new FilmValidator();
                foreach (var newFilm in newFilms)
                {
                    var results = validator.Validate(newFilm);
                    if (results.IsValid)
                    {
                        nhSession.Save(newFilm);
                    }
                    else
                    {
                        ValidationErrors.Add(newFilm.IMDBId, results.Errors);
                        mayCommit = false;
                    }
                }

                if (mayCommit)
                {
                    tx.Commit();
                }
            }
            return(mayCommit);
        }