public async Task <int> CreateHotelAsync(RegisterHotelDTO model) { var currentUser = _userResolverService.GetUser(); var currentUserName = currentUser.FindFirst(ClaimTypes.NameIdentifier).Value; User user = await _userManager.FindByIdAsync(currentUserName); var city = CreateCity(model.CityName); if (!_userManager.IsInRoleAsync(user, "Hotel manager").Result) { await _userManager.AddToRoleAsync(user, "Hotel manager"); } model.StatusId = (int)HotelStatusTypes.Pending; var hotelManager = new HotelUser(); model.CityId = city.Id; var hotel = _mapper.Map <Hotel>(model); hotel.CityId = city.Id; hotelManager.Hotel = hotel; hotelManager.User = user; _hotelAppContext.HotelUsers.Add(hotelManager); hotel.HotelUsers.Add(hotelManager); _hotelAppContext.Hotels.Add(hotel); _hotelAppContext.SaveChanges(); _logger.LogInformation("Hotel successfully added!"); return(hotel.Id); }
public int CreateRoom(AddRoomDTO model) { var room = _mapper.Map <Room>(model); _hotelAppContext.Rooms.Add(room); _hotelAppContext.SaveChanges(); _logger.LogInformation("Room successfully created!"); return(room.Id); }
public async Task <int> CreateReservationAsync(ReservationDTO model, int roomId) { var currentUser = _userResolverService.GetUser(); var currentUserName = currentUser.FindFirst(ClaimTypes.NameIdentifier).Value; User user = await _userManager.FindByIdAsync(currentUserName); var reservation = _mapper.Map <Reservation>(model); reservation.CreationDate = DateTime.Now; reservation.RegisteredUser = user; reservation.ReservationStatusId = (int)ReservationStatusTypes.Processing; reservation.RoomId = roomId; _hotelAppContext.Reservations.Add(reservation); _hotelAppContext.SaveChanges(); _logger.LogInformation("Reservation successfully created!"); return(reservation.Id); }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new HotelAppContext( serviceProvider.GetRequiredService <DbContextOptions <HotelAppContext> >())) { // Look for any movies. if (context.Room.Any()) { return; // DB has been seeded } context.Room.AddRange( new Room { RoomNumber = "1", Description = "Basis Kamer" }, new Room { RoomNumber = "2", Description = "Basis Kamer" }, new Room { RoomNumber = "3", Description = "Luxe Kamer" }, new Room { RoomNumber = "4", Description = "Luxe Kamer" } ); context.SaveChanges(); } }
public virtual void Commit() { _context.SaveChanges(); }