示例#1
0
        public IActionResult OnGet(int id)
        {
            bool isLoggedIn = false;
            bool isAdmin    = false;

            var currentUser = this.User;

            if (currentUser.Identity.IsAuthenticated)
            {
                isLoggedIn = true;

                isAdmin = currentUser.Claims.Any(c => c.Value == StaticConstants.AdminRole);
            }

            ViewData[StaticConstants.LoggedIn] = isLoggedIn.ToString();
            ViewData[StaticConstants.IsAdmin]  = isAdmin.ToString();


            if (!this.User.Identity.IsAuthenticated)
            {
                return(Redirect(StaticConstants.LoginRedirect));
            }

            CreatePetBindingModel pet = context.Pets
                                        .Select(p => new CreatePetBindingModel()
            {
                Id           = p.Id,
                Type         = p.Type,
                Name         = p.Name,
                Age          = p.Age,
                ImageUrl     = p.ImageUrl,
                LocationLost = p.LocationLost,
                TimeLost     = p.TimeLost,
                Gender       = p.Gender,
                Breed        = p.Breed,
                Color        = p.Color,
            })
                                        .FirstOrDefault(p => p.Id == id);

            if (pet == null)
            {
                return(RedirectToAction(StaticConstants.All, StaticConstants.Pets));
            }

            this.Id           = pet.Id;
            this.Type         = pet.Type;
            this.Name         = pet.Name;
            this.Age          = pet.Age;
            this.ImageUrl     = pet.ImageUrl;
            this.LocationLost = pet.LocationLost;
            this.TimeLost     = pet.TimeLost;
            this.Gender       = pet.Gender;
            this.Breed        = pet.Breed;
            this.Color        = pet.Color;

            ViewData[StaticConstants.PetExists] = false;

            return(Page());
        }
示例#2
0
        public IActionResult OnGet(int id)
        {
            if (!this.User.Identity.IsAuthenticated)
            {
                return(Redirect(StaticConstants.LoginRedirect));
            }

            CreatePetBindingModel pet = context.Pets
                                        .Select(p => new CreatePetBindingModel()
            {
                Id           = p.Id,
                Type         = p.Type,
                Name         = p.Name,
                Age          = p.Age,
                ImageUrl     = p.ImageUrl,
                LocationLost = p.LocationLost,
                TimeLost     = p.TimeLost,
                Gender       = p.Gender,
                Breed        = p.Breed,
                Color        = p.Color,
            })
                                        .FirstOrDefault(p => p.Id == id);

            if (pet == null)
            {
                return(RedirectToAction(StaticConstants.All, StaticConstants.Pets));
            }

            this.Id           = pet.Id;
            this.Type         = pet.Type;
            this.Name         = pet.Name;
            this.Age          = pet.Age;
            this.ImageUrl     = pet.ImageUrl;
            this.LocationLost = pet.LocationLost;
            this.TimeLost     = pet.TimeLost;
            this.Gender       = pet.Gender;
            this.Breed        = pet.Breed;
            this.Color        = pet.Color;


            ViewData[StaticConstants.PetExists] = false;
            return(Page());
        }