Пример #1
0
 public ViewResult CreateHotel()
 {
     var context = new TourEntities1();
     EditHotelModel model = new EditHotelModel()
     {
         Hotel = new Hotel(),
         Resort = new SelectList(context.Resort, "Id", "Name")
     };
     return View("EditHotel", model);
 }
Пример #2
0
        private void FillModelEditHotel(ref EditHotelModel model, int Id)
        {
            model = model ?? new EditHotelModel();

            var context = new TourEntities1();
            model.Hotel = context.Hotel.FirstOrDefault(p => p.Id == Id);
            model.Resort = new SelectList(context.Resort, "Id", "Name");
        }
Пример #3
0
        public ActionResult EditHotel(EditHotelModel model, HttpPostedFileBase image)
        {
            var context = new TourEntities1();

            if (ModelState.IsValid)
            {
                if (image != null)
                {
                    model.Hotel.ImageMimeType = image.ContentType;
                    model.Hotel.ImageData = new byte[image.ContentLength];
                    image.InputStream.Read(model.Hotel.ImageData, 0, image.ContentLength);
                }
                SaveHotel(model.Hotel);
                TempData["message"] = string.Format("{0} has been saved", model.Hotel.Name);
                return RedirectToAction("Index");
            }
            else
            {
                FillModelEditHotel(ref model, model.Hotel.Id);
                return View(model);
            }
        }