예제 #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(int?id, string[] selectedCategories)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var telefonToUpdate = await _context.Telefon
                                  .Include(i => i.Producator)
                                  .Include(i => i.TelefonCategories)
                                  .ThenInclude(i => i.Category)
                                  .FirstOrDefaultAsync(s => s.ID == id);

            if (telefonToUpdate == null)
            {
                return(NotFound());
            }
            if (await TryUpdateModelAsync <Telefon>(
                    telefonToUpdate,
                    "Telefon",
                    i => i.Model, i => i.ProducatorID,
                    i => i.Memorie, i => i.Pret))
            {
                UpdateTelefonCategories(_context, selectedCategories, telefonToUpdate);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            //Apelam UpdateBookCategories pentru a aplica informatiile din checkboxuri la entitatea Books care
            //este editata
            UpdateTelefonCategories(_context, selectedCategories, telefonToUpdate);
            PopulateAssignedCategoryData(_context, telefonToUpdate);
            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.Attach(Category).State = EntityState.Modified;

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

            return(RedirectToPage("./Index"));
        }
예제 #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(string[] selectedCategories)
        {
            var newTelefon = new Telefon();

            if (selectedCategories != null)
            {
                newTelefon.TelefonCategories = new List <TelefonCategory>();
                foreach (var cat in selectedCategories)
                {
                    var catToAdd = new TelefonCategory
                    {
                        CategoryID = int.Parse(cat)
                    };
                    newTelefon.TelefonCategories.Add(catToAdd);
                }
            }
            if (await TryUpdateModelAsync <Telefon>(
                    newTelefon,
                    "Telefon",
                    i => i.Model, i => i.ProducatorID,
                    i => i.Memorie, i => i.Pret))
            {
                _context.Telefon.Add(newTelefon);
                await _context.SaveChangesAsync();

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

            return(RedirectToPage("./Index"));
        }
        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"));
        }
예제 #6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

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

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

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

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