public ViewResult Create() { var context = new TourEntities1(); EditHotTourModel model = new EditHotTourModel() { HotTour = new HotTours(), Hotel = new SelectList(context.Hotel, "Id", "Name") }; return View("Edit", model); }
private void FillModelEditHotTour(ref EditHotTourModel model, int Id) { model = model ?? new EditHotTourModel(); var context = new TourEntities1(); model.HotTour = context.HotTours.FirstOrDefault(p => p.Id == Id); model.Hotel = new SelectList(context.Hotel, "Id", "Name"); }
public ActionResult Edit(EditHotTourModel model, HttpPostedFileBase image) { var context = new TourEntities1(); if (ModelState.IsValid) { if (image != null) { model.HotTour.ImageMimeType = image.ContentType; model.HotTour.ImageData = new byte[image.ContentLength]; image.InputStream.Read(model.HotTour.ImageData, 0, image.ContentLength); } SaveHotTour(model.HotTour); TempData["message"] = string.Format("{0} has been saved", model.HotTour.Name); return RedirectToAction("Index"); } else { FillModelEditHotTour(ref model, model.HotTour.Id); return View(model); } }