Beispiel #1
0
        public IActionResult Delete(int vehicleId, int id)
        {
            try
            {
                var photo = _photoService.GetPhoto(id);

                if (photo == null)
                {
                    TempData["InfoMessage"] = AppStrings.PhotoNotFoundMsg;
                    return(RedirectToAction("Details", "Vehicle", new { vehicleId }));
                }

                var result = _photoManager.DeleteImageFromDisk(photo.ImageUrl);

                if (result.Success)
                {
                    _photoService.DeletePhoto(id);
                }

                TempData["SuccessMessage"] = AppStrings.PhotoDeleteSuccessMsg;
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex.Message);
                TempData["ErrorMessage"] = AppStrings.PhotoDeleteErrorMsg;
            }

            return(RedirectToAction("Details", "Vehicle", new { id = vehicleId }));
        }