Esempio n. 1
0
        public async Task <IActionResult> OnPostAsync(string[] selectedCategories)
        {
            var newPicture = new Picture();

            if (selectedCategories != null)
            {
                newPicture.PictureCategories = new List <PictureCategory>();
                foreach (var cat in selectedCategories)
                {
                    var catToAdd = new PictureCategory
                    {
                        CategoryID = int.Parse(cat)
                    };
                    newPicture.PictureCategories.Add(catToAdd);
                }
            }
            if (await TryUpdateModelAsync <Picture>(
                    newPicture,
                    "Picture",
                    i => i.Title, i => i.Author,
                    i => i.Price, i => i.PublishingDate, i => i.PublisherID))
            {
                _context.Picture.Add(newPicture);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            PopulateAssignedCategoryData(_context, newPicture);
            return(Page());
        }
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(int? id, string[]
     selectedCategories)
 {
     if (id == null)
     {
         return NotFound();
     }
     var pictureToUpdate = await _context.Picture
     .Include(i => i.Publisher)
     .Include(i => i.PictureCategories)
     .ThenInclude(i => i.Category)
     .FirstOrDefaultAsync(s => s.ID == id);
     if (pictureToUpdate == null)
     {
         return NotFound();
     }
     if (await TryUpdateModelAsync<Picture>(
     pictureToUpdate,
     "Picture",
     i => i.Title, i => i.Author,
     i => i.Price, i => i.PublishingDate, i => i.Publisher))
     {
         UpdatePictureCategories(_context, selectedCategories, pictureToUpdate);
         await _context.SaveChangesAsync();
         return RedirectToPage("./Index");
     }
    
     UpdatePictureCategories(_context, selectedCategories, pictureToUpdate);
     PopulateAssignedCategoryData(_context, pictureToUpdate);
     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()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

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

            return(RedirectToPage("./Index"));
        }
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.Publisher.Add(Publisher);
            await _context.SaveChangesAsync();

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

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

            if (Publisher != null)
            {
                _context.Publisher.Remove(Publisher);
                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"));
        }