public ActionResult Index() { List <Evenement> evenements = DalGenerique <Evenement> .GetInstance().GetAll(); List <CreateEditEvenementVM> evenementsVM = new List <CreateEditEvenementVM>(); DateTime now = DateTime.Now; foreach (var evenement in evenements.Where(a => a.DateDebut > now).OrderByDescending(a => a.DateDebut)) { var defaultImage = evenement.Images.FirstOrDefault(a => a.IsDefault == true && a.Evenement.Images.Count() > 0); var genericImage = new Image() { Nom = "defaultImage.png" }; var vm = new CreateEditEvenementVM { defaultImage = defaultImage ?? genericImage, Evenement = evenement }; evenementsVM.Add(vm); } return(View(evenementsVM)); }
public ActionResult Evenement(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Evenement evenement = DalGenerique <Evenement> .GetInstance().GetById(id); if (evenement == null) { return(HttpNotFound()); } CreateEditEvenementVM evenementsVM = new CreateEditEvenementVM(); var defaultImage = evenement.Images.FirstOrDefault(a => a.IsDefault == true && a.Evenement.Images.Any()); var genericImage = new Image() { Nom = "defaultImage.png" }; evenementsVM.defaultImage = defaultImage ?? genericImage; evenementsVM.Evenement = evenement; return(View(evenementsVM)); }
public static bool CreateImage(HttpRequestBase request, HttpServerUtilityBase server, CreateEditEvenementVM eventVm, List <Evenement> evenements, int index) { var file = (null != request.Files[index]) ? request.Files[index] : null; var filename = Path.GetFileName(file?.FileName); // Check non nullité avec '?' if (filename == null) { return(false); } // TODO - Create Constante pour l'url de stockage des fichiers images des events var path = Path.Combine(server.MapPath("~/Content/images/evenements/"), filename); file.SaveAs(path); var img = new Image { Nom = filename, IsDefault = (index == 0) ? true : false, // Première image up désignée par défault Evenement = evenements.First(a => a.Id == eventVm.Evenement.Id) }; var isCreate = DalGenerique <Image> .GetInstance().Create(img); return((null != isCreate) ? true : false); }
public ActionResult DeleteConfirmed(int id) { var theme = DalGenerique <Theme> .GetInstance().GetById(id); DalGenerique <Theme> .GetInstance().Delete(theme.Id); return(RedirectToAction("Index")); }
// GET: Image/Create public ActionResult Create() { var vm = new CreateEditImageVM { Evenements = DalGenerique <Evenement> .GetInstance().GetAll() }; return(View(vm)); }
// GET: Evenements/Create public ActionResult Create() { var vm = new CreateEditEvenementVM { Themes = DalGenerique <Theme> .GetInstance().GetAll() }; return(View(vm)); }
public ActionResult Create([Bind(Include = "Identifiant,Nom,IsDefault")] CreateEditImageVM imageVm) { if (imageVm.IdSelectedEvent.HasValue) { imageVm.Image.Evenement = DalGenerique <Evenement> .GetInstance().GetById(imageVm.IdSelectedEvent.Value); } DalGenerique <Image> .GetInstance().Create(imageVm.Image); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,Nom")] Theme theme) { if (!ModelState.IsValid) { return(View(theme)); } DalGenerique <Theme> .GetInstance().Update(theme); return(RedirectToAction("Index")); }
// GET: Themes/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var theme = DalGenerique <Theme> .GetInstance().GetById(id); return(View(theme)); }
// GET: Evenements/Edit/5 public ActionResult Edit(int id) { var vm = new CreateEditEvenementVM { Evenement = DalGenerique <Evenement> .GetInstance().GetById(id), Themes = DalGenerique <Theme> .GetInstance().GetAll(), Images = ImageRepository.GetInstance().GetImagesByIdEvent(id) }; return(View(vm)); }
public static void UpdateEvenement(CreateEditEvenementVM eventVm) { if (eventVm.IdSelectedTheme.HasValue) { eventVm.Evenement.Theme = DalGenerique <Theme> .GetInstance().GetById(eventVm.IdSelectedTheme.Value); } var images = DalGenerique <Image> .GetInstance().GetAll(); eventVm.Evenement.Images = ImageRepository.GetInstance().GetImagesByIdEvent(eventVm.Evenement.Id); EvenementRepository.GetInstance().Update(eventVm.Evenement); }
// GET: Evenements/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var evenement = DalGenerique <Evenement> .GetInstance().GetById(id); if (evenement == null) { return(HttpNotFound()); } return(View(evenement)); }
// GET: Image/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Image image = DalGenerique <Image> .GetInstance().GetById(id); if (image == null) { return(HttpNotFound()); } return(View(image)); }
public static bool CreateEvenement(HttpRequestBase request, HttpServerUtilityBase server, CreateEditEvenementVM eventVm) { try { if (eventVm.IdSelectedTheme.HasValue) { eventVm.Evenement.Theme = DalGenerique <Theme> .GetInstance().GetById(eventVm.IdSelectedTheme.Value); } DalGenerique <Evenement> .GetInstance().Create(eventVm.Evenement); var evenements = DalGenerique <Evenement> .GetInstance().GetAll(); var nbFile = request.Files.Count; var fileExist = request.Files[0]?.ContentLength ?? 0; // On récupère ContentLength si différent de null if (nbFile <= 0 || fileExist <= 0) { return(false); } for (var i = 0; i < nbFile; i++) { var isCreated = EvenementsService.CreateImage(request, server, eventVm, evenements, i); if (isCreated != false) { continue; } return(false); } return(true); } catch (Exception ex) { throw new Exception(ex.Message); } }
// GET: Image public ActionResult Index() { return(View(DalGenerique <Image> .GetInstance().GetAll())); }