Пример #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(Seller).State = EntityState.Modified;

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

            return(RedirectToPage("./Index"));
        }
Пример #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 deviceToUpdate = await _context.Device
                                 .Include(i => i.Seller)
                                 .Include(i => i.DeviceCategories)
                                 .ThenInclude(i => i.Category)
                                 .FirstOrDefaultAsync(s => s.ID == id);

            if (deviceToUpdate == null)
            {
                return(NotFound());
            }
            if (await TryUpdateModelAsync <Device>(deviceToUpdate, "Device",
                                                   i => i.Name, i => i.Manufacturer,
                                                   i => i.Price, i => i.ReleaseDate, i => i.Seller))
            {
                UpdateDeviceCategories(_context, selectedCategories, deviceToUpdate);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            UpdateDeviceCategories(_context, selectedCategories, deviceToUpdate);
            PopulateAssignedCategoryData(_context, deviceToUpdate);
            return(Page());
        }
        // 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 newDevice = new Device();

            if (selectedCategories != null)
            {
                newDevice.DeviceCategories = new List <DeviceCategory>();
                foreach (var cat in selectedCategories)
                {
                    var catToAdd = new DeviceCategory
                    {
                        CategoryID = int.Parse(cat)
                    };
                    newDevice.DeviceCategories.Add(catToAdd);
                }
            }
            if (await TryUpdateModelAsync <Device>(newDevice, "Device",
                                                   i => i.Name, i => i.Manufacturer,
                                                   i => i.Price, i => i.ReleaseDate, i => i.SellerID))
            {
                _context.Device.Add(newDevice);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            PopulateAssignedCategoryData(_context, newDevice);
            return(Page());
        }
        // 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.Seller.Add(Seller);
            await _context.SaveChangesAsync();

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

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

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

            return(RedirectToPage("./Index"));
        }
Пример #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"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

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