Ejemplo n.º 1
0
        public ActionResult Create(Walk walk)   //Method overloading, two identical methods with different parameters
        {
            try
            {
                walk.Duration = walk.Duration * 60;
                _walkRepo.AddWalk(walk);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                int           ownerId = GetCurrentUserId();
                Owner         owner   = _ownerRepo.GetOwnerById(ownerId);
                List <Walker> walkers = _walkerRepo.GetWalkersInNeighborhood(owner.NeighborhoodId);
                List <Dog>    dogs    = _dogRepo.GetDogsByOwnerId(ownerId);

                WalkFormViewModel vm = new WalkFormViewModel()
                {
                    Walk    = new Walk(),
                    Walkers = walkers,
                    Dogs    = dogs
                };
                return(View(vm));
            }
        }
Ejemplo n.º 2
0
 //this is the POST functionality in the Create method for a walk, which will take in the selectedDogs Ids as strings and the view model
 public ActionResult Create(IEnumerable <string> selectedDogs, WalkFormViewModel walkform)
 {
     try
     {
         foreach (string idString in selectedDogs)
         {
             walkform.Walk.DogId = int.Parse(idString);
             _walkRepo.AddWalk(walkform.Walk);
         }
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         //if something goes wrong we return to the view, which is the WalkFormViewModel
         List <Walker>         walkers            = _walkerRepo.GetAllWalkers();
         List <Dog>            dogs               = _dogRepo.GetAllDogs();
         List <SelectListItem> listSelectListItem = new List <SelectListItem>();
         WalkFormViewModel     vm = new WalkFormViewModel()
         {
             Walk     = new Walk(),
             Dogs     = dogs,
             Walkers  = walkers,
             DogsList = listSelectListItem
         };
         return(View(vm));
     }
 }
Ejemplo n.º 3
0
 public ActionResult Create(Walk walk)
 {
     try
     {
         _walkRepo.AddWalk(walk);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View(walk));
     }
 }
Ejemplo n.º 4
0
 public ActionResult Create(WalksFormViewModel vm)
 {
     try
     {
         Walker walker = _walkerRepo.GetWalkerById(vm.Walk.WalkerId);
         vm.Walk.Walker   = walker;
         vm.Walk.Duration = vm.Walk.Duration * 60;
         _walkRepo.AddWalk(vm.Walk);
         return(RedirectToAction("Index", "Owner"));
     }
     catch
     {
         return(View(vm));
     }
 }
Ejemplo n.º 5
0
        public ActionResult Create(RequestWalkViewModel viewModel)
        {
            try
            {
                _walkRepo.AddWalk(viewModel.Walk);

                return(RedirectToAction(nameof(Index), "Owners"));
            }
            catch
            {
                RequestWalkViewModel sameView = viewModel;
                viewModel.Dogs = _dogRepo.GetDogsByOwnerId(GetCurrentUserId());

                return(View(sameView));
            }
        }
Ejemplo n.º 6
0
        public ActionResult CreateWalk(WalkFormViewModel walkFormViewModel)
        {
            try
            {
                foreach (int dogId in walkFormViewModel.DogIds)
                {
                    Walk walk = new Walk()
                    {
                        Date     = walkFormViewModel.Walk.Date,
                        Duration = walkFormViewModel.Walk.Duration,
                        WalkerId = walkFormViewModel.Walk.WalkerId,
                        DogId    = dogId
                    };

                    _walkRepo.AddWalk(walk);
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View(walkFormViewModel));
            }
        }