public async Task <HttpResponseMessage> AddUser([FromBody] User user) { sendOperation = async() => { await unitOfWork.IRepoUser.Add(user); }; StringValues stream; HttpContext.Request.Headers.TryGetValue("Authorization", out stream); user.UserModified = GetUserId(stream); return(await genericOperation.Execute(sendOperation, EnumOperation.Add, this.ControllerContext.RouteData, (int)user.UserModified)); }
public async Task <IActionResult> Login([FromBody] User login) { IActionResult response = Unauthorized(); User userCheck = await unitOfWork.IRepoUser.CheckUser(login); if (userCheck != null) { TokenData data = new TokenData() { IdUser = userCheck.UserId, Role = userCheck.RoleId ?? 0, }; try { var token = GenerateJWT(data); response = Ok(new { token = token, time = DateTime.Now.AddHours(12), userDetail = data }); await genericOperation.Execute(null, EnumOperation.PassLogin, this.ControllerContext.RouteData, (int)userCheck.UserId); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, "Wystąpił błąd serwera")); } } else { this.ControllerContext.RouteData.Values.Add("Login", login.Login); await genericOperation.Execute(null, EnumOperation.FailLogin, this.ControllerContext.RouteData, 0); } return(response); }