public async Task <object> EditUserData([FromBody] EditUserSettingView model) { var userSub = User.Claims.Where(c => c.Type == USERNAME_TYPE).FirstOrDefault(); string username = userSub.Value; var result = new Error(); result.SetNoUser(); if (userSub != null) { var user = await _userManager.FindByNameAsync(username); var currentChildData = _context.ChildData.Where(c => c.Id.Equals(user.Id)).FirstOrDefault(); if (currentChildData == null) { return(Ok(new { Response = "Error invalid user ID" })); } currentChildData = SetChildData(currentChildData, model); _context.ChildData.Update(currentChildData); _context.SaveChanges(); Success response = new Success(); response.SetSuccessEdit(); return(JsonConvert.SerializeObject(response)); } return(JsonConvert.SerializeObject(result)); }
private ChildData SetChildData(ChildData currentChildData, EditUserSettingView model) { currentChildData.Id = model.Id; currentChildData.City = model.City; currentChildData.Country = model.Country; currentChildData.FirstName = model.FirstName; currentChildData.LastName = model.LastName; currentChildData.Latitude = model.Latitude; currentChildData.Longitude = model.Longitude; currentChildData.PostalCode = model.PostalCode; currentChildData.Province = model.Province; currentChildData.Street = model.Street; return(currentChildData); }