Example #1
0
        public async Task AddItemToOrderAsync(AgregarElemento model, string userName)
        {
            var product = await this.context.Products.FindAsync(model.ProductId);

            if (product == null)
            {
                return;
            }

            var DetallesPedidoTemporal = await this.context.DetallesPedidoTemporal
                                         .FirstOrDefaultAsync();

            if (DetallesPedidoTemporal == null)
            {
                DetallesPedidoTemporal = new DetallesPedidoTemporal
                {
                    Precio   = product.Precio,
                    Product  = product,
                    Cantidad = model.Cantidad,
                };

                this.context.DetallesPedidoTemporal.Add(DetallesPedidoTemporal);
            }
            else
            {
                DetallesPedidoTemporal.Cantidad += model.Cantidad;
                this.context.DetallesPedidoTemporal.Update(DetallesPedidoTemporal);
            }

            await this.context.SaveChangesAsync();
        }
Example #2
0
        public IActionResult AddProduct()
        {
            var model = new AgregarElemento
            {
                Cantidad = 1,
                Products = this.repositorioProducto.GetComboProducts()
            };

            return(View(model));
        }
Example #3
0
        public async Task <IActionResult> AddProduct(AgregarElemento model)
        {
            if (this.ModelState.IsValid)
            {
                await this.repositorioPedido.AddItemToOrderAsync(model, this.User.Identity.Name);

                return(this.RedirectToAction("Create"));
            }

            return(this.View(model));
        }