public async Task <ActionResult> Create(OwnerFormViewModel ownerFormModel) { try { _ownerRepo.AddOwner(ownerFormModel.Owner); List <Claim> claims = new List <Claim> { new Claim(ClaimTypes.NameIdentifier, ownerFormModel.Owner.Id.ToString()), new Claim(ClaimTypes.Email, ownerFormModel.Owner.Email), new Claim(ClaimTypes.Role, "DogOwner"), }; ClaimsIdentity claimsIdentity = new ClaimsIdentity( claims, CookieAuthenticationDefaults.AuthenticationScheme); await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity)); return(RedirectToAction(nameof(Details), new { id = ownerFormModel.Owner.Id })); } catch { ownerFormModel.ErrorMessage = "Whoops! Something went wrong while saving this owner"; ownerFormModel.Neighborhoods = _neighborhoodRepo.GetAll(); return(View(ownerFormModel)); } }
// GET: OwnerController/Create public ActionResult Create() { OwnerFormViewModel vm = new OwnerFormViewModel() { Owner = new Owner(), Neighborhoods = _neighborhoodRepo.GetAll() }; return(View(vm)); }
public ActionResult Edit(int id, OwnerFormViewModel vm) { try { _ownerRepo.UpdateOwner(vm.Owner); return(RedirectToAction("Index")); } catch (Exception ex) { return(View(vm.Owner)); } }
public ActionResult Edit(int id, OwnerFormViewModel vm) { try { _ownerRepository.UpdateOwner(vm.Owner); return(RedirectToAction(nameof(Index))); } catch { return(View(vm)); } }
private OwnerFormViewModel CreateFormViewModel(Owner owner) { List <Neighborhood> neighborhoods = _neighborhoodRepo.GetAll(); OwnerFormViewModel vm = new OwnerFormViewModel { Owner = owner, Neighborhoods = neighborhoods }; return(vm); }
// GET: OwnerController/Create public ActionResult Create() { List <Neighborhood> neighborhoods = _neighborhoodRepo.GetAll(); OwnerFormViewModel vm = new OwnerFormViewModel() { Owner = new Owner(), Neighborhoods = neighborhoods }; return(View(vm));//Will be a Virtural Model once created. }
// GET: Owner/Create public ActionResult Create() { List <Neighborhood> neighborhoods = _neighborhoodRepository.GetAll(); OwnerFormViewModel vm = new OwnerFormViewModel() { Owner = new Owner(), Neighborhoods = neighborhoods }; return(View(vm)); }
public ActionResult Create(OwnerFormViewModel vm) { try { _ownerRepository.AddOwner(vm.Owner); return(RedirectToAction("Index")); } catch (Exception ex) { return(View(vm)); } }
// GET: OwnersController/Create // GETTING THE FORM public ActionResult Create() { List <Neighborhood> neighborhoods = _neighborhoodRepo.GetAll(); OwnerFormViewModel vm = new OwnerFormViewModel() { NeighborhoodOptions = neighborhoods, Owner = new Owner() }; return(View(vm)); }
// GET: Owners/Edit/5 public ActionResult Edit(int id) { List <Neighborhood> neighborhoods = _neighborhoodRepo.GetAll(); Owner owner = _ownerRepo.GetOwnerById(id); OwnerFormViewModel vm = new OwnerFormViewModel() { Owner = owner, Neighborhoods = neighborhoods }; return(View(vm)); }
public ActionResult Create(OwnerFormViewModel vm) { try { _ownerRepo.AddOwner(vm.Owner); return(RedirectToAction("Details", new { id = vm.Owner.Id })); } catch { return(View(vm)); } }
// GET: OwnersController/Edit/5 public ActionResult Edit(int id) { Owner owner = _ownerRepo.GetOwnerById(id); if (owner == null) { return(NotFound()); } OwnerFormViewModel vm = CreateFormViewModel(owner); return(View(vm)); }
public ActionResult Create(OwnerFormViewModel vm) { try { _ownerRepository.AddOwner(vm.Owner); return(RedirectToAction(nameof(Index))); } catch { return(View(vm)); } }
public ActionResult Create(OwnerFormViewModel ownerFormViewModel) { try { _ownerRepo.AddOwner(ownerFormViewModel.Owner); return(RedirectToAction("Index")); } catch (Exception ex) { return(View(ownerFormViewModel)); } }
// GET: Owner/Edit/5 public ActionResult Edit(int id) { OwnerFormViewModel vm = new OwnerFormViewModel { Owner = _ownerRepo.GetOwnerById(id), Neighborhoods = _neighborhoodRepo.GetAll() }; if (vm.Owner == null) { return(NotFound()); } return(View(vm)); }
// GET: Owners/Create public ActionResult Create() { List <Neighborhood> neighborhoods = _neighborhoodRepo.GetAll(); neighborhoods.Sort((x, y) => string.Compare(x.Name, y.Name)); OwnerFormViewModel vm = new OwnerFormViewModel() { Owner = new Owner(), Neighborhoods = neighborhoods }; return(View(vm)); }
public ActionResult Create(OwnerFormViewModel viewModel) { try { _ownerRepo.AddOwner(viewModel.Owner); return(RedirectToAction("Index")); } catch (Exception ex) { viewModel.ErrorMessage = "Something went wrong"; viewModel.Neighborhood = _neighborhoodRepo.GetAll(); return(View(viewModel)); } }
// GET: OwnersController/Edit/5 public ActionResult Edit() { int id = GetCurrentUserId(); Owner owner = _ownerRepository.GetOwnerById(id); List <Neighborhood> neighborhoods = _neighborhoodRepository.GetAll(); OwnerFormViewModel vm = new OwnerFormViewModel() { Owner = owner, Neighborhoods = neighborhoods }; return(View(vm)); }
public ActionResult Edit(int id, OwnerFormViewModel viewModel) { try { _ownerRepo.UpdateOwner(viewModel.Owner); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { viewModel.ErrorMessage = "An error occured in your edit submission."; viewModel.Neighborhood = _neighborhoodRepo.GetAll(); return(View(viewModel)); } }
public ActionResult Create(OwnerFormViewModel vm) { try { _ownerRepo.AddOwner(vm.Owner); return(RedirectToAction("Index")); } catch (Exception ex) { vm.Neighborhoods = _hoodRepo.GetAll(); return(View(vm)); } }
public ActionResult Create(OwnerFormViewModel viewModel) { try { viewModel.ErrorMessage = "Woops! Something went wrong while saving this owner"; _ownerRepo.AddOwner(viewModel.Owner); return(RedirectToAction(nameof(Index))); } catch { viewModel.Neighborhoods = _neighborhoodRepo.GetAll(); return(View(viewModel)); } }
public ActionResult Edit(int id, Owner owner) { OwnerFormViewModel vm = CreateFormViewModel(owner); try { _ownerRepo.UpdateOwner(owner); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { return(View(vm)); } }
public ActionResult Edit(int id, OwnerFormViewModel ownerFormModel) { try { _ownerRepo.UpdateOwner(ownerFormModel.Owner); return(RedirectToAction(nameof(Index))); } catch { ownerFormModel.Neighborhoods = _neighborhoodRepo.GetAll(); return(View(ownerFormModel)); } }
public ActionResult Create(Owner owner) { OwnerFormViewModel vm = CreateFormViewModel(new Owner()); try { _ownerRepo.AddOwner(owner); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { return(View(vm)); } }
//the sever is handing the user a blank html form. The user is getting the form // GET: OwnersController/Create public ActionResult Create() { //bringing in the list of neighborhoods List <Neighborhood> neighborhoods = _neighborhoodRepo.GetAll(); //creating an obect to hold owner and the list of neighborhoods OwnerFormViewModel vm = new OwnerFormViewModel() { Owner = new Owner(), Neighborhoods = neighborhoods, }; //returning the view model return(View(vm)); }
public ActionResult Create(OwnerFormViewModel vm) { try { _ownerRepo.AddOwner(vm.Owner); return(RedirectToAction("Details", new { id = vm.Owner.Id })); } catch (Exception ex) { //vm.ErrorMessage = "Woops! Something went wrong while saving this owner"; vm.Neighborhoods = _neighborhoodRepo.GetAll(); return(View(vm)); } }
public ActionResult Create(OwnerFormViewModel vm) { try { _ownerRepo.AddOwner(vm.Owner); return(RedirectToAction("Index")); } catch (Exception ex) { vm.Neighborhoods = _neighborhoodRepo.GetAll(); // If something goes wrong, just keep the user on the same page so they can try again return(View(vm)); } }
public ActionResult Details(int id) { Owner owner = _ownerRepo.GetOwnerById(id); List <Dog> dogs = _dogRepo.GetDogsByOwnerId(owner.Id); List <Walker> walkers = _walkerRepo.GetWalkersInNeighborhood(owner.NeighborhoodId); OwnerFormViewModel vm = new OwnerFormViewModel() { Owner = owner, Dog = dogs, Walkers = walkers }; return(View(vm)); }
// GET: Owners/Edit/5 public ActionResult Edit(int id) { // List the required elements needed to render the view the user should see Owner owner = _ownerRepo.GetOwnerById(id); List <Neighborhood> neighborhoods = _neighborhoodRepo.GetAll(); OwnerFormViewModel vm = new OwnerFormViewModel() { Owner = owner, Neighborhoods = neighborhoods }; return(View(vm)); }
public ActionResult Edit(int id, OwnerFormViewModel vm) { try { _ownerRepo.UpdateOwner(vm.Owner); return(RedirectToAction("Index")); } catch { vm.ErrorMessage = "Woops! Something went wrong while saving this owner"; vm.NeighborhoodOptions = _neighborhoodRepo.GetAll(); return(View(vm)); } }