Exemple #1
0
        public async Task <Dal.Entities.Product> AddProduct(Dal.Entities.Product product)
        {
            Guard.Argument(product, nameof(product)).NotNull();

            await ValidateProduct(product);

            _unitOfWork.ProductRepository.Insert(product);
            await _unitOfWork.SaveChanges();

            return(product);
        }
 public static ProductOutputModel ToOutputModel(this Dal.Entities.Product input)
 {
     return(new ProductOutputModel
     {
         Name = input.Name,
         Description = input.Description,
         Category = input.Category,
         Price = input.Price,
         AddedOn = DateTime.Now,
         StoreName = input.Store?.StoreName
     });
 }
Exemple #3
0
        public async Task <Dal.Entities.Product> UpdateProduct(Dal.Entities.Product product)
        {
            Guard.Argument(product, nameof(Product)).NotNull();

            await ValidateProduct(product);

            var currentProduct = await GetProductById(product.Id);

            var mapper = ServiceMapper.GetMapper();

            mapper.Map(product, currentProduct);

            await _unitOfWork.SaveChanges();

            return(currentProduct);
        }
Exemple #4
0
        private async Task ValidateProduct(Dal.Entities.Product product)
        {
            var productValidator = new ProductValidator();
            var validateResult   = await productValidator.ValidateAsync(product);

            if (validateResult.IsValid)
            {
                return;
            }

            throw new ServiceException(validateResult.Errors.Select(e => new ErrorMessage()
            {
                Code = ErrorCodes.Model_Validation_Error_Code,
                Meta = new
                {
                    e.ErrorCode,
                    e.ErrorMessage,
                    e.PropertyName
                },
                Message = e.ErrorMessage
            }).ToArray());
        }
Exemple #5
0
 public bool IsActiveProduct(Dal.Entities.Product product)
 {
     return(product.Active);
 }