public Task <TattooEditViewModel> GetTattooEditViewModel(TattooEditInputModel inputModel, Profile profile) { var viewModel = Mapper.Map <TattooEditInputModel, TattooEditViewModel>(inputModel); viewModel.Albums = Mapper.Map <List <Album>, List <SelectListItem> >(profile.Albums); viewModel.Albums.Add(new SelectListItem() { Text = "None", Value = "0", Selected = true }); return(Task.FromResult(viewModel)); }
public async Task <IActionResult> Edit(int id, TattooEditInputModel inputModel) { if (ModelState.IsValid) { var tattoo = await _tattooService.GetTattooWithStyles(id); var authorizeResultTask = _authorizationService.AuthorizeAsync(User, tattoo, "EditPolicy"); if (!authorizeResultTask.GetAwaiter().GetResult().Succeeded) { return(Forbid()); } var profileId = _userManager.GetProfileId(User); await _tattooViewModelService.EditTattooByViewModel(inputModel, tattoo); } var profile = _profileService.GetProfileWithAlbums(_userManager.GetProfileId(User)); var viewModel = await _tattooViewModelService.GetTattooEditViewModel(inputModel, await profile); return(View(viewModel)); }
public async Task EditTattooByViewModel(TattooEditInputModel viewModel, Tattoo tattoo) { var selectedStyles = viewModel.StylesCheckBoxes.Where(x => x.Checked == true).Select(s => s.Value).ToList(); await _tattooService.EditTattoo(tattoo, viewModel.Description, selectedStyles, viewModel.Album); }