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 List <Author> Get()
        {
            var authors = AuthorsHelper.GetAllAuthors();

            return(authors);
        }