public static Director CreateDirector(this DirectorInput input, HttpPostedFileBase photo, IDaoCountry daoCountry, IDaoFilm daoFilm) { var director = new Director { Name = input.Name, Surname = input.Surname, Birth = input.Birth, Death = input.Death, Country = daoCountry.GetCountryByEnglishName(input.CountryName), Gender = (Data.Models.Gender)input.Gender }; if (photo != null && photo.ContentLength > 0) { try { if (photo.ContentType.Contains("image")) { var filename = Guid.NewGuid().ToString() + Path.GetExtension(photo.FileName); var path = Path.Combine(PathUtils.GetProjectDirectory(), "Cinematheque.WebSite\\images\\directors\\", filename); photo.SaveAs(path); director.PhotoFileName = filename; } else { throw new Exception("ERROR: Uploaded file is not image"); } } catch (Exception ex) { throw new Exception("ERROR:" + ex.Message.ToString()); } } else { director.PhotoFileName = "default.jpg"; } if (input.FilmsDirected != null) { foreach (var id in input.FilmsDirected) { var film = daoFilm.Find(id); director.AddFilm(film); } } return(director); }
public static void CopyToData(this FilmInput input, Film data, HttpPostedFileBase poster, IDaoCountry daoCountry, IDaoGenre daoGenre, IDaoDirector daoDirector, IDaoActor daoActor) { if (data.ID != input.ID) { throw new Exception("Cannot copy from foreign view to data"); } data.Title = input.Title; data.ReleaseDate = input.ReleaseDate; data.IMDbRating = input.IMDbRating; data.Duration = input.Duration; data.Description = input.Description; data.Countries = new List <Country>(); foreach (var name in input.Countries) { data.Countries.Add(daoCountry.GetCountryByEnglishName(name)); } data.RemoveAllGenres(); if (input.Genres != null) { foreach (var id in input.Genres) { var genre = daoGenre.Find(id); data.AddGenre(genre); } } if (input.DirectorID != Guid.Empty) { data.Director = daoDirector.Find(input.DirectorID); } data.RemoveAllActors(); if (input.Actors != null) { foreach (var id in input.Actors) { var actor = daoActor.Find(id); data.AddActor(actor); } } if (poster != null && poster.ContentLength > 0) { try { if (poster.ContentType.Contains("image")) { var filename = Guid.NewGuid().ToString() + Path.GetExtension(poster.FileName); var path = Path.Combine(PathUtils.GetProjectDirectory(), "Cinematheque.WebSite\\images\\films\\", filename); poster.SaveAs(path); /*File.Delete(Path.Combine(PathUtils.GetProjectDirectory(), * "Cinematheque.WebSite\\images\\films\\", * filename);*/ data.PosterFileName = filename; } else { throw new Exception("ERROR: Uploaded file is not image"); } } catch (Exception ex) { throw new Exception("ERROR:" + ex.Message.ToString()); } } }
public static Film CreateFilm(this FilmInput input, HttpPostedFileBase poster, IDaoCountry daoCountry, IDaoActor daoActor, IDaoDirector daoDirector, IDaoGenre daoGenre) { var film = new Film { Title = input.Title, ReleaseDate = input.ReleaseDate, IMDbRating = input.IMDbRating, Duration = input.Duration, Description = input.Description, Countries = new List <Country>() }; foreach (var name in input.Countries) { film.Countries.Add(daoCountry.GetCountryByEnglishName(name)); } if (poster != null && poster.ContentLength > 0) { try { if (poster.ContentType.Contains("image")) { var filename = Guid.NewGuid().ToString() + Path.GetExtension(poster.FileName); var path = Path.Combine(PathUtils.GetProjectDirectory(), "Cinematheque.WebSite\\images\\films\\", filename); poster.SaveAs(path); film.PosterFileName = filename; } else { throw new Exception("ERROR: Uploaded file is not image"); } } catch (Exception ex) { throw new Exception("ERROR:" + ex.Message.ToString()); } } else { film.PosterFileName = "default.jpg"; } if (input.Genres != null) { foreach (var id in input.Genres) { var genre = daoGenre.Find(id); film.AddGenre(genre); } } film.Director = daoDirector.Find(input.DirectorID); if (input.Actors != null) { foreach (var id in input.Actors) { var actor = daoActor.Find(id); film.AddActor(actor); } } return(film); }