static void Main(string[] args) { ProducteurService ps = new ProducteurService(); Producteur p = new Producteur { Nom = "test", prenom = "test", DateNaissance = DateTime.Now }; ps.Add(p); ps.Commit(); FilmService fs = new FilmService(); Film f = new Film { Titre = "film1", Description = "Test", // DateProd = DateTime.Now, DateProd = new DateTime(2016, 1, 1, 12, 00, 00), Price = 15, Genre = "Action", Evaluation = "Super", //avec validation // Genre = "ok", //Evaluation = "suoer", ImageUrl = "image", ProducteurId = 1 }; fs.Add(f); fs.Commit(); }
public void ADD_ShouldReturnFilmAdded() { //Arrange int x = 4; var film = new Film() { FilmId = x, Title = "Pain and Gain", Description = "Three bodybuilder will do anything to become rich", Year = 2014, Duration = "2h 10min", Genre = "Action/Drama", Rating = "8.1/10" }; var options = new DbContextOptionsBuilder <CinemaDbContext>() .UseInMemoryDatabase(databaseName: "ADD_ShouldReturnFilmAdded") .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking) .Options; var context = new CinemaDbContext(options); SeedFilms(context); var service = new FilmService(context); //Act var result = service.Add(film); //Assert Assert.Equal(result.Title, film.Title); }
public ActionResult Create(Film f, HttpPostedFileBase Image) { f.ImageUrl = Image.FileName; serviceFilm.Add(f); serviceFilm.Commit(); var path = Path.Combine(Server.MapPath("~/Content/Upload/"), Image.FileName); Image.SaveAs(path); return(RedirectToAction("Index")); }
public ActionResult Create(Models.Film filmVM, HttpPostedFileBase Image) { Domaine.Film film = new Domaine.Film(); film.Titre = filmVM.Titre; film.Price = filmVM.Prix; film.DateProd = filmVM.ReleaseDate; film.Description = filmVM.Description; film.Genre = filmVM.Genre; film.ImageUrl = filmVM.ImageUrl; film.ProducteurId = filmVM.ProducteurId; film.Evaluation = filmVM.Avis; film.ImageUrl = Image.FileName; serviceFilm.Add(film); serviceFilm.Commit(); var path = Path.Combine(Server.MapPath("~/Content/Upload/"), Image.FileName); Image.SaveAs(path); return(RedirectToAction("Index")); }
public ActionResult Create(Film film, HttpPostedFileBase file) { var path = ""; if (file != null) { string FileName = Path.GetFileName(Request.Files[0].FileName); if (file.ContentLength > 0) { //for checking uploaded file is image or not if (Path.GetExtension(file.FileName).ToLower() == ".jpg" || Path.GetExtension(file.FileName).ToLower() == ".png" || Path.GetExtension(file.FileName).ToLower() == ".gif" || Path.GetExtension(file.FileName).ToLower() == ".jpeg") { path = Path.Combine(Server.MapPath("~/Content/Images"), FileName); file.SaveAs(path); FileName = "/Content/Images/" + FileName; film.Image = FileName; } } } try { if (ModelState.IsValid) { filmService.Add(film); return(RedirectToAction("Index")); } } catch (DataException) { ModelState.AddModelError("", "Không thể tạo phim!"); } return(View(film)); }
public IActionResult Create(Films model) { _service.Add(model); return(CreatedAtRoute("GetFilm", new { id = model.Id }, model)); }