Example #1
0
 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);
 }
Example #2
0
        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");
        }
Example #3
0
        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);
            }
        }