Ejemplo n.º 1
0
        public async Task <ActionResult> Delete(int?id, TypeOfPacking tag)
        {
            if (id == null)
            {
                return(NotFound());
            }
            if (id != tag.Id)
            {
                return(NotFound());
            }
            var tagToDelete = _db.Tags.FirstOrDefault(x => x.Id == id);

            if (tagToDelete == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _db.Tags.Remove(tagToDelete);
                await _db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(tagToDelete));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Edit(TypeOfPacking tag)
        {
            if (ModelState.IsValid)
            {
                _db.Update(tag);
                await _db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tag));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Create(TypeOfPacking tag)
        {
            if (ModelState.IsValid)
            {
                _db.Tags.Add(tag);
                await _db.SaveChangesAsync();

                TempData["Save"] = "Nazwa została dodana";
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tag));
        }