public IActionResult CreateProblem([FromBody] CreateProblemRequest request) { var user = UserService.Get(long.Parse(User.Identity.Name)); if (user == null) { return(NotFound(new ResponseModel { Success = false, Message = "Пользователь не найден" })); } var problem = new Problem { User = user, ProblemText = request.ProblemText }; ProblemService.Create(problem); return(Ok(new DataResponse <ProblemViewModel> { Data = new ProblemViewModel(problem) })); }
public IActionResult SignUp([FromBody] SignUpRequest request) { var user = UserService.FindByPhoneNumber(request.PhoneNumber); if (user != null) { return(BadRequest(new ResponseModel { Success = false, Message = "Номер телефона уже используется" })); } user = UserService.FindByEmail(request.Email); if (user != null) { return(BadRequest(new ResponseModel { Success = false, Message = "Email уже используется" })); } user = new User { FirstName = request.FirstName, LastName = request.LastName, PhoneNumber = request.PhoneNumber, Email = request.Email, Role = UserRole.Client, RegisteredAt = DateTime.UtcNow }; UserService.Create(user); UserWalletService.Create(new UserWallet { User = user, Balance = 0 }); ProblemService.Create(new Problem { User = user, ProblemText = request.Problem }); var session = UserSessionService.CreateSession(user); SmscHelper.SendSms(user.PhoneNumber, $"Код для входа: {session.AuthCode}"); return(Ok(new SignInResponse { UserID = user.ID })); }