예제 #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));
            }
        }
예제 #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));
     }
 }
예제 #3
0
 public ActionResult RequestAWalk(WalkFormViewModel vm)
 {
     try
     {
         _ownerRepo.AddWalk(vm.Walk);
         return(RedirectToAction("Index", "Owner"));
     }
     catch
     {
         return(View(vm));
     }
 }
예제 #4
0
        // GET: Walks/Create
        public ActionResult Create(int id)
        {
            WalkFormViewModel vm = new WalkFormViewModel()
            {
                Dogs = _dogsRepo.GetDogsByOwnerId(GetCurrentUserId()),
                Walk = new Walks()
                {
                    WalkerId = id,
                    Date     = DateTime.Today
                }
            };

            return(View(vm));
        }
예제 #5
0
        public ActionResult Create(WalkFormViewModel vm)
        {
            vm.Walk.Duration     = 0;
            vm.Walk.WalkStatusId = 1;
            vm.Dogs = _dogsRepo.GetDogsByOwnerId(GetCurrentUserId());

            try
            {
                // TODO: Add insert logic here
                _walksRepo.AddWalk(vm.Walk);
                return(RedirectToAction("Details", "Owners", new { id = GetCurrentUserId() }));
            }
            catch
            {
                return(View(vm));
            }
        }
예제 #6
0
        // GET: WalksController/Create
        public ActionResult Create()
        {
            int   currentUserId = GetCurrentUserId();
            Owner thisOwner     = _ownerRepo.GetOwnerById(currentUserId);

            Walk walk = new Walk();

            WalkFormViewModel vm = new WalkFormViewModel()
            {
                Walkers      = _walkerRepo.GetWalkersInNeighborhood(thisOwner.NeighborhoodId),
                Dogs         = _dogRepo.GetDogsByOwnerId(thisOwner.Id),
                WalkStatuses = _walkStatusRepo.GetWalkStatuses(),
                Walk         = walk
            };

            return(View(vm));
        }
예제 #7
0
        // GET: Walks/Create
        public ActionResult Create()
        {
            int                   ownerId = GetCurrentUserId();
            Owner                 owner   = _ownerRepo.GetOwnerById(ownerId);
            List <Walker>         walkers = _walkerRepo.GetWalkersInNeighborhood(owner.NeighborhoodId);
            List <Dog>            dogs    = _dogRepo.GetDogsByOwnerId(ownerId);
            List <SelectListItem> items   = new List <SelectListItem>();



            WalkFormViewModel vm = new WalkFormViewModel()
            {
                Walk    = new Walk(),
                Walkers = walkers,
                Dogs    = dogs
            };

            return(View(vm));
        }
예제 #8
0
        // GET WalkersController/CreateWalk
        public ActionResult CreateWalk(int id)
        {
            int        ownerId = GetCurrentUserId();
            Walker     walker  = _walkerRepo.GetWalkerById(id);
            List <Dog> dogs    = _dogRepo.GetDogsByOwnerId(ownerId);

            WalkFormViewModel vm = new WalkFormViewModel()
            {
                Walk = new Walk()
                {
                    WalkerId = walker.Id,
                    Duration = 0
                },
                Walks  = new List <Walk>(),
                Walker = walker,
                Dogs   = dogs,
            };

            return(View(vm));
        }
예제 #9
0
        public ActionResult RequestAWalk(int id)
        {
            Owner owner = _ownerRepo.GetOwnerById(id);

            int ownerId = GetCurrentUserId();

            if (ownerId != owner.Id)
            {
                return(NotFound());
            }
            List <Dog>    dogs    = _dogRepo.GetDogsByOwnerId(owner.Id);
            List <Walker> walkers = _walkerRepo.GetWalkersInNeighborhood(owner.NeighborhoodId);

            WalkFormViewModel vm = new WalkFormViewModel()
            {
                Owner = owner,
                Dogs  = dogs,
                WalkersInNeighborhood = walkers
            };

            return(View(vm));
        }
예제 #10
0
        // GET: WalksController/Create
        public ActionResult Create()
        {
            //getting list of all the walkers
            List <Walker> walkers = _walkerRepo.GetAllWalkers();
            //getting list of all the dogs
            List <Dog> dogs = _dogRepo.GetAllDogs();
            //this will be a list of all the dogs (iterating through the dogs list and adding them to the listSelectListItem )
            List <SelectListItem> listSelectListItem = new List <SelectListItem>();

            foreach (Dog dog in dogs)
            {
                //with each iteration we are setting the properties of this SelectListItem object
                //and adding each object to the list
                //Text is a property of the SelectListItem class (display text of the selected item)
                //Value is a property of SelectListItem class (value of the selected item- int needs to be converted to string)
                //Selected is a property of SelectListItem class (value that indicated whether this SelectListItem has been selected - boolean on the Dog class)
                SelectListItem selectListItem = new SelectListItem()
                {
                    Text     = dog.Name,
                    Value    = dog.Id.ToString(),
                    Selected = dog.isSelected
                };
                //with each iteration each item with these properties will be added to the list of dogs
                listSelectListItem.Add(selectListItem);
            }

            //instanstiate the viewmodel and set the properties of the viewmodel to the proper values; DogsList will be the listSelectListItem that was
            //formed with each addition of the dog to the list
            WalkFormViewModel vm = new WalkFormViewModel()
            {
                Walk     = new Walk(),
                Dogs     = dogs,
                Walkers  = walkers,
                DogsList = listSelectListItem
            };

            return(View(vm));
        }
예제 #11
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));
            }
        }