public async Task <(Response response, int messageId)> CreateAsync(Message message) { if (message.Author == null && message.AuthorId != 0) { message.Author = _context.Users.FirstOrDefault(u => u.Id == message.AuthorId); } _context.Messages.Add(message); await _context.SaveChangesAsync(); return(Created, message.Id); }
public async Task <(Response response, int userId)> CreateAsync(User user) { if (await UserExists(0, user.Email)) { return(Conflict, 0); } await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); return(Created, user.Id); }
public async Task <long> AddMessage(MessageCreateDTO message, string username) { var userId = await GetUserId(username); var newMessage = new Message { AuthorId = userId, Text = message.content, PubDate = DateTimeOffset.UtcNow.ToUnixTimeSeconds(), Flagged = 0 }; _context.Messages.Add(newMessage); await _context.SaveChangesAsync(); return(newMessage.MessageId); }
public async Task UpdateLatestAsync(long value) { var latest = new Latest { Date = DateTime.Now, Value = value }; await _context.Latest.AddAsync(latest); await _context.SaveChangesAsync(); }
public async Task <HttpStatusCode> FollowUser(string username, string followName) { if (!await IsFollowing(username, followName)) { var WhoId = await GetUserId(username); var WhomId = await GetUserId(followName); var follower = new Follower { WhoId = (int)WhoId, WhomId = (int)WhomId }; _context.Followers.Add(follower); await _context.SaveChangesAsync(); return(NoContent); } return(BadRequest); }