Ejemplo n.º 1
0
        public async Task BookRoom(BookingCreate booking)
        {
            var bookingToDb = Mapper.Map <Booking>(booking);

            Booking.Add(bookingToDb);
            await SaveChangesAsync();
        }
        public ActionResult <BookingDetail> CreateBooking(BookingCreate p)
        {
            var Booking = this.mapper.Map <Booking>(p);

            Booking = this.BookingRepository.Create(Booking);
            return(this.mapper.Map <BookingDetail>(Booking));
        }
Ejemplo n.º 3
0
 public IHttpActionResult Post(BookingCreate model)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (_service.CreateBooking(model))
     {
         return(Ok());
     }
     return(InternalServerError());
 }
        public bool CreateBooking(BookingCreate model)
        {
            var entity =
                new Booking()
            {
                DestId  = model.DestId,
                TransId = model.TransId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Bookings.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public IHttpActionResult Post(BookingCreate booking)
        {
            booking.UserId = User.Identity.GetUserId();
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateBookingService();

            if (!service.CreateBooking(booking))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
Ejemplo n.º 6
0
        public async Task UpdateBooking(BookingCreate booking)
        {
            var bookingToUpdate = FindExistingBooking(booking);
            var newBooking      = Mapper.Map <Booking>(booking);

            // Using reflection to set all properties of the existing booking to the ones coming in.
            foreach (PropertyInfo propertyInfo in bookingToUpdate.GetType().GetProperties())
            {
                if (propertyInfo.CanRead)
                {
                    propertyInfo.SetValue(bookingToUpdate, propertyInfo.GetValue(newBooking));
                }
            }

            await SaveChangesAsync();
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Create([FromBody] BookingCreate booking)
        {
            if (booking == null)
            {
                return(BadRequest());
            }
            await context.BookRoom(booking);

            var routeParameters = new
            {
                roomId    = booking.RoomId,
                startTime = booking.StartTime,
                endTime   = booking.EndTime
            };

            var uri = "api/calendar/roomId/startTime/endTime";

            return(Created(uri, routeParameters));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> UpdateBooking(int id, [FromBody] BookingCreate newBooking)
        {
            if (newBooking == null || newBooking.Id != id)
            {
                return(BadRequest());
            }

            var BookingToUpdate = context.FindExistingBooking(newBooking);

            if (BookingToUpdate == null)
            {
                return(NotFound());
            }
            else if (BookingToUpdate.OccupantId != newBooking.OccupantId || BookingToUpdate.RoomId != newBooking.RoomId)
            {
                return(BadRequest());
            }

            await context.UpdateBooking(newBooking);

            return(new NoContentResult());
        }
Ejemplo n.º 9
0
        public bool CreateBooking(BookingCreate model)
        {
            var newBooking = new Booking
            {
                SpaceId     = model.SpaceId,
                RenterId    = model.RenterId,
                BookingDate = DateTime.Now,
                StartDate   = model.StartDate,
                EndDate     = model.EndDate,
                Status      = "booked"
            };

            try
            {
                using (var ctx = new ApplicationDbContext())
                {
                    var space = ctx.Spaces
                                .Where(s => s.Id == model.SpaceId && s.Status == "vacant")
                                .FirstOrDefault();
                    if (space == null)
                    {
                        return(false);
                    }

                    ctx.Bookings.Add(newBooking);
                    space.Status = "booked";

                    return(ctx.SaveChanges() == 2);
                }
            }
            catch (Exception e)
            {
                SentrySdk.CaptureException(e);
                return(false);
            }
        }
Ejemplo n.º 10
0
 public Booking FindExistingBooking(BookingCreate newBooking)
 {
     // It's okay to return null, that's handled in the Controller.
     return(Booking.First(b => b.Id == newBooking.Id));
 }