コード例 #1
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"));
        }
コード例 #2
0
 public IActionResult Post([FromBody] Article model)
 {
     try
     {
         Console.WriteLine("Article Model State Valid?: " + ModelState.IsValid);
         if (ModelState.IsValid)
         {
             repository.AddEntity(model);
             if (repository.SaveAll())
             {
                 return(Ok("New article has been saved"));
             }
         }
         else
         {
             return(BadRequest(ModelState));
         }
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception);
     }
     return(BadRequest("Failed to save new article: " + ModelState.Values));
 }