コード例 #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(CarCategory).State = EntityState.Modified;

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

            return(RedirectToPage("./Index"));
        }
コード例 #2
0
        public async Task <IActionResult> OnPostAsync(int?id, string[] selectedCategories)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var carToUpdate = await _context.Car
                              .Include(i => i.Seller)
                              .Include(i => i.CarCategories)
                              .ThenInclude(i => i.Category)
                              .FirstOrDefaultAsync(s => s.ID == id);

            if (carToUpdate == null)
            {
                return(NotFound());
            }
            if (await TryUpdateModelAsync <Car>(
                    carToUpdate, "Car",
                    i => i.Brand,
                    i => i.Type,
                    i => i.Price,
                    i => i.SellingDate,
                    i => i.Seller))
            {
                UpdateCarCategories(_context, selectedCategories, carToUpdate);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            //Apelam UpdateBookCategories pentru a aplica informatiile din checkboxuri la entitatea Books care //
            UpdateCarCategories(_context, selectedCategories, carToUpdate);
            PopulateAssignedCategoryData(_context, carToUpdate);
            return(Page());
        }
コード例 #3
0
        public async Task <IActionResult> OnPostAsync(string[] selectedCategories)
        {
            var newCar = new Car(); if (selectedCategories != null)

            {
                newCar.CarCategories = new List <CarCategory>();
                foreach (var cat in selectedCategories)
                {
                    var catToAdd = new CarCategory
                    {
                        CategoryID = int.Parse(cat)
                    };
                    newCar.CarCategories.Add(catToAdd);
                }
            }
            if (await TryUpdateModelAsync <Car>(newCar, "Car",
                                                i => i.Brand,
                                                i => i.Type,
                                                i => i.Price,
                                                i => i.SellingDate,
                                                i => i.SellerID))
            {
                _context.Car.Add(newCar);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            PopulateAssignedCategoryData(_context, newCar);
            return(Page());
        }
コード例 #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.CarCategory.Add(CarCategory);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
コード例 #5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

            return(RedirectToPage("./Index"));
        }
コード例 #6
0
        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"));
        }