public ActionResult EditAdvert(AdvertManageVM model) { var eventID = db.Events.FirstOrDefault(e => e.Id == model.Id).Id; var a = db.Advertisements.FirstOrDefault(o => o.Id == eventID); if (ModelState.IsValidField("startDate")) { if (model.startDate > model.endDate) { ModelState.AddModelError("startDate", "start date cannot exceed end date!"); } } if (model == null) { return(RedirectToAction("Index", "Admin")); } if (ModelState.IsValid) { a.Id = model.Id; a.startDate = model.startDate; a.endDate = model.endDate; db.SaveChanges(); TempData["info"] = "Advertisement record updated successfully"; return(RedirectToAction("DisplayAdvert", "Admin")); } ViewBag.EventList = new SelectList(db.Events, "Id", "name"); return(View(model)); }
public ActionResult EditAdvert(AdvertManageVM model) { var a = db.Advertisements.Find(model.Id); if (model == null) { return(RedirectToAction("Index", "Admin")); } int duration = ((int)model.endTime.TotalMinutes - (int)model.startTime.TotalMinutes) / 60; if (ModelState.IsValid) { a.name = model.name; a.des = model.des; a.charge = model.charge; a.startDate = model.startDate; a.endDate = model.endDate; a.startTime = model.startTime; a.endTime = model.endTime; a.duration = duration.ToString(); if (model.Photo != null) { DeletePhoto(a.photoURL); a.photoURL = SavePhoto(model.Photo); } db.SaveChanges(); TempData["info"] = "Advertisement record updated successfully"; return(RedirectToAction("DisplayAdvert", "Admin")); } return(View(model)); }
public ActionResult EditAdvert(int id) { var a = db.Advertisements.Find(id); if (a == null) { return(RedirectToAction("Index", "Admin")); } var model = new AdvertManageVM { Id = id, name = a.name, des = a.des, charge = a.charge, startDate = a.startDate, endDate = a.endDate, startTime = a.startTime, endTime = a.endTime, duration = a.duration, userId = a.userId, photoURL = a.photoURL, }; return(View(model)); }
public ActionResult EditAdvert(int id) { ViewBag.EventList = new SelectList(db.Events, "Id", "name"); var a = db.Advertisements.Find(id); if (a == null) { return(RedirectToAction("Index", "Admin")); } var model = new AdvertManageVM { Id = id, startDate = a.startDate, endDate = a.endDate, }; return(View(model)); }
public ActionResult InsertAdvert(AdvertManageVM model) { var id = db.Users.FirstOrDefault(u => u.username == User.Identity.Name).Id; string error = ValidatePhoto(model.Photo); if (error != null) { ModelState.AddModelError("Photo", error); } if (ModelState.IsValid) { int duration = ((int)model.endTime.TotalMinutes - (int)model.startTime.TotalMinutes) / 60; var a = new Advertisement { name = model.name, des = model.des, charge = model.charge, startDate = model.startDate, endDate = model.endDate, startTime = model.startTime, endTime = model.endTime, duration = duration.ToString(), status = true, userId = id, photoURL = SavePhoto(model.Photo) }; // TempData["Info"] = "Event record added successfully!"; db.Advertisements.Add(a); db.SaveChanges(); TempData["info"] = "Advertisement record inserted successfully"; return(RedirectToAction("DisplayAdvert", "Admin")); } else { TempData["Error"] = "Error"; } return(View(model)); }
public ActionResult InsertAdvert(AdvertManageVM model) { if (ModelState.IsValidField("startDate")) { if (model.startDate > model.endDate) { ModelState.AddModelError("startDate", "start date cannot exceed end date!"); } } var adv = db.Advertisements.Find(model.Id); if (adv != null) { ModelState.AddModelError("Id", "This event had been promoted! Please choose other options!"); } if (ModelState.IsValid) { var a = new Advertisement { Id = model.Id, startDate = model.startDate, endDate = model.endDate, status = true, }; db.Advertisements.Add(a); db.SaveChanges(); TempData["info"] = "Advertisement record inserted successfully"; return(RedirectToAction("DisplayAdvert", "Admin")); } else { TempData["Error"] = "Error"; } ViewBag.EventList = new SelectList(db.Events, "Id", "name"); return(View(model)); }