public async Task <User> GetCurrentUserAsync() { var login = _userAuthentication.GetCurrentUserName(); await using var mnpContext = _contextFactory.Create(); var user = await mnpContext.Users .IncludeImagesAndRoles() .AsNoTracking() .SingleOrDefaultAsync(u => u.UserName.ToLower() == login.ToLower()); return(user); }
public async Task <UserOffer> GetByIdAsync(Guid id) { await using var mnpContext = _contextFactory.Create(); var offer = await mnpContext.UserOffers .Include(o => o.Author) .ThenInclude(a => a.UserImages) .ThenInclude(ui => ui.File) .Include(o => o.Author) .ThenInclude(a => a.UserImages) .ThenInclude(ui => ui.CompressedFile) .Include(o => o.Periods) .Include(o => o.UserOfferGames) .ThenInclude(og => og.Game) .AsNoTracking() .FindByIdAsync(id); if (offer == null) { throw new NotFoundException($"Offer with {id} not found"); } return(offer); }
public async Task <Lobby> GetLobbyByIdAsync(Guid id) { await using var mnpContext = _contextFactory.Create(); var lobby = await mnpContext.Lobbies .Include(l => l.LobbyGames) .ThenInclude(lg => lg.Game) .Include(l => l.LobbyImages) .ThenInclude(i => i.File) .Include(l => l.LobbyImages) .ThenInclude(i => i.CompressedFile) .Include(l => l.LobbyPlayers) .ThenInclude(p => p.Player) .AsNoTracking() .FindByIdAsync(id); if (lobby == null) { throw new NotFoundException($"Lobby with {id} not found"); } return(lobby); }
public async Task ExecuteSeeding() { var country = new Country { Name = "Россия" }; var city = new City { Name = "Екатеринбург", Country = country }; var places = new List <Place> { new() { Name = "Антикафе «Автограф»", Description = "В антикафе вы платите только за проведённое время: одна минута здесь стоит два рубля. Каждый день здесь происходит что-то интересное и, конечно, не обходится без настольных игр. Тут играют в «Мафию», в Бэнг и устраивают большие игротеки. Впрочем, вы можете прийти и сыграть в любую игру вне расписания. Выбор очень большой!", PlaceType = PlaceType.Cafe }, new() { Name = "Антикафе «Коммуникатор»", Description = "Ещё одно антикафе, где всегда царит дружеская и домашняя атмосфера. Много настольных игр, насыщенное расписание, вкусный кофе делают это место очень популярным. Одна минута первого часа стоит два рубля, последующих часов - рубль. Приятно, что можно получить бессрочную карту постоянного гостя, которая даёт скидку на пребывание в заведении.", PlaceType = PlaceType.Cafe }, new() { Name = "Вместе Party Place", Description = "Пространство, в котором можно собраться компанией на любой праздник. Здесь не будет шумно и вам никто не помешает послушать музыку, попеть в караоке и поиграть в любимые настольные игры. Можно выбрать один из восьми залов в соответствии с количеством игроков.", PlaceType = PlaceType.Cafe } }; var files = new List <File> { new() { CreationDate = DateTime.Now, FileLink = "https://kudago.com/media/thumbs/m/images/place/2d/e7/2de7f29dba4fcb98377690ab9a6d162c.jpg" }, new() { CreationDate = DateTime.Now, FileLink = "https://kudago.com/media/thumbs/m/images/place/e7/26/e7269247edfc71ee3f7d8cd7a5f5a0bc.jpg" }, new() { CreationDate = DateTime.Now, FileLink = "https://kudago.com/media/thumbs/m/images/list/1f/c8/1fc8722cb7a6b576bba414f1904f6a89.jpg" } }; var placeImages = new List <PlaceImage> { new() { IsCurrentPoster = true, Place = places[0], File = files[0], CompressedFile = files[0] }, new() { IsCurrentPoster = true, Place = places[1], File = files[1], CompressedFile = files[1] }, new() { IsCurrentPoster = true, Place = places[2], File = files[2], CompressedFile = files[2] } }; var locations = new List <Location> { new() { Address = "ул. Добролюбова, д. 16", City = city, EndWorkHour = 22, IsActive = true, Place = places[0] }, new() { Address = "ул. Тургенева, д. 22", City = city, EndWorkHour = 22, IsActive = true, Place = places[1] }, new() { Address = "ул. Репина, д. 22", City = city, EndWorkHour = 22, IsActive = true, Place = places[2] } }; await using var mnpContext = _contextFactory.Create(); await mnpContext.AddAsync(country); await mnpContext.AddAsync(city); await mnpContext.AddRangeAsync(places); await mnpContext.AddRangeAsync(locations); await mnpContext.AddRangeAsync(files); await mnpContext.AddRangeAsync(placeImages); await mnpContext.SaveAndDetachAsync(); }
public async Task <Guid> CreateChatWithUserAsync(Guid userId) { await using var mnpContext = _contextFactory.Create(); var currentUserId = await _userService.GetCurrentUserIdAsync(); var alreadyCreatedChat = await mnpContext.Chats .FirstOrDefaultAsync(c => c.IsPersonalChat && c.ChatUsers.Select(c => c.UserId).Contains(currentUserId) && c.ChatUsers.Select(c => c.UserId).Contains(userId)); if (alreadyCreatedChat != null) { return(alreadyCreatedChat.Id); } var chat = new Chat { Name = "Переписка", CreationDate = DateTime.Now, IsPersonalChat = true, ChatUsers = new List <ChatUser> { new() { UserId = currentUserId, IsCreator = true }, new() { UserId = userId, IsCreator = false } } }; await mnpContext.AddAsync(chat); await mnpContext.SaveChangesAsync(); return(chat.Id); }