コード例 #1
0
        // GET: Hotels/Edit/5
        public async Task <IActionResult> EditHotel(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var hotels = await _context.Hotels.SingleOrDefaultAsync(m => m.IdHotel == id);

            if (hotels == null)
            {
                return(NotFound());
            }
            HotelCreateViewModel HotelPass = hotelRepositories.GetHotelCreateViewModel(hotels);

            var facilities = _context.Facilities.ToArray();
            //change facilities if they ar pozitive or not
            var facilitiesHotel = _context.FacilitiesHotel.Where(x => x.IdHotel == hotels.IdHotel).ToList();

            for (int i = 0; i < facilities.Length; i++)
            {
                foreach (var hotel_facility in facilitiesHotel)
                {
                    if (facilities[i].IdFacilities == hotel_facility.IdFacilities)
                    {
                        facilities[i].IsChecked = true;
                    }
                }
            }
            HotelPass.facilities = facilities;


            ViewData["IdLocation"] = new SelectList(_context.Location, "IdLocation", "RegionName", hotels.IdLocation);
            return(View(HotelPass));
        }
コード例 #2
0
        public async Task <IActionResult> EditHotel(int id, [Bind("IdHotel,DescriptionTable,HotelName,Stars,IdLocation,ImageHotel,facilities")] HotelCreateViewModel hotels /*, [Bind("ImageHotel")] List<IFormFile> ImageHotel,[Bind("facilities")] Facilities[] facilitiesSelectedForHotel*/)
        {
            if (id != hotels.IdHotel)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                int _IdHotelImage = _context.HotelImages.Last().IdImageHotel;

                if (!(hotels.ImageHotel == null))
                {
                    hotelRepositories.SaveImages(hotels.ImageHotel, hotels.IdHotel, _IdHotelImage);
                }

                hotelRepositories.SaveChangesFacilities(hotels.facilities, hotels.IdHotel);

                Hotels hotelUpdate = new Hotels()
                {
                    IdHotel          = id,
                    DescriptionTable = hotels.DescriptionTable,
                    HotelName        = hotels.HotelName,
                    Stars            = hotels.Stars,
                    IdLocation       = hotels.IdLocation
                };
                // the edit hotel part
                try
                {
                    _context.Update(hotelUpdate);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HotelsExists(hotels.IdHotel))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                hotels.GaleryImages = _context.HotelImages.Where(x => x.IdHotel == hotels.IdHotel).ToArray();
                hotels.imagesString = new string[hotels.GaleryImages.Length];
                //new List<string>();
                int imageNumber = 0;
                foreach (var item in hotels.GaleryImages)
                {
                    hotels.imagesString[imageNumber] = (Convert.ToBase64String(item.ImageHotel));
                    imageNumber++;
                }
            }
            ViewData["IdLocation"] = new SelectList(_context.Location, "IdLocation", "RegionName", hotels.IdLocation);
            return(View(hotels));
        }
コード例 #3
0
        public ActionResult Create()
        {
            var model = new HotelCreateViewModel();

            model.Information = new HtmlContent("/Views/Hotel/InformationTemp.html").Text;

            ViewBag.Facility = new FacilityModel().SelectListItems;
            ViewBag.Scenics  = new ScenicModel().SelectListItems;
            ViewBag.ImgKey   = Guid.NewGuid().GetHashCode().ToString("x");
            model.Enabled    = true;
            return(View(model));
        }
コード例 #4
0
        // end of code

        public HotelCreateViewModel GetHotelCreateViewModel(Hotels hotels)
        {
            HotelCreateViewModel HotelPass = new HotelCreateViewModel()
            {
                IdHotel          = hotels.IdHotel,
                HotelName        = hotels.HotelName,
                DescriptionTable = hotels.DescriptionTable,
                Stars            = hotels.Stars,
                IdLocation       = hotels.Stars,
                GaleryImages     = context.HotelImages.Where(x => x.IdHotel == hotels.IdHotel).ToArray()
            };

            HotelPass.imagesString = new string[HotelPass.GaleryImages.Length];

            int imageNumber = 0;

            foreach (var item in HotelPass.GaleryImages)
            {
                HotelPass.imagesString[imageNumber] = (Convert.ToBase64String(item.ImageHotel));
                imageNumber++;
            }

            return(HotelPass);
        }
