public async Task <IActionResult> Create([FromBody] Reservation reservation)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var reserv = new Reservation
                    {
                        Id         = reservation.Id,
                        Name       = reservation.Name,
                        RoomId     = reservation.RoomId,
                        UserId     = reservation.UserId,
                        TimePeriod = reservation.TimePeriod,
                        Date       = reservation.Date
                    };

                    _context.Reservations.Add(reserv);

                    await _context.SaveChangesAsync();

                    ReservasionsStore.Save(_context.Reservations.ToList());
                    _logger.LogInformation($"resevation save id: {reservation.Id}");
                    return(Ok(reservation));
                }
                catch (Exception ex)
                {
                    _logger.LogError("Error occurend creating reservation", ex);
                    return(StatusCode(500));
                }
            }
            return(BadRequest(ModelState.Values.SelectMany(v => v.Errors).ToList()));
        }
        public async Task <IActionResult> Delete(Guid id)
        {
            try
            {
                var reservation = await _context.Reservations.FirstOrDefaultAsync(x => x.Id == id);

                if (reservation == null)
                {
                    return(NotFound());
                }

                _context.Reservations.Remove(reservation);

                await _context.SaveChangesAsync();

                ReservasionsStore.Save(_context.Reservations.ToList());

                return(Ok("Done!"));
            }
            catch (Exception ex)
            {
                _logger.LogError("Error occurend creating reservation", ex);
                return(StatusCode(500));
            }
        }
        public void ShouldBeSaveReservations()
        {
            var reservations = new List <Reservation>()
            {
                new Reservation()
                {
                    Id     = Guid.NewGuid(),
                    Name   = "new Project",
                    Date   = DateTime.Parse("2040-01-01"),
                    RoomId = 10, TimePeriod = "7h - 8h"
                }
            };

            Assert.IsTrue(ReservasionsStore.Save(reservations));
        }
        public async Task <IActionResult> Edit(Guid id, Reservation reservation)
        {
            try
            {
                var reservationDb = await _context.Reservations.FirstOrDefaultAsync(x => x.Id == id);

                if (reservationDb == null)
                {
                    throw new Exception("Could not find reservation");
                }
                if (reservationDb.RoomId != reservation.RoomId)
                {
                    _context.Reservations.Remove(reservationDb);
                    var newReservation = new Reservation()
                    {
                        Id         = reservation.Id,
                        UserId     = 1,
                        Name       = reservation.Name,
                        Date       = reservation.Date,
                        TimePeriod = reservation.TimePeriod,
                        RoomId     = reservation.RoomId,
                    };
                    await _context.Reservations.AddAsync(newReservation);
                }
                else
                {
                    reservationDb.Name       = reservation.Name;
                    reservationDb.Date       = reservation.Date;
                    reservationDb.TimePeriod = reservation.TimePeriod;
                }
                await _context.SaveChangesAsync();

                ReservasionsStore.Save(_context.Reservations.ToList());
                return(Ok("Done!"));
            }

            catch (Exception ex)
            {
                _logger.LogError("Error occurend creating reservation", ex);
                return(StatusCode(500));
            }
            ;
        }