Example #1
0
        public ActionResult <Note> Post([FromBody] CreateNote createNote)
        {
            var authorizationHeader = Request.Headers["Authorization"];
            var user = BasicAuthenticationHandler.GetUserFrom(authorizationHeader);

            var note = new Note
            {
                Author  = user.Username,
                Content = createNote.Content,
            };

            _database.Add(note);
            _database.SaveChanges();

            return(CreatedAtRoute("GetNoteById", new { noteId = note.Id }, note));
        }
Example #2
0
        public ActionResult <Answer[]> Post([FromBody] SubmitAnswer submitAnswer)
        {
            if (!submitAnswer.IsValid(_secrets))
            {
                return(BadRequest($"{submitAnswer.Solution} is not a valid solution for {submitAnswer.Flag}"));
            }

            var answer = new Answer
            {
                Name = submitAnswer.Name.Trim().ToUpper(),
                Flag = submitAnswer.Flag,
            };

            if (_database.Contains(answer))
            {
                return(Ok(_database.Answers.ToArray()));
            }

            _database.Add(answer);
            _database.SaveChanges();

            return(CreatedAtRoute("GetAnswers", _database.Answers.ToArray()));
        }