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

            var dbUser = await _repository.GetUser(userId, true);

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

            var dbPhoto = await _repository.GetPhoto(photoId);

            if (dbPhoto.IsProfilePhoto)
            {
                return(BadRequest("Profile photo can't be deleted."));
            }

            if (dbPhoto.PublicId != null)
            {
                var deleteParams = new DeletionParams(dbPhoto.PublicId);

                var deleteResult = _cloudinary.Destroy(deleteParams);

                if (deleteResult.Result == "ok")
                {
                    _repository.Delete(dbPhoto);
                }
            }
            else
            {
                _repository.Delete(dbPhoto);
            }

            if (await _repository.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to delete the photo"));
        }
コード例 #3
0
        public ApplicationEvent[] Handle(DeleteNetwork command)
        {
            _repository.Delete(command.NetworkIdentity);

            return(new ApplicationEvent[] { new NetworkDeleted(command.NetworkIdentity) });
        }