コード例 #1
0
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var user = await _usersService.GetUser(userId);

            if (!user.Photos.Any(p => p.Id == id))
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _photosService.GetPhoto(id);

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("You can't delete your main photo!"));
            }

            _photosService.DeletePhoto(photoFromRepo);

            if (await _photosService.SaveChangesInContext())
            {
                return(Ok());
            }

            return(BadRequest("Failed to delete the photo!"));
        }
コード例 #2
0
 public JsonResult DeletePhoto(string key, string photoGuid)
 {
     if (!IsKeyForProfile(key))
     {
         throw new HttpException(404, "Photo not found!");
     }
     try {
         var isProfilePhoto = _photosService.DeletePhoto(KatushaProfile.Id, Guid.Parse(photoGuid));
         return(Json(new { isProfilePhoto = isProfilePhoto }));
     }
     catch (Exception ex) {
         throw new HttpException(404, ex.Message);
     }
 }
コード例 #3
0
        public async Task <IActionResult> DeletePhoto(Guid photoId)
        {
            logger.LogInformation($"{nameof(DeletePhoto)}({nameof(photoId)} = '{photoId}')");
            UserId     currentUserId = GetCurrentUserId();
            PhotoModel photo         = await photosService.GetPhoto(photoId, currentUserId);

            if (!UserMayDeletePhoto(photo, currentUserId))
            {
                return(new UnauthorizedResult());
            }

            await photosService.DeletePhoto(photoId);

            return(Ok());
        }
コード例 #4
0
        public async Task <IActionResult> DeletePhoto(int photoId)
        {
            await _service.DeletePhoto(base.GetUserIdFromToken(), photoId);

            return(NoContent());
        }