Exemplo n.º 1
0
 private static T Create <T>(DiscountRequest discuountBase) where T : DiscuountBase, new ()
 {
     return(new T
     {
         Descripcion = discuountBase.Descripcion,
         Vigencia = discuountBase.Vigencia,
         Porcentaje = discuountBase.Porcentaje
     });
 }
Exemplo n.º 2
0
        public async Task <DiscountResult> CreateDiscountAsync(DiscountRequest discountRequest)
        {
            if (discountRequest == null)
            {
                var ex = new ArgumentNullException("request");

                throw ex;
            }

            var availableProduct = await _productRepository.GetById(discountRequest.ProductDescription);

            DiscountResult discountResult = Create <DiscountResult>(discountRequest);

            if (availableProduct != null)
            {
                Id          = Guid.NewGuid().ToString();
                Descripcion = discountRequest.Descripcion;
                Vigencia    = discountRequest.Vigencia;
                Porcentaje  = discountRequest.Porcentaje;
                ProductId   = availableProduct.SKU;
                var result = _discountRepository.Add(this);
                discountResult.Code = DiscountResultCode.Success;
            }
            else
            {
                ProductId           = "";
                discountResult.Code = DiscountResultCode.NoProductAvailable;
            }



            discountResult.Id        = Id;
            discountResult.ProductId = ProductId;

            return(discountResult);
        }