Exemplo n.º 1
0
        // GET: WalksCOntroller/Create
        public ActionResult Create()
        {
            List <Walker> walkers = _walkerRepo.GetAllWalkers();
            List <Dog>    dogs    = _dogRepo.GetAllDogs();
            WalkFormModel vm      = new WalkFormModel()
            {
                Walks   = new Walks(),
                Dogs    = dogs,
                Walkers = walkers
            };

            return(View(vm));
        }
Exemplo n.º 2
0
        // GET: WalksController/Create
        public ActionResult Create()
        {
            List <Dog>    Dog    = _dogRepo.GetAllDogs();
            List <Walker> Walker = _walkerRepo.GetAllWalkers();

            WalksViewModel vm = new WalksViewModel
            {
                Dog    = Dog,
                Walker = Walker,
                Walk   = new Walks()
            };

            return(View(vm));
        }
Exemplo n.º 3
0
        public IActionResult GetDogs([FromQuery] DogsResourceParameters parameters, [FromHeader(Name = "Accept")] string mediaType)
        {
            if (!MediaTypeHeaderValue.TryParse(mediaType, out MediaTypeHeaderValue parsedMediaType))
            {
                return(BadRequest());
            }

            if (!_propertyMappingService.ValidMappingExistsFor <DogDto, Dog>(parameters.OrderBy))
            {
                return(BadRequest());
            }

            if (!_propertyCheckerService.TypeHasProperties <DogDto>(parameters.Fields))
            {
                return(BadRequest());
            }

            var dogsFromRepo = _dogRepository.GetAllDogs(parameters);

            Response.AddPagination(dogsFromRepo.TotalCount, dogsFromRepo.PageSize, dogsFromRepo.CurrentPage,
                                   dogsFromRepo.TotalPages, null, null);

            if (parsedMediaType.MediaType == "application/vnd.marvin.hateoas+json")
            {
                var linkedCollectionResource = GetLinkedCollectionResource(parameters, dogsFromRepo);
                return(Ok(linkedCollectionResource));
            }

            return(Ok(_mapper.Map <IEnumerable <DogDto> >(dogsFromRepo).ShapeData(parameters.Fields)));
        }
Exemplo n.º 4
0
 public ActionResult Create(WalksFormModel res)
 {
     try
     {
         foreach (int id in res.SelectedDogs)
         {
             res.Walks.DogId = id;
             _walksRepo.AddWalks(res.Walks);
         }
         return(RedirectToAction("Index", "Walker"));
     }
     catch
     {
         List <Dog>     Dogs = _dogRepo.GetAllDogs();
         WalksFormModel wfm  = new WalksFormModel()
         {
             Walks  = res.Walks,
             Owners = _ownerRepo.GetAllOwners(),
             Dogs   = Dogs.Select(x => new SelectListItem
             {
                 Value = x.Id.ToString(),
                 Text  = x.Name
             })
         };
         return(View(wfm));
     }
 }
Exemplo n.º 5
0
        private WalkerProfileViewModel createViewModel(int walkerId, Walker walker)
        {
            List <Walks> unsortedWalks  = _walksRepo.GetWalksByWalkerId(walkerId);
            List <Dog>   unsortedDogs   = _dogRepo.GetAllDogs();
            List <Owner> sortedOwners   = _ownerRepo.GetOwnersSortedByName();
            List <Dog>   sortedDogs     = new List <Dog>();
            List <Walks> sortedWalks    = new List <Walks>();
            List <Owner> relaventOwners = new List <Owner>();
            List <Dog>   relaventDogs   = new List <Dog>();

            foreach (Owner owner in sortedOwners)
            {
                foreach (Dog dog in unsortedDogs)
                {
                    if (dog.OwnerId == owner.id)
                    {
                        sortedDogs.Add(dog);
                    }
                }
            }
            foreach (Dog dog in sortedDogs)
            {
                foreach (Walks walk in unsortedWalks)
                {
                    if (dog.Id == walk.DogId)
                    {
                        sortedWalks.Add(walk);
                    }
                }
            }
            foreach (Walks walk in sortedWalks)
            {
                foreach (Dog dog in sortedDogs)
                {
                    if (walk.DogId == dog.Id)
                    {
                        relaventDogs.Add(dog);
                    }
                }
            }
            foreach (Dog dog in relaventDogs)
            {
                foreach (Owner owner in sortedOwners)
                {
                    if (dog.OwnerId == owner.id)
                    {
                        relaventOwners.Add(owner);
                    }
                }
            }
            WalkerProfileViewModel vm = new WalkerProfileViewModel
            {
                Walker = walker,
                Walk   = sortedWalks,
                Owner  = relaventOwners
            };

            return(vm);
        }
Exemplo n.º 6
0
        // GET: DogController
        public ActionResult Index()
        {
            List <Dog> dogs = _dogRepo.GetAllDogs();

            if (dogs == null)
            {
                return(NotFound());
            }

            return(View(dogs));
        }
Exemplo n.º 7
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));
        }
Exemplo n.º 8
0
        public ActionResult Index()
        {
            int ownerId = GetCurrentUserId();

            if (ownerId == 0)
            {
                List <Dog> allDogs = _dogRepo.GetAllDogs();
                return(View(allDogs));
            }
            else
            {
                List <Dog> dogs = _dogRepo.GetDogsByOwnerId(ownerId);
                return(View(dogs));
            }
        }
Exemplo n.º 9
0
        public async Task <IActionResult> RegisterDog(RegisterDogViewModel model, string id)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            ApplicationUser user = await _userManager.FindByIdAsync(id);

            //throw new Exception("Error");
            if (user == null)
            {
                _logger.LogError($"User not found with Id= {id} while trying to register a dog. 404 status code thrown.");
                Response.StatusCode = 404;
                return(View("~/Views/Error/UserNotFound.cshtml"));
            }

            Dog dog = new Dog
            {
                Id          = Guid.NewGuid(),
                IdParent    = id,
                FirstName   = model.FirstName,
                MiddleName  = model.MiddleName,
                LastName    = user.LastName,
                FullName    = model.FirstName + " " + model.MiddleName + " " + user.LastName,
                Description = model.Description,
                FavoriteToy = model.FavoriteToy,
                Breed       = model.Breed
            };

            string uniqueFileName = ProcessUploadedPhoto(model.Photo, dog.Id.ToString());

            dog.PhotoPath = uniqueFileName;

            _dogRepository.Add(dog);

            if (_dogRepository.GetAllDogs().Contains(dog))
            {
                if (_signInManager.IsSignedIn(User) && User.IsInRole("Admin"))
                {
                    return(RedirectToAction("ListUsers", "Administration"));
                }
                await _signInManager.SignInAsync(user, isPersistent : false);

                return(RedirectToAction("ViewDog", "Account", new { dog.Id }));
            }

            return(View(model));
        }
Exemplo n.º 10
0
        // GET: Dogs
        public ActionResult Index()
        {
            List <Dog> dogs = _dogRepo.GetAllDogs();

            return(View(dogs));
        }