Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("HotelsId,HotelsName,HotelsCompanyName,HotelsTitle,HotelsDescription,HotelsMap,HotelsRating,HotelsRoomtype,HotelsSeatPrice,CheckIn,CheckoutTime,ImageName")] HotelsModel hotelsModel)
        {
            if (id != hotelsModel.HotelsId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(hotelsModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HotelsModelExists(hotelsModel.HotelsId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(hotelsModel));
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Post(HotelsModel hotel)
        {
            byte[] imageBytes = Convert.FromBase64String(hotel.ImagePath);
            Hotel  newHotel   = new Hotel();

            newHotel.Description = hotel.Description;
            newHotel.Name        = hotel.Name;
            newHotel.ImageData   = imageBytes;
            context.Hotels.Add(newHotel);
            context.SaveChanges();
            return(Request.CreateResponse(
                       HttpStatusCode.Created));
        }
Ejemplo n.º 3
0
        public ActionResult Index(HotelsSearch search, string name, string address, string userRateFrom, string userRateTo,
                                  string yourRateFrom, string yourRateTo, string distance, string lat, string lng, int?page)
        {
            ViewBag.CurrentSearch = new HotelsSearch();
            ViewBag.Empty         = null;
            if (search != null)
            {
                page = 1;
                ViewBag.CurrentSearch = search;
                search.lat            = lat;
                search.lng            = lng;
            }
            else
            {
                ViewBag.CurrentSearch.nameSearch    = name;
                ViewBag.CurrentSearch.addressSearch = address;
                ViewBag.CurrentSearch.usersRateFrom = userRateFrom;
                ViewBag.CurrentSearch.usersRateTo   = userRateTo;
                ViewBag.CurrentSearch.yourRateFrom  = yourRateFrom;
                ViewBag.CurrentSearch.yourRateTo    = yourRateTo;
                ViewBag.CurrentSearch.distance      = distance;
                ViewBag.CurrentSearch.lat           = lat;
                ViewBag.CurrentSearch.lng           = lng;
                search = ViewBag.CurrentSearch;
            }
            int  pageSize   = 10;
            int  pageNumber = (page ?? 1);
            bool canRate    = User.Identity.IsAuthenticated;
            var  user       = HttpContext.User.Identity;
            var  idUser     = _accountSqlExecutor.GetUserId(user.Name);
            var  canEdit    = false;

            if (user.Name == "Admin")
            {
                canEdit = true;
            }
            var         hotels = _hotelsSqlExecutor.FilterHotels(search, canRate, idUser);
            HotelsModel model  = new HotelsModel {
                Hotels = hotels.ToPagedList <Hotel>(pageNumber, pageSize), CanEdit = canEdit, CanRate = canRate, Search = search
            };

            return(View(model));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("HotelsId,HotelsName,HotelsCompanyName,HotelsTitle,HotelsDescription,HotelsMap,HotelsRating,HotelsRoomtype,HotelsSeatPrice,CheckIn,CheckoutTime,ImageFile,ImageName")] HotelsModel hotelsModel)
        {
            if (ModelState.IsValid)
            {
                //Save image to wwwroot/image
                string wwwRootPath = iweb.WebRootPath;
                string fileName    = Path.GetFileNameWithoutExtension(hotelsModel.ImageFile.FileName);
                string extension   = Path.GetExtension(hotelsModel.ImageFile.FileName);
                hotelsModel.ImageName = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                string path = Path.Combine(wwwRootPath + "/Image/Hotels/", fileName);
                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    await hotelsModel.ImageFile.CopyToAsync(fileStream);
                }
                //Insert record
                _context.Add(hotelsModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(hotelsModel));
        }
Ejemplo n.º 5
0
        public List <HotelsModel> GetAllHotel()
        {
            List <HotelsModel> list = new List <HotelsModel>();

            try
            {
                DataTable dt = new CDatabase().GetAllHotels().Tables[0];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    HotelsModel obj = new HotelsModel();
                    if (Int32.Parse(dt.Rows[i]["Status"].ToString()) == 1)
                    {
                        obj.ID          = Int32.Parse(dt.Rows[i]["ID"].ToString());
                        obj.LogoUrl     = dt.Rows[i]["LogoUrl"].ToString();
                        obj.Name        = dt.Rows[i]["Name"].ToString();
                        obj.Phone       = dt.Rows[i]["Phone"].ToString();
                        obj.Mobile      = dt.Rows[i]["Mobile"].ToString();
                        obj.RoomCount   = Int32.Parse(dt.Rows[i]["RoomCount"].ToString());
                        obj.Status      = Int32.Parse(dt.Rows[i]["Status"].ToString());
                        obj.Website     = dt.Rows[i]["Website"].ToString();
                        obj.Email       = dt.Rows[i]["Email"].ToString();
                        obj.Code        = dt.Rows[i]["Code"].ToString();
                        obj.Address     = dt.Rows[i]["Address"].ToString();
                        obj.Description = dt.Rows[i]["Description"].ToString();

                        obj.Modifyby = string.IsNullOrEmpty(dt.Rows[i]["Modifyby"].ToString()) ? 0 : Int32.Parse(dt.Rows[i]["Modifyby"].ToString());
                        obj.Createby = string.IsNullOrEmpty(dt.Rows[i]["Createby"].ToString()) ? 0 : Int32.Parse(dt.Rows[i]["Createby"].ToString());
                        //obj.CreateDate =  dt.Rows[i][""].ToString();
                        //obj.ModifyDate = dt.Rows[i]["ModifyDate"].ToString();
                        list.Add(obj);
                    }
                }
                return(list);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }