Beispiel #1
0
        public ActionResult DogProfile(int id)
        {
            ViewBag.DogId = id;
            var dog = _dogRepo.GetById(id);

            return(View(DogProfileViewModel.FromDogProfile(dog)));
        }
Beispiel #2
0
        public JsonResult UpdateProfile(DogProfileViewModel DogModel)
        {
            int?dogId = HttpContext.Session.GetInt32("CurrentDog");

            Dog CurrentDog = _context.dogs.Include(d => d.Interests)
                             .ThenInclude(di => di.Interest)
                             .Include(d => d.Humans)
                             .ThenInclude(f => f.Human)
                             .Include(d => d.Animals)
                             .ThenInclude(c => c.Animal).SingleOrDefault(dog => dog.DogId == dogId);

            CurrentDog.Age              = DogModel.Age;
            CurrentDog.BodyType         = DogModel.BodyType;
            CurrentDog.HighestEducation = DogModel.HighestEducation;
            CurrentDog.Barking          = DogModel.Barking;
            CurrentDog.Accidents        = DogModel.Accidents;
            CurrentDog.Breed            = DogModel.Breed;
            CurrentDog.Description      = DogModel.Description;
            foreach (var animal in DogModel.Animals)
            {
                if (CurrentDog.Animals.Where(a => a.Animal_Id == animal).ToList().Count == 0)
                {
                    Cohab newCohab = new Cohab();
                    newCohab.DogId     = CurrentDog.DogId;
                    newCohab.Animal_Id = animal;
                    CurrentDog.Animals.Add(newCohab);
                    _context.Cohabs.Add(newCohab);
                }
            }
            foreach (var human in DogModel.Humans)
            {
                if (CurrentDog.Humans.Where(h => h.HumanId == human).ToList().Count == 0)
                {
                    Family newFamily = new Family();
                    newFamily.DogId   = CurrentDog.DogId;
                    newFamily.HumanId = human;
                    CurrentDog.Humans.Add(newFamily);
                    _context.Families.Add(newFamily);
                }
            }
            foreach (var interest in DogModel.Interests)
            {
                if (CurrentDog.Interests.Where(i => i.InterestId == interest).ToList().Count == 0)
                {
                    DogInterest newInterest = new DogInterest();
                    newInterest.DogId      = CurrentDog.DogId;
                    newInterest.InterestId = interest;
                    CurrentDog.Interests.Add(newInterest);
                    _context.DogInterests.Add(newInterest);
                }
            }
            _context.SaveChanges();
            return(Json(CurrentDog));
        }
Beispiel #3
0
        // GET: DogController/Details/5
        public ActionResult Details(int id)
        {
            Dog dog = _dogRepo.GetDogById(id);

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

            List <Walk>         walks     = _walkRepo.GetWalksByDogId(id);
            DogProfileViewModel viewModel = new DogProfileViewModel
            {
                Dog   = dog,
                Walks = walks.Where(walk => walk.WalkStatusId == 3).ToList()
            };

            return(View(viewModel));
        }
Beispiel #4
0
        // GET: DogsController/Details/5
        public ActionResult Details(int id)
        {
            Dog dog = _dogRepo.GetDogById(id);

            Owner owner = _ownerRepo.GetOwnerById(dog.OwnerId);

            dog.Owner = owner;

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

            DogProfileViewModel vm = new DogProfileViewModel()
            {
                dog = dog
            };

            return(View(vm));
        }
Beispiel #5
0
        // GET: DogController1/Details/5
        public ActionResult Details(int id)
        {
            Dog         dog           = _dogRepo.GetDogById(id);
            List <Walk> walks         = _walkRepo.GetWalksByDogId(id);
            int         currentUserId = GetCurrentUserId();

            if (dog.OwnerId != currentUserId)
            {
                return(NotFound());
            }
            if (dog == null)
            {
                return(NotFound());
            }

            DogProfileViewModel vm = new DogProfileViewModel()
            {
                Dog   = dog,
                Walks = walks
            };

            return(View(vm));
        }