Ejemplo n.º 1
0
        public async Task <IActionResult> DeleteDescriptionGroup(int id)
        {
            var descGroup = await _shopManager.GetDescriptionGroupByIdAsync(id);

            if (descGroup == null)
            {
                return(View("Error", new ErrorViewModel {
                    Message = $"Категория с id {id} не найдена."
                }));
            }

            var descGroupDto = _mapper.Map <DescriptionGroupDto>(descGroup);

            return(View(descGroupDto));
        }
Ejemplo n.º 2
0
        public async Task <OperationResult> ValidateAsync(IShopManager manager, DescriptionGroupItem entity)
        {
            if (manager == null)
            {
                throw new ArgumentNullException(nameof(manager));
            }
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var errors = new List <OperationError>();

            if (entity.Name.IsNullOrEmpty())
            {
                errors.Add(manager.ErrorDescriber.EmptyDescriptionGroupItemName());
            }
            else
            {
                var existing = await manager.GetDescriptionItemByNameAsync(entity.Name);

                if (existing != null && existing?.Id != entity.Id && existing.DescriptionGroupId == entity.DescriptionGroupId)
                {
                    errors.Add(manager.ErrorDescriber.DuplicateDescriptionGroupItemName());
                }
            }

            var descGroup = await manager.GetDescriptionGroupByIdAsync(entity.DescriptionGroupId.GetValueOrDefault());

            if (descGroup == null)
            {
                errors.Add(manager.ErrorDescriber.EntityNotFound("Группа описаний"));
            }

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

            return(OperationResult.Success());
        }