Ejemplo n.º 1
0
        public async Task <IActionResult> ChangeSupplier(ChangeSupplierModel changeSupplierModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            await this.productService.ChangeSupplier(changeSupplierModel);

            return(RedirectToAction("ChangeProductSupplier"));
        }
        public async Task ChangeSupplier(ChangeSupplierModel changeSupplierModel)
        {
            var suppliers = await GetSupplierNames();

            var products = await this.context.Products.Where(x => x.Supplier == suppliers[changeSupplierModel.CurrentSupplierIndex].Name).ToListAsync();

            for (int i = 0; i < products.Count; i++)
            {
                products[i].Supplier = suppliers[changeSupplierModel.NewSupplierIndex].Name;
                this.context.Update(products[i]);
            }
            await this.context.SaveChangesAsync();
        }