Beispiel #1
0
        public HttpResponseMessage DeleteById(int id)
        {
            _opportunity.Delete(id);

            SuccessResponse response = new SuccessResponse();

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Beispiel #2
0
        public IActionResult Delete(Guid Id)
        {
            Opportunity deletedOpportunity = _opportunityService.Delete(Id);

            if (deletedOpportunity != null)
            {
                TempData["message"] = $"{deletedOpportunity.Name} was deleted";
            }
            return(Redirect("Index"));
        }
        public IActionResult Delete(string id)
        {
            try
            {
                _logger.LogInformation($"Trying to delete opportunity record {id}");
                var exists = _opportunitiesService.Get(id);

                OpportunityResponse.Success = false;
                OpportunityResponse.Data    = new();

                if (exists == null)
                {
                    OpportunityResponse.Message = "Opportunity record not found.";
                    return(NotFound(new[] { OpportunityResponse }));
                }

                bool opportunityRemoved = _opportunitiesService.Delete(id);

                if (!opportunityRemoved)
                {
                    OpportunityResponse.Message = "Opportunity record not deleted.";
                    return(BadRequest(new[] { OpportunityResponse }));
                }

                OpportunityResponse.Success = true;
                OpportunityResponse.Message = $"Opportunity record with id {id} deleted.";
                return(Ok(new[] { OpportunityResponse }));
            }
            catch (MongoException ex)
            {
                _logger.LogError($"Error removing from DB: {ex.Message}");
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error: {ex.Message}");
            }
            _logger.LogInformation("Error: delete request cannot be handled, bad request.");
            return(BadRequest());
        }
 public ActionResult DeleteConfirmed(Guid id)
 {
     opportunityService.Delete(id);
     return(RedirectToAction("Index"));
 }