public async Task CreateGameEventAsync(CreateGameEventDto requestedGameEvent) { var creator = await _repository.ApplicationUsers.SingleAsync( ApplicationUser.UserNameEquals(requestedGameEvent.CreatorUserName)); var creatorParticipation = new GameEventParticipation { ParticipantId = creator.Id, ParticipationStatus = ParticipationStatus.Creator }; var gameEvent = new GameEvent { Name = requestedGameEvent.Name, Date = requestedGameEvent.Date, Place = requestedGameEvent.Place, Games = requestedGameEvent.Games .Select((game, index) => new Game { Name = game, PositionOnTheList = index }).ToList(), Participations = new List <GameEventParticipation>(), Description = new DescriptionTab() }; gameEvent.Participations.Add(creatorParticipation); _repository.GameEvents.Add(gameEvent); await _repository.SaveChangesAsync(); }
private async Task SaveFriendshipAsync(Friendship friendship) { _repository.Friendships.Add(friendship); try { await _repository.SaveChangesAsync(); } catch (DbUpdateException e) when(e.InnerException is SqlException sqlException) { switch (sqlException.Number) { case 50000: throw new FriendRequestException( "You have already been invited by this user. Check your inbox for the friend request."); case 50001: throw new FriendRequestException( "You have already sent this user a friend request."); case 50002: throw new FriendRequestException("You are already friends."); default: throw new ArgumentOutOfRangeException( $"Uncaught SQL Exception with error number {sqlException.Number} occured."); } } }
private async Task ChangeGameEventParticipationStatusAsync( GameEventParticipation participation, ParticipationStatus participationStatus) { participation.ParticipationStatus = participationStatus; await _repository.SaveChangesAsync(); }
public async Task EditDescriptionTabAsync(EditDescriptionTabDto editDescriptionTabDto) { var descriptionTab = await _repository.DescriptionTabs .SingleAsync(dt => dt.Id == editDescriptionTabDto.Id); descriptionTab.Description = editDescriptionTabDto.Description; await _repository.SaveChangesAsync(); }
public async Task AddGroupAsync(string userName, string groupName) { if (string.IsNullOrEmpty(groupName)) { throw new GroupsException("Group name cannot be empty."); } var user = await _repository.ApplicationUsers.SingleAsync(ApplicationUser.UserNameEquals(userName)); var group = new Group { Name = groupName, OwnerId = user.Id, Owner = user }; _repository.Groups.Add(group); await _repository.SaveChangesAsync(); }