Beispiel #1
0
 public Hotel CreateHotel(Hotel hotel)
 {
     using (var hotelDbContext = new HotelDbContext())
     {
         hotelDbContext.Add(hotel);
         hotelDbContext.SaveChanges();
         return(hotel);
     }
 }
        public async Task <T> Add(T entity)
        {
            using (HotelDbContext context = new HotelDbContext())
            {
                context.Add(entity);
                await context.SaveChangesAsync();

                return(entity);
            }
        }
Beispiel #3
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,PhoneNumber,Email,IsAdult")] Client client)
        {
            if (ModelState.IsValid)
            {
                _context.Add(client);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(client));
        }
        public async Task <IActionResult> Create([Bind("ID,Name")] Amenity amenity)
        {
            if (ModelState.IsValid)
            {
                _context.Add(amenity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(amenity));
        }
        public async Task <IActionResult> Create([Bind("ID,Name,Layout")] Room room)
        {
            if (ModelState.IsValid)
            {
                _context.Add(room);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(room));
        }
Beispiel #6
0
        public async Task <IActionResult> Create([Bind("ID,HotelName,Address,City,State,Zip")] Hotel hotel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(hotel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(hotel));
        }
Beispiel #7
0
        public async Task <IActionResult> Create([Bind("Id,Capacity,Type,PriceForAdult,PriceForKid,Number")] Room room)
        {
            if (ModelState.IsValid)
            {
                _context.Add(room);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(room));
        }
        public async Task <IActionResult> Create([Bind("HotelID,RoomNumber,RoomID,RoomName,RoomRate,PetFriendly")] HotelRoom hotelRoom)
        {
            if (ModelState.IsValid)
            {
                _context.Add(hotelRoom);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["HotelID"] = new SelectList(_context.Hotel, "ID", "HotelName", hotelRoom.HotelID);
            return(View(hotelRoom));
        }
Beispiel #9
0
        public async Task <IActionResult> Create([Bind("AmenityID,RoomID")] RoomAmenity roomAmenity)
        {
            if (ModelState.IsValid)
            {
                _context.Add(roomAmenity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AmenityID"] = new SelectList(_context.Amenities, "ID", "Name", roomAmenity.AmenityID);
            ViewData["RoomID"]    = new SelectList(_context.Rooms, "ID", "Name", roomAmenity.RoomID);
            return(View(roomAmenity));
        }
Beispiel #10
0
        public async Task <IActionResult> Create([Bind("HotelID,RoomID,RoomNumber,Rate,PetFriendly")] HotelRoom hotelRoom)
        {
            if (_context.HotelRooms.Any(hr => hr.RoomNumber == hotelRoom.RoomNumber))
            {
                ModelState.AddModelError("", $"{hotelRoom.RoomNumber} already exists.");
            }

            if (ModelState.IsValid)
            {
                _context.Add(hotelRoom);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["HotelID"] = new SelectList(_context.Hotels, "ID", "Name", hotelRoom.HotelID);
            ViewData["RoomID"]  = new SelectList(_context.Rooms, "ID", "Name", hotelRoom.RoomID);
            return(View(hotelRoom));
        }
        public async Task <IActionResult> Create([Bind("Id,RoomId,ClientsIDs,DateOfArrival,DateOfLeaving,IsBreakfastIncluded,IsAllInclusive")] Reservation reservation)
        {
            if (ModelState.IsValid)
            {
                var current_User = _userManager.GetUserAsync(HttpContext.User).Result;
                reservation.UserId = current_User.Id;
                foreach (var id in reservation.ClientsIDs)
                {
                    reservation.Clients.Add(_context.Clients.Find(id));
                }
                reservation.Cost = CalculateCost(reservation);
                _context.Add(reservation);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["Room"] = new List <SelectListItem>();
            foreach (var room in _context.Rooms)
            {
                ViewBag.Room.Add(new SelectListItem {
                    Text = room.Number.ToString(), Value = room.Id.ToString()
                });
            }
            ViewData["User"] = new List <SelectListItem>();
            foreach (var user in _context.Users)
            {
                ViewBag.User.Add(new SelectListItem {
                    Text = user.UserName, Value = user.Id
                });
            }
            ViewData["Client"] = new List <SelectListItem>();
            foreach (var client in _context.Clients)
            {
                ViewBag.Client.Add(new SelectListItem {
                    Text = client.FirstName + client.LastName, Value = client.Id.ToString()
                });
            }
            return(View(reservation));
        }
Beispiel #12
0
        public Client GetOrAddClient(string clientName, string phone)
        {
            Client client;

            client = _context.Clients.FirstOrDefault(cl => cl.Name == clientName && cl.Phone == phone);

            if (client != null)
            {
                return(client);
            }

            client = new Client()
            {
                Id    = new Guid(),
                Name  = clientName,
                Phone = phone
            };

            _context.Add(client);
            _context.SaveChanges();

            return(client);
        }
        public IActionResult Create(ReservationCreateBindingModel reservationCreateBindingModel)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            decimal sum = 0;

            var roomId = context.Rooms.SingleOrDefault(
                r => r.Number == reservationCreateBindingModel.RoomNumber).Id;

            var priceForChild = Convert.ToDecimal(context.Rooms.FirstOrDefault(r => r.Id == roomId).PriceForBedAsChild);
            var priceForAdult = Convert.ToDecimal(context.Rooms.FirstOrDefault(r => r.Id == roomId).PriceForBedAsAdult);

            foreach (var item in context.Clients.ToList())
            {
                if (reservationCreateBindingModel.AllInclusive)
                {
                    sum += 100;
                    if (item.isAdult)
                    {
                        sum += priceForAdult;
                    }
                    else
                    {
                        sum += priceForChild;
                    }
                }
                else if (reservationCreateBindingModel.IncludedBreakfast)
                {
                    sum += 50;
                    if (item.isAdult)
                    {
                        sum += priceForAdult;
                    }
                    else
                    {
                        sum += priceForChild;
                    }
                }
                else
                {
                    sum += 150;
                    if (item.isAdult)
                    {
                        sum += priceForAdult;
                    }
                    else
                    {
                        sum += priceForChild;
                    }
                }
            }

            Reservation reservation = new Reservation
            {
                Id          = Guid.NewGuid().ToString(),
                RoomId      = roomId,
                HotelUserId = context.HotelUsers.SingleOrDefault(
                    r => r.UserName == reservationCreateBindingModel.HotelUserUsername).Id,
                DataOfIncoming    = reservationCreateBindingModel.DataOfIncoming,
                DateOfOutgoing    = reservationCreateBindingModel.DateOfOutgoing,
                includedBreakfast = reservationCreateBindingModel.IncludedBreakfast,
                allInclusive      = reservationCreateBindingModel.AllInclusive,
                AllAmount         = sum.ToString()
            };

            context.Add(reservation);
            context.SaveChangesAsync();

            return(Redirect("/Identity/ReservationList"));
        }
Beispiel #14
0
 public virtual void Insert(TEntity item)
 {
     context.Add <TEntity>(item);
 }
Beispiel #15
0
 /// <summary>
 /// Adds hotel
 /// </summary>
 /// <param name="hotel">hotel to be added</param>
 /// <returns></returns>
 public async Task AddHotel(Hotel hotel)
 {
     _context.Add(hotel);
     await _context.SaveChangesAsync();
 }