Esempio n. 1
0
 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"));
 }
Esempio n. 2
0
 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"));
 }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        public ActionResult Add()
        {
            ContestantDTO contestant = new ContestantDTO();

            contestant.Districts = Mapper.Map <IEnumerable <DistrictDTO> >(unitOfWork.District.GetAll());
            return(View(contestant));
        }