public async Task <ActionResult> UpdateProfile(ServiceProviderProfileViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var userId = User.Identity.GetUserId(); if (userId != null) { await _serviceProviderManager.UpdateServiceProviderProfileAsync(model, userId); return(RedirectToAction("Index", new { Message = ManageMessage.UpdateProfileSuccess })); } return(RedirectToAction("Index", new { Message = ManageMessage.Error })); }
public async Task UpdateServiceProviderProfileAsync(ServiceProviderProfileViewModel viewModel, string userId) { var dataModel = _mapper.Map <ServiceProviderProfile>(viewModel); dataModel.Id = userId; if (await context.ServiceProviderProfiles.AnyAsync(x => x.Id == dataModel.Id)) { context.ServiceProviderProfiles.Attach(dataModel); context.Entry <ServiceProviderProfile>(dataModel).State = EntityState.Modified; } else { context.ServiceProviderProfiles.Add(dataModel); } await context.SaveChangesAsync(); }