Esempio n. 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"));
        }
        public IActionResult Post([FromBody] TeamCategoryViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var newCategory = new TeamCategory()
                    {
                        Name = model.Name
                    };

                    repository.AddTeamCategory(newCategory);
                    if (repository.SaveAll())
                    {
                        return(Ok("New team category has been saved"));
                    }
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
            return(BadRequest("Failed to save new team category"));
        }
Esempio n. 3
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));
 }