Esempio n. 1
0
        public ActionResult Cat(Guid catId)
        {
            Cat selectedCat = Cats.Single(item => item.Id == catId);
            CatDetailsViewModel catViewModel = new CatDetailsViewModel()
            {
                Description = selectedCat.Description,
                ImageUrl    = selectedCat.ImageUrl,
                Title       = selectedCat.Title
            };

            return(View("~/Views/Cats/Cat.cshtml", catViewModel)); /* Explicitly specified view. It would work without the first string parameter, too!*/
        }
        public CatDetailsViewModel CatInfo(string catId)
        {
            CatDetailsViewModel result = _db.Cats.Where(cat => cat.Id == int.Parse(catId)).Select(cat => new CatDetailsViewModel
            {
                Name  = cat.Name,
                Image = cat.Image,
                Age   = cat.Age,
                Breed = cat.Breed
            })
                                         .FirstOrDefault();

            return(result);
        }
Esempio n. 3
0
        public IActionResult Details(int id)
        {
            var Cat = this.dbContext.Cats.FirstOrDefault(c => c.Id == id);

            var viewModel = new CatDetailsViewModel
            {
                Name     = Cat.Name,
                Age      = Cat.Age,
                Breed    = Cat.Breed,
                ImageUrl = Cat.ImageUrl
            };

            return(View(viewModel));
        }
Esempio n. 4
0
        public IActionResult Details(int id)
        {
            var cat = this.catsService.GetCatById(id);

            var model = new CatDetailsViewModel
            {
                Name     = cat.Name,
                Age      = cat.Age,
                ImageURL = cat.ImageURL,
                Breed    = cat.Breed
            };

            return(this.View(model));
        }
        public IActionResult Details(int Id)
        {
            var cat = this.dbContext.Cats.FirstOrDefault(c => c.Id == Id);

            var model = new CatDetailsViewModel()
            {
                Name     = cat.Name,
                Age      = cat.Age,
                Breed    = cat.Breed,
                ImageUrl = cat.ImageUrl
            };

            return(View(model));
        }
Esempio n. 6
0
        public async Task <string> GetCat(string id)
        {
            var cat = await this.db.Cats.FirstOrDefaultAsync(c => c.CatId == id);

            if (cat == null)
            {
                throw new ArgumentException("There is no cat with given id!");
            }

            var model = new CatDetailsViewModel()
            {
                CatId        = cat.CatId,
                Name         = cat.Name,
                Age          = cat.Age,
                Birthday     = (DateTime)cat.Birthday,
                Gender       = cat.Gender.ToString(),
                Breed        = cat.Breed.ToString(),
                Color        = cat.Color.ToString(),
                ProfileImage = cat.ProfileImage,
            };

            if (!string.IsNullOrEmpty(cat.FatherId))
            {
                var father = await this.db.Cats.FirstOrDefaultAsync(c => c.CatId == cat.FatherId);

                model.Father = new ParentPartialViewModel()
                {
                    CatId        = father.CatId,
                    Name         = father.Name,
                    ProfileImage = father.ProfileImage,
                };
            }

            if (!string.IsNullOrEmpty(cat.MotherId))
            {
                var mother = await this.db.Cats.FirstOrDefaultAsync(c => c.CatId == cat.MotherId);

                model.Mother = new ParentPartialViewModel()
                {
                    CatId        = mother.CatId,
                    Name         = mother.Name,
                    ProfileImage = mother.ProfileImage,
                };
            }

            var json = JsonConvert.SerializeObject(model);

            return(json);
        }
Esempio n. 7
0
        public CatDetailsViewModel GetById(string id)
        {
            var cat = this.dbContext.Cats.FirstOrDefault(x => x.Id == id);

            if (cat == null)
            {
                throw new Exception("No cat with such ID in DB");
            }

            var result = new CatDetailsViewModel();

            result.Age      = cat.Age;
            result.Breed    = cat.Breed;
            result.ImageUrl = cat.ImageUrl;
            result.Name     = cat.Name;

            return(result);
        }
Esempio n. 8
0
        public IActionResult Details(string id)
        {
            var cat = this._context.Cats.Find(id);

            if (cat == null)
            {
                return(NotFound());
            }
            var catModel = new CatDetailsViewModel()
            {
                Name     = cat.Name,
                Age      = cat.Age,
                Breed    = cat.Breed,
                ImageUrl = cat.ImageUrl
            };

            return(View(catModel));
        }
Esempio n. 9
0
        public IActionResult Details(int id)
        {
            var cat = context.Cats.Find(id);

            if (cat != null)
            {
                var model = new CatDetailsViewModel()
                {
                    Name     = cat.Name,
                    Breed    = cat.Breed,
                    ImageUrl = cat.ImageUrl
                };

                return(this.View(model));
            }

            return(NotFound());
        }
        public IActionResult Details(int id) // ?? to Rout cats/id, not /cats/Details/id ???
        {
            var cat = this.Context.Cats.Find(id);

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

            var catModel = new CatDetailsViewModel() // When we return not Cat from DB, but ViewModel!
            {
                Name     = cat.Name,
                Age      = cat.Age,
                Breed    = cat.Breed,
                ImageUrl = cat.ImageUrl
            };

            return(View(model: catModel)); // or return View(catModel);
        }
Esempio n. 11
0
        public IActionResult Details(int id)
        {
            CatDetailsViewModel model;

            using (this.dbContext)
            {
                var cat = this.dbContext.Cats.Find(id);

                model = new CatDetailsViewModel()
                {
                    Name     = cat.Name,
                    Age      = cat.Age,
                    Breed    = cat.Breed,
                    ImageUrl = cat.ImageUrl
                };
            }

            return(View(model));
        }
Esempio n. 12
0
        public IActionResult Details(int id)
        {
            var cat = this.Context
                      .Cats
                      .FirstOrDefault(c => c.Id == id);

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

            var catModel = new CatDetailsViewModel
            {
                Name     = cat.Name,
                Age      = cat.Age,
                Breed    = cat.Breed,
                ImageUrl = cat.ImageUrl
            };

            return(View(catModel));
        }
        public IActionResult Details(int id)
        {
            var cat = this.db.Cats
                      .Include(c => c.Breed)
                      .FirstOrDefault(c => c.Id == id);

            if (cat == null)
            {
                return(NotFound(id));
            }

            var model = new CatDetailsViewModel
            {
                Id       = cat.Id,
                Breed    = cat.Breed.Name,
                Age      = cat.Age,
                Name     = cat.Name,
                ImageUrl = cat.ImageUrl
            };

            return(View(model));
        }
Esempio n. 14
0
        public IActionResult Details(string catId)
        {
            CatDetailsViewModel model = _detailsServices.CatInfo(catId);

            return(this.View(model));
        }