public HttpResponseMessage Delete(HttpRequestMessage request, int id)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var trainerDb = _trainerService.Get(id);
                    if (trainerDb == null)
                    {
                        response = request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid Id.");
                    }
                    else
                    {
                        _trainerService.Delete(trainerDb);

                        _trainerService.Save();

                        response = request.CreateResponse(HttpStatusCode.OK, true);
                    }
                }

                return response;
            }));
        }
Exemple #2
0
 public IActionResult TrainerDelete(Trainer trainer)
 {
     _trainerService.Delete(trainer);
     return(RedirectToAction("Trainer"));
 }
        public async Task <IActionResult> Delete(Guid id, CancellationToken cancellationToken = default)
        {
            await _trainerService.Delete(id, cancellationToken);

            return(Accepted());
        }
Exemple #4
0
 public IActionResult DeleteConfirmed(Guid id)
 {
     _trainerService.Delete(id);
     return(RedirectToAction(nameof(Index)));
 }