public ActionResult Update(int id, ContestantDTO contestant, HttpPostedFileWrapper PhotoUrl) { try { Contestant updcontestant = unitOfWork.Contestant.Get(id); string previousPhotoUrl = updcontestant.PhotoUrl; Mapper.Map(contestant, updcontestant); // Verify that the user selected a file if (PhotoUrl != null && PhotoUrl.ContentLength > 0) { // extract only the filename var fileName = Path.GetFileName(PhotoUrl.FileName); // store the file inside /Images/Photos folder var path = Path.Combine(Server.MapPath("~/Images/Photos"), fileName); PhotoUrl.SaveAs(path); updcontestant.PhotoUrl = fileName; } else { updcontestant.PhotoUrl = previousPhotoUrl; } unitOfWork.Contestant.Update(updcontestant); unitOfWork.Complete(); } catch (Exception e) { TempData["Message"] = "Contestant updating failed !"; TempData["MessageType"] = "danger"; return(RedirectToAction("Index")); } TempData["Message"] = "Contestant updated successfully !"; TempData["MessageType"] = "success"; return(RedirectToAction("Index")); }
public ActionResult Add(ContestantDTO contestant, HttpPostedFileWrapper PhotoUrl) { try { Contestant newcontestant = Mapper.Map <Contestant>(contestant); // Verify that the user selected a file if (PhotoUrl != null && PhotoUrl.ContentLength > 0) { // extract only the filename var fileName = Path.GetFileName(PhotoUrl.FileName); // store the file inside /Images/Photos folder var path = Path.Combine(Server.MapPath("~/Images/Photos"), fileName); PhotoUrl.SaveAs(path); newcontestant.PhotoUrl = fileName; } unitOfWork.Contestant.Add(newcontestant); unitOfWork.Complete(); } catch (Exception e) { TempData["Message"] = "Contestant adding failed !"; TempData["MessageType"] = "danger"; return(RedirectToAction("Index")); } TempData["Message"] = "Contestant added successfully !"; TempData["MessageType"] = "success"; return(RedirectToAction("Index")); }
public ActionResult Update(int id) { ContestantDTO contestant = Mapper.Map <ContestantDTO>(unitOfWork.Contestant.Get(id)); contestant.Districts = Mapper.Map <IEnumerable <DistrictDTO> >(unitOfWork.District.GetAll()); return(View(contestant)); }
public ActionResult Add() { ContestantDTO contestant = new ContestantDTO(); contestant.Districts = Mapper.Map <IEnumerable <DistrictDTO> >(unitOfWork.District.GetAll()); return(View(contestant)); }