public async Task <ActionResult <Room> > PostRoomItem(Room item)
        {
            _context.Rooms.Add(item);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetRoomItem), new { id = item.Id }, item));
        }
Esempio n. 2
0
        public async Task <ActionResult <Agency> > PostAgencyItem(Agency item)
        {
            _context.Agencies.Add(item);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetAgencyItem), new { id = item.Id }, item));
        }
        public async Task <ActionResult <Hotel> > PostHotelItem(Hotel item)
        {
            _context.Hotels.Add(item);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetHotelItem), new { id = item.Id }, item));
        }
Esempio n. 4
0
        public async Task <ActionResult <AuthUser> > PostGuestItem(AuthUser item)
        {
            _context.Users.Add(item);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetGuestItem), new { id = item.Id }, item));
        }
        public async Task <ActionResult <Payment> > PostPaymentItem(Payment item)
        {
            _context.Payments.Add(item);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetPaymentItem), new { id = item.Id }, item));
        }
        public async Task <ActionResult <Booking> > PostBookingItem([FromBody] BookingPostRequest request)
        {
            if (request.CheckIn > request.CheckOut)
            {
                return(BadRequest("Datum prijave ne može biti veći od dana odjave"));
            }

            var booking = new Booking {
                CheckIn  = request.CheckIn,
                CheckOut = request.CheckOut,
                UserId   = request.UserId,
                RoomId   = request.RoomId,
                AgencyId = request.AgencyId
            };

            _context.Bookings.Add(booking);
            // _context.Payments.Add(payment);
            await _context.SaveChangesAsync();

            booking = await _context
                      .Bookings
                      .Include(b => b.Room)
                      .Include(b => b.Agency)
                      .FirstAsync(b => b.Id == booking.Id);

            var payment = new Payment {
                AgencyId = booking.AgencyId,
                UserId   = booking.UserId,
                Price    = booking.Room.PricePerNight * (booking.CheckOut - booking.CheckIn).Days * (1 + booking.Agency.Commission / 100)
            };

            _context.Payments.Add(payment);
            await _context.SaveChangesAsync();

            return(Ok(booking));
        }