Beispiel #1
0
        public async Task <IActionResult> DeleteDescriptionItem(int id)
        {
            DescriptionGroupItem item = await _shopManager.GetDescriptionItemByIdAsync(id);

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

            var itemDto = _mapper.Map <DescriptionGroupItemDto>(item);

            return(View(itemDto));
        }
Beispiel #2
0
        public async Task <OperationResult> ValidateAsync(IShopManager manager, Description description)
        {
            if (manager == null)
            {
                throw new ArgumentNullException(nameof(manager));
            }
            if (description == null)
            {
                throw new ArgumentNullException(nameof(description));
            }

            var errors = new List <OperationError>();

            if (description.Value.IsNullOrEmpty())
            {
                errors.Add(manager.ErrorDescriber.EmptyDescriptionValue());
            }

            if (!description.DescriptionGroupItemId.HasValue)
            {
                errors.Add(manager.ErrorDescriber.InvalidModel());
            }

            var existingDescItem = await manager.GetDescriptionItemByIdAsync(description.DescriptionGroupItemId.GetValueOrDefault());

            if (existingDescItem == null)
            {
                errors.Add(manager.ErrorDescriber.EntityNotFound("Пункт описания группы"));
            }

            if (errors.Count > 0)
            {
                return(OperationResult.Failure(errors.ToArray()));
            }

            return(OperationResult.Success());
        }