Ejemplo n.º 1
0
        public async Task <IActionResult> OnGetAsync()
        {
            // Get user from session
            var user = await HttpContext.Session.GetUser();

            // Redirect to login page if user is invalid or user is an admin
            if (user?.Admin_permission != false || user.User_ID == null)
            {
                return(RedirectToPage("/Index"));
            }

            // Store user data in ViewData
            ViewData["name"]         = user.Name;
            ViewData["address"]      = user.Address;
            ViewData["zip code"]     = user.Zip_code;
            ViewData["phone number"] = user.Phone_number;
            ViewData["email"]        = user.Email;

            // Create dictionary for storing dogs and their lessons
            var dogs = new DogData();

            foreach (var dog in await DogRepository.GetDogs(user.User_ID))
            {
                // Add lessons to dog, or empty list if none were found
                var lessons = await LessonRepository.GetLessons(dog.Dog_ID);

                dogs[dog] = lessons?.ToList() ?? new List <Lesson>();
            }

            // Store dogs and their lessons in ViewData
            ViewData["dogs"] = dogs;
            return(Page());
        }
        public void IsRepositoryInitializeWithValidNumberofData()
        {
            var result = Repo.GetDogs();

            Assert.IsNotNull(result);
            var NumberOfRecords = result.ToList().Count;

            Assert.AreEqual(11, NumberOfRecords);
        }
Ejemplo n.º 3
0
 //here we're taking the data we got from the repository and mapping it onto a DTO
 //calls the GetDogs() method we created in the repository
 public IList <DogDTO> GetDogs()
 {
     return((from d in _dRepo.GetDogs()
             select new DogDTO()
     {
         Id = d.Id,
         Age = d.Age,
         Breed = d.Breed,
         Name = d.Name
     }).ToList());
 }
Ejemplo n.º 4
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            // Get user from session
            var user = await HttpContext.Session.GetUser();

            // Redirect to login page if user is invalid or user is a customer
            if (user?.Admin_permission != true)
            {
                return(RedirectToPage("/Index"));
            }
            var customer = await UserRepository.GetUser(id);

            // Add users for searching
            var users = await UserRepository.GetUsers();

            ViewData["user search"] = users;

            // Set hasData and return if no customer was found
            ViewData["hasData"] = customer != null;
            if (customer == null)
            {
                return(Page());
            }

            // Store user data in ViewData
            ViewData["id"]           = customer.User_ID;
            ViewData["name"]         = customer.Name;
            ViewData["address"]      = customer.Address;
            ViewData["zip code"]     = customer.Zip_code;
            ViewData["phone number"] = customer.Phone_number;
            ViewData["email"]        = customer.Email;
            ViewData["note"]         = customer.Note;

            // Filter out courses that have finished
            var courses = await CourseRepository.GetCourses();

            ViewData["courses"] = courses.Where(course => course.Finish_date.CompareTo(DateTime.Today) >= 0);

            // Create dictionary for storing dogs and their courses
            var dogs = new DogData();

            foreach (var dog in await DogRepository.GetDogs(customer.User_ID))
            {
                // Add courses to dog, or empty list if none were found
                var dogCourses = await CourseRepository.GetCourseNames(dog.Dog_ID);

                dogs[dog] = dogCourses?.ToList() ?? new List <string>();
            }

            // Store dogs and their courses in ViewData
            ViewData["dogs"] = dogs;
            return(Page());
        }
Ejemplo n.º 5
0
        private static void Main(string[] args)
        {
            DogRepository repo = new DogRepository();

            repo.SetDog(new Dog(1, (decimal)12.4, (decimal)134.5));
            repo.SetDog(new Dog(2));
            repo.GetDogs();
            repo.GetDog(1);

            string s1 = repo.GetTitle("title", "subtitle", "author") +
                        repo.CountHowMuchYouMustSpendMoneyToBeHappy((decimal)12.4,
                                                                    (decimal)134.5, (decimal)12.4);
            string s2 = repo.GetTitle("title", "subtitle", "author") +
                        repo.CountHowMuchYouMustSpendMoneyToBeFine((decimal)12.4,
                                                                   (decimal)134.5, (decimal)12.4);

            Console.WriteLine(s1 + " vs " + s2);
            Console.ReadKey();
        }
Ejemplo n.º 6
0
        private static List <PetListVM> GetDogs(int pageSize, int page, PetSortBy sortBy)
        {
            var dogModels = _dogRepository.GetDogs(pageSize, page, sortBy, true).ToList();

            List <PetListVM> petVMsToReturn = new List <PetListVM>();

            dogModels.ForEach(d => petVMsToReturn.Add(new PetListVM()
            {
                Id           = d.Id,
                Age          = d.DogAge.ToString(),
                Name         = d.Name,
                Breed        = d.Breed.Name,
                Years        = d.Age,
                DateAdded    = d.Created,
                ThumbnailUrl = d.ThumbnailUrl,
                ImageUrl     = d.ImageUrl,
                OriginUrl    = d.OriginUrl
            }));

            return(petVMsToReturn);
        }
 // GET: Dogs
 public ActionResult Index()
 {
     return(View(db.GetDogs()));
 }
Ejemplo n.º 8
0
 public IActionResult List()
 {
     return(View(dogRepository.GetDogs()));
 }