Esempio n. 1
0
        public async Task <ActionResult> OnPostAsync([FromServices] IProductComponentFactory productComponentFactory)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            IProductComponent product = productComponentFactory.New();

            WorkflowResult result = await product.SaveAsync(Product.Description);

            if (!result.Success)
            {
                for (int i = 0; i < result.Errors.Length; i++)
                {
                    ModelState.TryAddModelError("", result.Errors[i]);
                }
                return(Page());
            }

            return(RedirectToPage("./Details", new { id = product.ProductId }));
        }
Esempio n. 2
0
        public async Task <ActionResult> OnPostDeletePriceDetailAsync(
            [FromServices] IProductComponentFactory productComponentFactory,
            int priceDetailId)
        {
            try
            {
                ModelState.Clear();
                if (priceDetailId <= 0)
                {
                    ModelState.TryAddModelError("", "Acción Invalida");
                    return(Page());
                }
                Option <IProductComponent> productResult = await productComponentFactory.CurrentAsync(Id);

                if (!productResult.Any())
                {
                    ModelState.TryAddModelError("", "Error, registro no existe en bd");
                }

                IProductComponent product = productResult.Single();

                WorkflowResult result = await product.DeletePriceDetailAsync(priceDetailId);

                if (!result.Success)
                {
                    for (int i = 0; i < result.Errors.Length; i++)
                    {
                        ModelState.TryAddModelError("", result.Errors[i]);
                    }
                }

                return(Page());
            }
            finally
            {
                AditionalService = new AddAditionalServiceRequest();
                Product          = await _productQueryComponent.ProductAsync(Id);
            }
        }
Esempio n. 3
0
        public async Task <ActionResult> OnPostAditionalServiceAsync([FromServices] IProductComponentFactory productComponentFactory)
        {
            try
            {
                ModelState.Clear();
                if (!TryValidateModel(AditionalService))
                {
                    return(Page());
                }
                Option <IProductComponent> productResult = await productComponentFactory.CurrentAsync(Id);

                if (!productResult.Any())
                {
                    ModelState.TryAddModelError("", "Error, registro no existe en bd");
                }

                IProductComponent product = productResult.Single();

                WorkflowResult result = await product.AddAditionalServiceAsync(AditionalService.Description, AditionalService.UnitPrice);

                if (!result.Success)
                {
                    for (int i = 0; i < result.Errors.Length; i++)
                    {
                        ModelState.TryAddModelError("", result.Errors[i]);
                    }
                }

                return(Page());
            }
            finally
            {
                AditionalService = new AddAditionalServiceRequest();
                Product          = await _productQueryComponent.ProductAsync(Id);
            }
        }