public async Task <IActionResult> Update([FromBody] CheckPostViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var ch = _mapper.Map <CheckListPost>(model); var userId = _claimPrincipalService.GetClaimFromHttp(); var user = await _userService.GetUserByClaimAsync(userId); var checkpost = new CheckListPost { Title = ch.Title, Color = ch.Color, User = user, Id = ch.Id }; _checkPostService.UpdateCheckPost(checkpost); return(new OkObjectResult("Post updated")); }
public async Task <int> Create([FromBody] CheckPostViewModel model) { //if (!ModelState.IsValid) //{ // return BadRequest(ModelState); //} var ch = _mapper.Map <CheckListPost>(model); var userId = _claimPrincipalService.GetClaimFromHttp(); var user = await _userService.GetUserByClaimAsync(userId); //if (!result.Succeeded) return new BadRequestObjectResult(Errors.AddErrorsToModelState(result, ModelState)); //await _appDbContext.User.AddAsync(new User { IdentityId = userIdentity.Id, Email = userIdentity.Email, Name = userIdentity.FirstName + " " + userIdentity.LastName, Username = userIdentity.UserName, Phone = userIdentity.PhoneNumber }); //await _appDbContext.SaveChangesAsync(); var checkpost = new CheckListPost { Title = ch.Title, Color = ch.Color, User = user }; int id = _checkPostService.InsertCheckPost(checkpost); return(id); }