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

            // get user from repo
            var user = await _repo.GetUser(userId);

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

            var photoFromRepo = await _repo.GetPhoto(id);

            //check if the picture the user is trying to delete is the main picture
            if (photoFromRepo.IsMain)
            {
                return(BadRequest("Unable to delete main picture"));
            }

            if (photoFromRepo.PublicId != null)
            {
                //from CLoudinary documentation to delete an image
                var deleteParams = new DeletionParams(photoFromRepo.PublicId);

                var result = _cloudinary.Destroy(deleteParams);

                if (result.Result == "ok")
                {
                    _repo.Delete(photoFromRepo);
                }
            }

            if (photoFromRepo.PublicId == null)
            {
                _repo.Delete(photoFromRepo);
            }

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

            return(BadRequest("Failed to delete photo"));
        }
コード例 #2
0
        public async Task <IActionResult> DeleteMessage(int id, int userId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var messageFromRepo = await _repo.GetMessage(id);

            if (messageFromRepo.SenderId == userId)
            {
                messageFromRepo.SenderDeleted = true;
            }

            if (messageFromRepo.RecipientId == userId)
            {
                messageFromRepo.RecipientDeleted = true;
            }

            if (messageFromRepo.SenderDeleted && messageFromRepo.RecipientDeleted)
            {
                _repo.Delete(messageFromRepo);
            }

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception("Error deleting the message");
        }
コード例 #3
0
        public async Task Delete(string alias)
        {
            var log = GetLog(alias);

            await translationRepository.Delete(alias);

            logRepository.Save(log);
        }
コード例 #4
0
 public void Delete(int id)
 {
     _TranslationRepository.Delete(id);
 }
コード例 #5
0
 public ActionResult Delete(int id, FormCollection form)
 {
     db.Delete(id);
     return(RedirectToAction("Index"));
 }
コード例 #6
0
        public async Task DeleteAsync(string languageKey, string projectKey, string key)
        {
            await _repository.Delete(languageKey, projectKey, key);

            _cache.Clear(languageKey, projectKey);
        }