public async Task AddRelationAsync(Guid userId, Guid friendId) { if (userId == Guid.Empty) { throw new ArgumentNullException(nameof(userId)); } if (friendId == Guid.Empty) { throw new ArgumentNullException(nameof(friendId)); } if (_appDbContext.Relations.Any( s => s.UserId == userId && s.FriendId == friendId || s.UserId == friendId && s.FriendId == userId)) { return; } await _appDbContext.Relations.AddAsync(new Relation { UserId = userId, FriendId = friendId, SinceWhen = DateTime.Now }); await _appDbContext.SaveAsync(); }
public async Task AddMessageAsync(Message message) { if (message == null) { throw new ArgumentNullException(nameof(message)); } if (message.FromWho == Guid.Empty) { throw new ArgumentNullException(nameof(message.FromWho)); } var conversation = _appDbContext.Conversations.FirstOrDefault(x => x.FirstUser == message.ToWho && x.SecondUser == message.FromWho || x.FirstUser == message.FromWho && x.SecondUser == message.ToWho); if (conversation == null) { conversation = new Conversation { FirstUser = message.ToWho, SecondUser = message.FromWho }; _appDbContext.Conversations.Add(conversation); } message.ConversationId = conversation.Id; await _appDbContext.Messages.AddAsync(message); await _appDbContext.SaveAsync(); }
public async Task AddNotificationAsync(Notification notification) { if (notification == null) { throw new ArgumentNullException(nameof(notification)); } if (notification.FromWho == Guid.Empty) { throw new ArgumentNullException(nameof(notification.FromWho)); } await _appDbContext.Notifications.AddAsync(notification); await _appDbContext.SaveAsync(); }
public async Task AddProfilePicture(Guid userId, string imagePath) { if (userId == Guid.Empty || imagePath == null) { throw new ArgumentNullException(); } User user = await _appDbContext.Users .SingleOrDefaultAsync(x => x.Id == userId); if (user == null) { throw new ArgumentNullException(); } user.ProfileImagePath = imagePath; await _appDbContext.SaveAsync(); }
public async Task AddPostAsync(Post post) { if (post == null) { throw new ArgumentNullException(nameof(post)); } if (post.UserId == Guid.Empty) { throw new ArgumentNullException(nameof(post.UserId)); } await _appDbContext.Posts.AddAsync(post); await _appDbContext.SaveAsync(); }