Ejemplo n.º 1
0
        public async Task <Response> Update(BrandDTO brand)
        {
            Response         response = new Response();
            BrandValidator   validate = new BrandValidator();
            ValidationResult result   = validate.Validate(brand);

            if (!result.IsValid)
            {
                foreach (var failure in result.Errors)
                {
                    response.Errors.Add("Property " + failure.PropertyName + " failed validation. Error was: " + "(" + failure.ErrorMessage + ")");
                }

                return(response);
            }
            else
            {
                try
                {
                    return(response = await _iBrandRepository.Update(brand));
                }
                catch (Exception ex)
                {
                    _log.Error(ex + "\nStackTrace: " + ex.StackTrace);
                    response.Errors.Add("DataBase error, contact the system owner");
                    return(response);
                }
            }
        }
Ejemplo n.º 2
0
        public IResult Add(Brand brand)
        {
            var            context        = new ValidationContext <Brand>(brand);
            BrandValidator brandValidator = new BrandValidator();
            var            result         = brandValidator.Validate(brand);

            if (!result.IsValid)
            {
                throw new ValidationException(result.Errors);
            }

            _brandDal.Add(brand);
            return(new SuccessResult(Messages.BrandAdded));
        }
Ejemplo n.º 3
0
        public void Setup()
        {
            _mockBrandDal = new Mock <IBrandDal>();
            _mockBrands   = new List <Brand>
            {
                new Brand {
                    Id = 1, Name = "Brand1", CreateDate = DateTime.Now, Active = true
                },
                new Brand {
                    Id = 2, Name = "Brand2", CreateDate = DateTime.Now, Active = true
                },
                new Brand {
                    Id = 3, Name = "Brand3", CreateDate = DateTime.Now, Active = true
                }
            };
            _validator = new BrandValidator();

            _mockBrandDal.Setup(m => m.GetAll(null)).Returns(_mockBrands);
        }
Ejemplo n.º 4
0
        public async Task <Response> Update(BrandDTO brand)
        {
            Response         response = new Response();
            BrandValidator   validate = new BrandValidator();
            ValidationResult result   = validate.Validate(brand);

            if (!result.IsValid)
            {
                foreach (var failure in result.Errors)
                {
                    response.Errors.Add("Property " + failure.PropertyName + " failed validation. Error was: " + "(" + failure.ErrorMessage + ")");
                }

                return(response);
            }
            else
            {
                return(await _iBrandRepository.Update(brand));
            }
        }