Example #1
0
        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 :)"));
            }
        }
Example #2
0
 public BooksController(
     BooksRepository booksRepository,
     AuthorsRepository authorsRepository,
     AuthorsHelper authorsHelper)
 {
     this.booksRepository   = booksRepository;
     this.authorsHelper     = authorsHelper;
     this.authorsRepository = authorsRepository;
 }
Example #3
0
        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 :)"));
            }
        }
Example #4
0
        //[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);
        }
Example #5
0
        public Author Get(int id)
        {
            var author = AuthorsHelper.GetAuthorById(id);

            return(author);
        }
Example #6
0
        public List <Author> Get()
        {
            var authors = AuthorsHelper.GetAllAuthors();

            return(authors);
        }