Exemple #1
0
        public async Task <IActionResult> DeleteItemConfirm(int id)
        {
            if (id <= 0)
            {
                return(View("Error", new ErrorViewModel {
                    Message = $"Получены некорректные данные."
                }));
            }

            var item = await _shopManager.GetProductByIdAsync(id, false, false, false);

            if (item == null)
            {
                return(View("Error", new ErrorViewModel {
                    Message = $"Товар с id {id} не найден."
                }));
            }

            var result = await _shopManager.DeleteProductAsync(id);

            if (!result.Succeeded)
            {
                ViewData["message"] = result.Errors?.FirstOrDefault()?.Description;
            }
            else
            {
                ViewData["message"] = "Товар успешно удален.";
            }

            return(View());
        }