Example #1
0
        public async Task <ActionResult <Photo> > Get(int photoId)
        {
            //int applicationUserId = int.Parse(User.Claims.First(i => i.Type == JwtRegisteredClaimNames.NameId).Value);

            var photo = await _photoRespository.GetAsync(photoId);

            return(Ok(photo));
        }
Example #2
0
        public async Task <ActionResult <Blog> > Create(BlogCreate blogCreate)
        {
            int applicationUserId = int.Parse(User.Claims.First(i => i.Type == JwtRegisteredClaimNames.NameId).Value);

            if (blogCreate.PhotoId.HasValue)
            {
                var photo = await _photoRespository.GetAsync(blogCreate.PhotoId.Value);

                if (photo.ApplicationUserId != applicationUserId)
                {
                    return(BadRequest("You did not upload the photo"));
                }
            }

            var blog = await _blogRepository.UpsertAsync(blogCreate, applicationUserId);

            return(Ok(blog));
        }