public TourDayModel(TourModel tour) { this.TourId = tour.TourId; this.NoOfDays = tour.NoOfDays; this.TourTitle = tour.TourTitle; }
public ActionResult Edit(TourModel model) { try { ModelState state = ModelState["TourBannerImage"]; if (state != null) state.Errors.Clear(); if (ModelState.IsValid) { model.UpdatedOn = DateTime.UtcNow; model.UpdatedBy = GetUser().UserId; if (Request.Files["TourBannerImage"].ContentLength > 0) { HttpPostedFileBase imageFile = Request.Files["TourBannerImage"]; model.TourBannerImage = imageFile.FileName; //Get the physical path for the uploads folder and make sure it exists string folderToUpload = Server.MapPath("~/images/tours/"); //Resize Images Generate each version ImageUtils.TourImageResize(imageFile, folderToUpload); } TourModel tourUpdated = TourRepository.UpdateTour(model); if (tourUpdated != null) // return RedirectToAction("Tours", new { message = MessageType.Success }); return RedirectToAction("Tours", new { message = MessageType.Success }); return RedirectToAction("Tours", new { message = MessageType.Error }); } return View(model); } catch (Exception) { throw; } }
public ActionResult Create(TourModel model) { if (ModelState.IsValid) { try { if (Request.Files["TourBannerImage"].ContentLength > 0) { HttpPostedFileBase imageFile = Request.Files["TourBannerImage"]; model.TourBannerImage = imageFile.FileName; //Get the physical path for the uploads folder and make sure it exists string folderToUpload = Server.MapPath("~/images/tours/"); //Resize Images Generate each version ImageUtils.TourImageResize(imageFile, folderToUpload); } model.Description = HttpUtility.HtmlEncode(model.Description); model.CreatedBy = GetUser().UserId; model.CreatedOn = DateTime.UtcNow; TourModel addedTour = TourRepository.CreateTour(model.ToEntity()); if (addedTour != null) // return RedirectToAction("Tours", new { message = MessageType.Success }); return RedirectToAction("Tours", new { message = MessageType.Success, id = addedTour.TourId }); return RedirectToAction("Tours", new { message = MessageType.Error }); } catch (Exception) { throw; } } return View(model); }
public ActionResult Delete(TourModel tour) { try { bool status = TourRepository.DeleteTour(tour.TourId); if (!status) return RedirectToAction("Tours", new { message = MessageType.Error }); return RedirectToAction("Tours", new { message = MessageType.Success }); } catch (TourNotFoundException) { throw; } catch (Exception) { throw; } }
internal static TourModel UpdateTour(TourModel model) { try { TourModel tourUpdated = null; using (SriLankaToursEntities context = new SriLankaToursEntities()) { TourEntity entityTour = context.TourEntities.Find(model.TourId); if (entityTour == null) throw new TourNotFoundException(); if (string.IsNullOrEmpty(model.TourBannerImage)) model.TourBannerImage = entityTour.TourBannerImage; entityTour.NoOfDays = model.NoOfDays; entityTour.TourBannerImage = model.TourBannerImage; entityTour.TourTitle = model.TourTitle; entityTour.UpdatedBy = model.UpdatedBy; entityTour.UpdatedOn = model.UpdatedOn; entityTour.Visible = model.Visible; entityTour.Description = model.Description; context.SaveChanges(); return tourUpdated = GetTour(entityTour.TourId); } } catch (Exception) { throw; } }