Ejemplo n.º 1
0
        public IActionResult Delete(Guid id, IFormCollection collection)
        {
            var coach = _repository.GetElementById(id);

            try
            {
                // TODO: Add delete logic here
                _repository.Delete(id);

                return(RedirectToAction(nameof(Index)).WithSuccess("Supprimer", "vous avez supprimé avec succès "));;
            }

            catch (DbUpdateException ex)
            {
                //Log the exception to a file. We discussed logging to a file
                // using Nlog in Part 63 of ASP.NET Core tutorial
                logger.LogError($"Exception Occured : {ex}");
                // Pass the ErrorTitle and ErrorMessage that you want to show to
                // the user using ViewBag. The Error view retrieves this data
                // from the ViewBag and displays to the user.
                ViewBag.ErrorTitle   = $" Le coach \"{coach.First_Name+" "+coach.Last_Name}\" est en cours d'utilisation";
                ViewBag.ErrorMessage = $"Le coach  {coach.First_Name + " " + coach.Last_Name} ne peut pas être supprimé car il y a des activités dans ce coach. Si vous souhaitez supprimer ce coach, veuillez supprimer les activités du coach, puis essayez de supprimer";
                return(View("Error"));
            }
        }