예제 #1
0
        public async Task <IActionResult> PostTwitterUsers([FromBody] TwitterUsers twitterUsers)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            twitterUsers.DateCreated = DateTime.UtcNow;

            var twitterLogic = new TwitterLogic(Configuration);

            var userInfo = twitterLogic.GetTwitterUserInfo(twitterUsers);

            twitterUsers.Image = userInfo.ProfileImageUrlFullSize;

            _context.TwitterUsers.Add(twitterUsers);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTwitterUsers", new { id = twitterUsers.TwitterUserId }, twitterUsers));
        }
예제 #2
0
        public async Task <IActionResult> PutTwitterUsers([FromRoute] int id, [FromBody] TwitterUsers twitterUsers)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            if (id != twitterUsers.TwitterUserId)
            {
                return(BadRequest());
            }

            var twitterLogic = new TwitterLogic(Configuration);

            var userInfo = twitterLogic.GetTwitterUserInfo(twitterUsers);

            twitterUsers.Image = userInfo.ProfileImageUrlFullSize;

            _context.Entry(twitterUsers).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TwitterUsersExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }