Beispiel #1
0
        public IActionResult Edit([FromBody] WikiCategoryViewModel model, int id)
        {
            Console.WriteLine("Trying to update wiki category");
            if (!ModelState.IsValid)
            {
                Console.WriteLine("ModelState is not valid");
                return(BadRequest(ModelState));
            }

            var category = repository.GetWikiCategoryById(id);

            if (category != null)
            {
                category.Name             = model.Name;
                category.CategoryUrl      = model.CategoryUrl;
                category.ImageUrl         = model.ImageUrl;
                category.ImagePlaceholder = model.ImagePlaceholder;
                category.ImageName        = model.ImageName;
                category.ImagePath        = model.ImagePath;
                if (repository.SaveAll())
                {
                    return(new OkObjectResult("Successfully saved category inside"));
                }
            }

            Console.WriteLine("Successfully saved category outside");
            return(new OkObjectResult("Successfully saved category outside"));
        }
Beispiel #2
0
        public IActionResult Post([FromBody] WikiCategoryViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var newCategory = new WikiCategory()
                    {
                        Name             = model.Name,
                        CategoryUrl      = model.CategoryUrl,
                        ImageUrl         = model.ImageUrl,
                        ImagePlaceholder = model.ImagePlaceholder,
                        ImageName        = model.ImageName,
                        ImagePath        = model.ImagePath
                    };

                    repository.AddEntity(newCategory);
                    if (repository.SaveAll())
                    {
                        return(Ok("New wiki category has been saved"));
                    }
                    else
                    {
                        return(BadRequest(ModelState));
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
            return(BadRequest("Failed to save new wiki category"));
        }