//Add a response public Response AddResponse(string text, string userId, int questionId) { Response response = new Response() { Text = text, QuestionId = questionId, RespondedBy = userId, RespondedAt = DateTimeOffset.Now, IsSolution = false, Votes = 1, Inappropriate = false, MarkAsDeleted = false }; _context.Responses.Add(response); _context.SaveChangesAsync(); return(response); }
public User Register(CreateUser user) { if (_context.Users.Where(x => x.Username == user.Username).FirstOrDefaultAsync().Result != null) { throw new Exception("User already exists."); } var NewUser = new User() { Username = user.Username, DateJoined = DateTimeOffset.UtcNow, HashedPassword = BCrypt.Net.BCrypt.HashPassword(user.Password), }; _context.Users.Add(NewUser); _context.SaveChangesAsync(); return(NewUser); }