예제 #1
0
 public ActionResult Put(int id, [FromBody] CategoryPostDto dto)
 {
     try
     {
         _editCategory.Execute(dto);
         return(NoContent());
     }
     catch (Exception)
     {
         return(StatusCode(500, "An error has occured."));
     }
 }
예제 #2
0
        public void Execute(CategoryPostDto request)
        {
            if (Context.CategoryPosts.Any(c => c.NameCat == request.Name))
            {
                throw new EntityAlreadyExists();
            }

            Context.CategoryPosts.Add(new Domen.CategoryPost {
                NameCat = request.Name
            });
            Context.SaveChanges();
        }
예제 #3
0
 public ActionResult Post([FromBody] CategoryPostDto dto)
 {
     try
     {
         _addCategory.Execute(dto);
         return(StatusCode(201));
     }
     catch (EntityAlreadyExists)
     {
         return(NotFound());
     }
     catch (Exception)
     {
         return(StatusCode(500, "An error has occured."));
     }
 }
예제 #4
0
        public ActionResult Create(CategoryPostDto dto)
        {
            try
            {
                _addCategory.Execute(dto);

                return(RedirectToAction(nameof(Index)));
            }
            catch (EntityNoFound n)
            {
                return(NotFound());
            }
            catch (Exception e)
            {
                TempData["greska"] = "Doslo je do greske.";
            }
            return(View());
        }
예제 #5
0
        public void Execute(CategoryPostDto request)
        {
            var category = Context.CategoryPosts.Find(request.Id);

            if (category == null)
            {
                throw new EntityNoFound();
            }


            if (category.NameCat != request.Name)
            {
                if (Context.CategoryPosts.Any(c => c.NameCat == request.Name))
                {
                    throw new EntityAlreadyExists();
                }

                category.NameCat = request.Name;

                Context.SaveChanges();
            }
        }
예제 #6
0
        public ActionResult Edit(int id, CategoryPostDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(View(dto));
            }

            try
            {
                _editCategory.Execute(dto);
                return(RedirectToAction(nameof(Index)));
            }
            catch (EntityNoFound)
            {
                return(RedirectToAction(nameof(Index)));
            }
            catch (EntityAlreadyExists)
            {
                TempData["error"] = "Kategorija sa istim imenom vec postoji.";
                return(View(dto));
            }
        }
예제 #7
0
        public async Task <IHttpActionResult> PostCategory(CategoryPostDto category)
        {
            var newCategory = await CategoryService.AddAsync(category);

            return(CreatedAtRoute("CategoryRoute", new { id = newCategory.Id }, newCategory));
        }