public ActionResult Post([FromBody] Author author) { StringValues admin = "admin"; if (Request.Headers.ContainsKey("Authorization") && Request.Headers.TryGetValue("Authorization", out admin)) { var allAuthors = AuthorsHelper.GetAllAuthors(); if (ModelState.IsValid && author != null) { if (allAuthors.Any(a => a.UserID == author.UserID)) { throw new Exception(); } AuthorsHelper.AddNewAuthor(author); return(RedirectToAction("api/authors")); } else { return(Content("Something bad happened :)")); } } else { return(Content("Not authorized for this action :)")); } }
public BooksController( BooksRepository booksRepository, AuthorsRepository authorsRepository, AuthorsHelper authorsHelper) { this.booksRepository = booksRepository; this.authorsHelper = authorsHelper; this.authorsRepository = authorsRepository; }
public ActionResult Put(int id, int aid, [FromBody] Article article) { StringValues admin = "admin"; if (Request.Headers.ContainsKey("Authorization") && Request.Headers.TryGetValue("Authorization", out admin)) { AuthorsHelper.UpdateArticle(id, article, aid); return(RedirectToAction("GetArticlesByAuthor")); } else { return(Content("Not authorized for this action :)")); } }
//[HttpGet("{id}/articles", Name = "Author_articles")] public List <Article> GetArticlesByAuthor(int id, string title = "", string level = "", string publishedDate = "") { var article = AuthorsHelper.GetAllArticles(id, title, level, publishedDate); return(article); }
public Author Get(int id) { var author = AuthorsHelper.GetAuthorById(id); return(author); }
public List <Author> Get() { var authors = AuthorsHelper.GetAllAuthors(); return(authors); }