コード例 #5
0
        public ActionResult Edit(HotelCreateViewModel model)
        {
            model.UserId = CurrentUser.Id;

            if (ModelState.IsValid)
            {
                if (model.ID == 0)
                {
                    model.Create();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    model.Edit();
                    return(RedirectToAction("Edit", model.ID));
                }
            }

            //var CheckboxForScenics = new ScenicsCheckbox().ConverToCheckbox(model.Scenics.Split(','));
            //ViewBag.Scenics = CheckboxForScenics;
            //var CheckboxForServiceoption = new ServiceOptionCheckbox().ConverToCheckbox(model.ServiceOptions.Split(','));
            //ViewBag.ServiceOptions = CheckboxForServiceoption;
            return(View(model.ID));
        }
コード例 #6
0
        public ActionResult Edit(int?id = null)
        {
            //ViewBag.Facility = new FacilityModel().SelectListItems;
            //ViewBag.Scenics = new ScenicModel().SelectListItems;
            var result = new HotelCreateViewModel();

            var model = _db.Hotel.Where(o => o.ID == id).FirstOrDefault();

            #region ## 設施/景點
            if (model != null && !string.IsNullOrEmpty(model.Facility))
            {
                var chkoptions    = model.Facility.Split(',').ToList();
                var FacilityModel = new FacilityModel();
                FacilityModel.SelectedItems = chkoptions;
                ViewBag.Facility            = new FacilityModel().List(chkoptions);
            }
            else
            {
                ViewBag.Facility = new FacilityModel().SelectListItems;
            }

            if (model != null && !string.IsNullOrEmpty(model.Scenics))
            {
                var chkScenics = model.Scenics.Split(',').ToList();
                ViewBag.Scenics = new ScenicModel().List(chkScenics);
            }
            else
            {
                ViewBag.Scenics = new ScenicModel().SelectListItems;
            }
            #endregion

            if (id == null || model == null)
            {
                result.Information = new HtmlContent("/Views/Hotel/InformationTemp.html").Text;

                ViewBag.ImgKey = Guid.NewGuid().GetHashCode().ToString("x");
                result.Enabled = true;
                result.SaleOff = true;
                return(View(result));
            }

            result.ID          = model.ID;
            result.Information = model.Information;
            result.Introduce   = model.Introduce;
            result.Location    = model.Location;
            result.Name        = model.Name;
            result.Tel         = model.Tel;
            result.WebSite     = model.WebSite;
            result.Enabled     = model.Enabled;
            result.Feature     = model.Feature;
            result.Area        = model.Area;
            result.City        = model.City;
            result.Address     = model.Address;
            result.SaleOff     = model.SaleOff;
            result.Enabled     = true;



            ViewBag.CurrentCity     = model.City;
            ViewBag.CurrentArea     = model.Area;
            ViewBag.CurrentLocation = model.Location;
            var SessionKey = Guid.NewGuid().GetHashCode().ToString("x");
            ViewBag.ImgKey = SessionKey;
            var HotelImages = model.HotelImage.ToList();
            Session[SessionKey] = HotelImages;
            ViewBag.HotelImg    = HotelImages;

            var        City       = new Caches().TWCity;
            SelectList selectList = new SelectList(City, "ID", "Name", model.City);
            ViewBag.City = selectList;

            var Areas = new Caches().TWArea;

            //SelectList Areas = new SelectList(City, "ID", "Name", 0);
            var AreaList = Areas.Select(o => new DropDownListItem
            {
                DataAttr = o.CID.ToString(),
                Selected = model.Area <= 0 ? false : o.ID == model.Area,
                Text     = o.Name,
                Value    = o.ID.ToString()
            }).ToList();
            ViewBag.Area = AreaList;

            var        Location  = new Caches().TWLocation;
            SelectList Locations = new SelectList(Location, "Location", "Location", model.Location);
            ViewBag.Location = Locations;

            return(View(result));
        }