public async Task <IActionResult> CreateNewBooking(NewBooking booking) { try { DateTime[] formatedDates = BookingsHelper.formatDates(booking.startDate, booking.endDate); booking.startDate = formatedDates[0]; booking.endDate = formatedDates[1]; List <string> errors = await BookingsHelper.validations(booking.startDate, booking.endDate, mySQLDBContext, booking.idRoom); errors.AddRange(BookingsHelper.validationsBooking(booking.startDate, booking.endDate, mySQLDBContext, booking.idRoom)); if (errors.Count != 0) { return(BadRequest(errors)); } Bookings newBooking = new Bookings { idRoom = booking.idRoom, startDate = booking.startDate, endDate = booking.endDate }; await mySQLDBContext.AddAsync(newBooking); await mySQLDBContext.SaveChangesAsync(); return(Ok(newBooking)); } catch (Exception e) { logger.LogError(e.Message); return(StatusCode(500)); } }
public async Task <IActionResult> AddRoom(Rooms room) { try { List <string> errors = await RoomsHelper.Validations(room, mySQLDBContext); if (errors.Count != 0) { return(BadRequest(errors)); } await mySQLDBContext.AddAsync(room); await mySQLDBContext.SaveChangesAsync(); return(Ok(room)); } catch (Exception e) { logger.LogError(e.Message); return(StatusCode(500)); } }