Beispiel #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Subcategorie,CategorieId,Verantwoordelijke,Verantwoordelijke2")] SubCategorie subCat)
        {
            if (id != subCat.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(subCat);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SubCategorieExists(subCat.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategorieId"] = new SelectList(_context.Categorie, "Id", "Naam", subCat.CategorieId);
            return(View(subCat));
        }
Beispiel #2
0
        public async Task <ActionResult <SubCategorie> > PostSubCategorie(SubCategorie subCategorie)
        {
            _context.SubCategories.Add(subCategorie);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetSubCategorie", new { id = subCategorie.Id }, subCategorie));
        }
Beispiel #3
0
        public async Task <IActionResult> PutSubCategorie(int id, SubCategorie subCategorie)
        {
            if (id != subCategorie.Id)
            {
                return(BadRequest());
            }

            _context.Entry(subCategorie).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SubCategorieExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #4
0
        public void UpdateSubCategorie(SubCategorie subCategorie)
        {
            if (subCategorie == null)
            {
                throw new ArgumentNullException(nameof(subCategorie));
            }

            _context.Entry(subCategorie).State = EntityState.Modified;
        }
Beispiel #5
0
        public void DeleteSubCategorie(SubCategorie subCategorie)
        {
            if (subCategorie == null)
            {
                throw new ArgumentNullException(nameof(subCategorie));
            }

            _context.Remove(subCategorie);
        }
Beispiel #6
0
        public void CreateSubCategorie(SubCategorie subCategorie)
        {
            if (subCategorie == null)
            {
                throw new ArgumentNullException(nameof(subCategorie));
            }

            _context.Add(subCategorie);
        }
Beispiel #7
0
 public ActionResult <SubCategorie> AddSubCategorie([FromBody] SubCategorie subCategorie)
 {
     try
     {
         _repository.CreateSubCategorie(subCategorie);
         _repository.SaveChanges();
         return(CreatedAtAction(nameof(GetSubCategorieById), new SubCategorie {
             Id = subCategorie.Id
         }, subCategorie));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
Beispiel #8
0
        public ActionResult PutSubCategorie(int id, [FromBody] SubCategorie subCategorie)
        {
            try
            {
                if (subCategorie.Id != id)
                {
                    return(NotFound());
                }

                _repository.UpdateSubCategorie(subCategorie);
                _repository.SaveChanges();
                return(Ok());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }