Exemple #1
0
        [ProducesResponseType(500)] //internal server error
        public IActionResult DeleteMerchant(int merchantId)
        {
            if (!_merchantRepository.MerchantExists(merchantId))
            {
                return(NotFound()); //not found
            }
            var merchantToDelete = _merchantRepository.GetMerchant(merchantId);

            //var transactionsToDelete = _userRepository.GetTransactionsByUser(userId);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState)); //bad request
            }
            if (!_merchantRepository.DeleteMerchant(merchantToDelete))
            {
                ModelState.AddModelError("", $"Something went wrong deleting {merchantToDelete.Name}");
                return(StatusCode(500, ModelState)); //internal server error
            }

            // TO DO - Delete Transaction
            //if (!_reviewRepository.DeleteReviews(reviewsToDelete.ToList()))
            //{
            //    ModelState.AddModelError("", $"Something went wrong deleting {reviewerToDelete.FirstName} {reviewerToDelete.LastName}");
            //    return StatusCode(500, ModelState); //internal server error
            //}

            return(NoContent()); //204
        }
        public async Task <Response> Handle(DeleteMerchantCommand request, CancellationToken cancellationToken)
        {
            var deleteMerchantResult = await _merchantRepository.DeleteMerchant(request.UniqueId);

            return(deleteMerchantResult.IsSuccess
                ? new Response(HttpStatusCode.OK)
                : new Response(HttpStatusCode.BadRequest));
        }