Example #1
0
        public IActionResult POST([FromBody] ComicUser newUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            IQueryable <ComicUser> checkForUserEmail = _context.Reader.Where(user => user.Email == newUser.Email);

            ComicUser userExists      = checkForUserEmail.FirstOrDefault();
            string    createdLocation = "http://localhost:5000/api/User?=";

            if (userExists != null)
            {
                // should actually return "Already Created", but I want it to return the user from the DB either way.
                createdLocation += userExists.ComicUserId;
                return(Created(createdLocation, userExists));
            }

            _context.Reader.Add(newUser);

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateException)
            {
                return(new StatusCodeResult(StatusCodes.Status418ImATeapot));
            }

            createdLocation += newUser.ComicUserId;
            return(Created(createdLocation, newUser));
        }
        public IActionResult POST([FromBody] ComicStrip newComicStrip)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Strip.Add(newComicStrip);

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateException)
            {
                return(new StatusCodeResult(StatusCodes.Status418ImATeapot));
            }

            // research this more
            string createdLocation = "http://localhost:5000/api/ComicStrip?stripId=" + newComicStrip.ComicStripId;

            return(Created(createdLocation, newComicStrip));
        }
Example #3
0
        public IActionResult POST([FromBody] ComicStripComment newComment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Comment.Add(newComment);

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateException)
            {
                return(new StatusCodeResult(StatusCodes.Status418ImATeapot));
            }

            string createdLocation = "http://localhost:5000/api/Emotion?commentId=" + newComment.ComicStripCommentId;

            return(Created(createdLocation, newComment));
        }