Esempio n. 1
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Location).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LocationExists(Location.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(string [] selectedCategories)
        {
            var newPet = new Pet();

            if (selectedCategories != null)
            {
                newPet.PetCategories = new List <PetCategory>();
                foreach (var cat in selectedCategories)
                {
                    var catToAdd = new PetCategory
                    {
                        CategoryID = int.Parse(cat)
                    };
                    newPet.PetCategories.Add(catToAdd);
                }
            }
            if (await TryUpdateModelAsync <Pet>(
                    newPet,
                    "Pet",
                    i => i.Name, i => i.Breed, i => i.Age, i => i.AvailableDate, i => i.LocationID, i => i.Photo))
            {
                _context.Pet.Add(newPet);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            PopulateAssignedCategoryData(_context, newPet);
            return(Page());
        }
Esempio n. 3
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(int?id, string [] selectedCategories)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var petToUpdate = await _context.Pet
                              .Include(i => i.Location)
                              .Include(i => i.PetCategories)
                              .ThenInclude(i => i.Category)
                              .FirstOrDefaultAsync(s => s.ID == id);

            if (petToUpdate == null)
            {
                return(NotFound());
            }
            if (await TryUpdateModelAsync <Pet>(
                    petToUpdate,
                    "Pet",
                    i => i.Photo,
                    i => i.Name, i => i.Breed,
                    i => i.Age, i => i.AvailableDate, i => i.Location))
            {
                UpdatePetCategories(_context, selectedCategories, petToUpdate);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            //Apelam UpdateBookCategories pentru a aplica informatiile din checkboxuri la entitatea Books care
            //este editata
            UpdatePetCategories(_context, selectedCategories, petToUpdate);
            PopulateAssignedCategoryData(_context, petToUpdate);
            return(Page());
        }
Esempio n. 4
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Category.Add(Category);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Esempio n. 5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Location = await _context.Location.FindAsync(id);

            if (Location != null)
            {
                _context.Location.Remove(Location);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Category = await _context.Category.FindAsync(id);

            if (Category != null)
            {
                _context.Category.Remove(Category);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }