public async Task <IActionResult> ReadStringDataManual()
        {
            hotelsContext hotelsContext = new hotelsContext();

            int      id       = hotelsContext.Reservation.Max(h => (int)h.Id) + 1;
            string   name     = Request.Form["name"];
            string   surname  = Request.Form["surname"];
            string   email    = Request.Form["email"];
            DateTime datefrom = DateTime.ParseExact(Request.Form["datefrom"], "yyyy-MM-dd", CultureInfo.InvariantCulture);
            DateTime dateto   = DateTime.ParseExact(Request.Form["dateto"], "yyyy-MM-dd", CultureInfo.InvariantCulture);
            int      roomid   = Convert.ToInt32(Request.Form["roomid"]);

            var r = new Reservation
            {
                Id       = id,
                Name     = name,
                Surname  = surname,
                Email    = email,
                DateFrom = datefrom,
                DateTo   = dateto,
                RoomId   = roomid
            };

            hotelsContext.Reservation.Add(r);
            hotelsContext.SaveChanges();
            return(Redirect("/"));
        }
        public async Task <IActionResult> Index(string searchString)
        {
            hotelsContext hotelsContext = new hotelsContext();

            hotelsContext.Hotels
            .GroupJoin(hotelsContext.Countries,
                       h => h.CountryId,
                       c => c.Id,
                       (ho, co) => new {
                Hotels    = ho,
                Countries = co
            }).ToList();

            var hotels = from h in hotelsContext.Hotels
                         select h;

            if (!String.IsNullOrEmpty(searchString))
            {
                hotels = hotels.Where(h => h.Name.Contains(searchString));
            }

            ViewData["hotels"] = hotels;
            return(View());
        }
Exemple #3
0
        public async Task <IActionResult> Index(int id)
        {
            hotelsContext hotelsContext = new hotelsContext();

            hotelsContext.Hotels
            .GroupJoin(hotelsContext.Countries,
                       h => h.CountryId,
                       c => c.Id,
                       (ho, co) => new {
                Hotels    = ho,
                Countries = co
            }).ToList();

            hotelsContext.Rooms
            .GroupJoin(hotelsContext.Hotels,
                       r => r.HotelId,
                       h => h.Id,
                       (ro, ho) => new {
                Hotels    = ho,
                Countries = ro
            }).ToList();

            var rooms = from r in hotelsContext.Rooms
                        where r.HotelId == id
                        select r;

            ViewData["rooms"] = rooms;

            var hotel = from r in hotelsContext.Hotels
                        where r.Id == id
                        select r;

            ViewData["hotel"] = hotel;

            return(View());
        }