public async Task <IActionResult> Edit(string id, [Bind("CountryRegionCode,CurrencyCode,ModifiedDate")] CountryRegionCurrency countryRegionCurrency)
        {
            if (id != countryRegionCurrency.CountryRegionCode)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(countryRegionCurrency);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CountryRegionCurrencyExists(countryRegionCurrency.CountryRegionCode))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryRegionCode"] = new SelectList(_context.CountryRegion, "CountryRegionCode", "CountryRegionCode", countryRegionCurrency.CountryRegionCode);
            ViewData["CurrencyCode"]      = new SelectList(_context.Currency, "CurrencyCode", "CurrencyCode", countryRegionCurrency.CurrencyCode);
            return(View(countryRegionCurrency));
        }
        public async Task <IActionResult> Edit(int id, [Bind("BusinessEntityId,Rowguid,ModifiedDate")] BusinessEntity businessEntity)
        {
            if (id != businessEntity.BusinessEntityId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(businessEntity);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BusinessEntityExists(businessEntity.BusinessEntityId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(businessEntity));
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id, [Bind("CustomerId,NameStyle,Title,FirstName,MiddleName,LastName,Suffix,CompanyName,SalesPerson,EmailAddress,Phone,PasswordHash,PasswordSalt,Rowguid,ModifiedDate")] Customer customer)
        {
            if (id != customer.CustomerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerExists(customer.CustomerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Esempio n. 4
0
        public async Task <IActionResult> Edit(int id, [Bind("TerritoryId,Name,CountryRegionCode,Group,SalesYtd,SalesLastYear,CostYtd,CostLastYear,Rowguid,ModifiedDate")] SalesTerritory salesTerritory)
        {
            if (id != salesTerritory.TerritoryId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(salesTerritory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SalesTerritoryExists(salesTerritory.TerritoryId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryRegionCode"] = new SelectList(_context.CountryRegion, "CountryRegionCode", "CountryRegionCode", salesTerritory.CountryRegionCode);
            return(View(salesTerritory));
        }
Esempio n. 5
0
        public async Task <IActionResult> Edit(int id, [Bind("AddressId,AddressLine1,AddressLine2,City,StateProvinceId,PostalCode,Rowguid,ModifiedDate")] Address address)
        {
            if (id != address.AddressId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(address);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AddressExists(address.AddressId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StateProvinceId"] = new SelectList(_context.StateProvince, "StateProvinceId", "CountryRegionCode", address.StateProvinceId);
            return(View(address));
        }
        public async Task <IActionResult> Edit(short id, [Bind("DepartmentId,Name,GroupName,ModifiedDate")] Department department)
        {
            if (id != department.DepartmentId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(department);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DepartmentExists(department.DepartmentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(department));
        }
        public async Task <IActionResult> Edit(int id, [Bind("CustomerId,PersonId,StoreId,TerritoryId,AccountNumber,Rowguid,ModifiedDate")] Customer customer)
        {
            if (id != customer.CustomerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerExists(customer.CustomerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PersonId"]    = new SelectList(_context.Person, "BusinessEntityId", "FirstName", customer.PersonId);
            ViewData["StoreId"]     = new SelectList(_context.Store, "BusinessEntityId", "Name", customer.StoreId);
            ViewData["TerritoryId"] = new SelectList(_context.SalesTerritory, "TerritoryId", "CountryRegionCode", customer.TerritoryId);
            return(View(customer));
        }
Esempio n. 8
0
        public async Task <IActionResult> Edit(int id, [Bind("DatabaseLogId,PostTime,DatabaseUser,Event,Schema,Object,Tsql,XmlEvent")] DatabaseLog databaseLog)
        {
            if (id != databaseLog.DatabaseLogId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(databaseLog);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DatabaseLogExists(databaseLog.DatabaseLogId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(databaseLog));
        }
Esempio n. 9
0
        public async Task <IActionResult> Edit(int id, [Bind("BusinessEntityId,PersonId,ContactTypeId,Rowguid,ModifiedDate")] BusinessEntityContact businessEntityContact)
        {
            if (id != businessEntityContact.BusinessEntityId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(businessEntityContact);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BusinessEntityContactExists(businessEntityContact.BusinessEntityId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BusinessEntityId"] = new SelectList(_context.BusinessEntity, "BusinessEntityId", "BusinessEntityId", businessEntityContact.BusinessEntityId);
            ViewData["ContactTypeId"]    = new SelectList(_context.ContactType, "ContactTypeId", "Name", businessEntityContact.ContactTypeId);
            ViewData["PersonId"]         = new SelectList(_context.Person, "BusinessEntityId", "FirstName", businessEntityContact.PersonId);
            return(View(businessEntityContact));
        }
Esempio n. 10
0
        public async Task <IActionResult> Edit(int id, [Bind("BusinessEntityId,NationalIdnumber,LoginId,OrganizationLevel,JobTitle,BirthDate,MaritalStatus,Gender,HireDate,SalariedFlag,VacationHours,SickLeaveHours,CurrentFlag,Rowguid,ModifiedDate")] Employee employee)
        {
            if (id != employee.BusinessEntityId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(employee);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeeExists(employee.BusinessEntityId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BusinessEntityId"] = new SelectList(_context.People, "BusinessEntityId", "FirstName", employee.BusinessEntityId);
            return(View(employee));
        }
        public async Task <IActionResult> Edit(int id, [Bind("StateProvinceId,StateProvinceCode,CountryRegionCode,IsOnlyStateProvinceFlag,Name,TerritoryId,Rowguid,ModifiedDate")] StateProvince stateProvince)
        {
            if (id != stateProvince.StateProvinceId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(stateProvince);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StateProvinceExists(stateProvince.StateProvinceId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryRegionCode"] = new SelectList(_context.CountryRegion, "CountryRegionCode", "CountryRegionCode", stateProvince.CountryRegionCode);
            ViewData["TerritoryId"]       = new SelectList(_context.SalesTerritory, "TerritoryId", "CountryRegionCode", stateProvince.TerritoryId);
            return(View(stateProvince));
        }
Esempio n. 12
0
        public async Task <IActionResult> Edit(byte id, [Bind("SystemInformationId,DatabaseVersion,VersionDate,ModifiedDate")] AwbuildVersion awbuildVersion)
        {
            if (id != awbuildVersion.SystemInformationId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(awbuildVersion);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AwbuildVersionExists(awbuildVersion.SystemInformationId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(awbuildVersion));
        }
Esempio n. 13
0
        public async Task <IActionResult> Edit(int id, [Bind("ProductId,Name,ProductNumber,MakeFlag,FinishedGoodsFlag,Color,SafetyStockLevel,ReorderPoint,StandardCost,ListPrice,Size,SizeUnitMeasureCode,WeightUnitMeasureCode,Weight,DaysToManufacture,ProductLine,Class,Style,ProductSubcategoryId,ProductModelId,SellStartDate,SellEndDate,DiscontinuedDate,Rowguid,ModifiedDate")] Product product)
        {
            if (id != product.ProductId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.ProductId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index), new { id = id }));
            }
            ViewData["ProductModelId"]        = new SelectList(_context.ProductModels, "ProductModelId", "Name", product.ProductModelId);
            ViewData["ProductSubcategoryId"]  = new SelectList(_context.ProductSubcategories, "ProductSubcategoryId", "Name", product.ProductSubcategoryId);
            ViewData["SizeUnitMeasureCode"]   = new SelectList(_context.UnitMeasures, "UnitMeasureCode", "UnitMeasureCode", product.SizeUnitMeasureCode);
            ViewData["WeightUnitMeasureCode"] = new SelectList(_context.UnitMeasures, "UnitMeasureCode", "UnitMeasureCode", product.WeightUnitMeasureCode);
            return(View(product));
        }
        public async Task <IActionResult> Edit(int id, [Bind("CreditCardId,CardType,CardNumber,ExpMonth,ExpYear,ModifiedDate")] CreditCard creditCard)
        {
            if (id != creditCard.CreditCardId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(creditCard);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CreditCardExists(creditCard.CreditCardId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(creditCard));
        }
        public async Task <IActionResult> Edit(int id, [Bind("CurrencyRateId,CurrencyRateDate,FromCurrencyCode,ToCurrencyCode,AverageRate,EndOfDayRate,ModifiedDate")] CurrencyRate currencyRate)
        {
            if (id != currencyRate.CurrencyRateId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(currencyRate);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CurrencyRateExists(currencyRate.CurrencyRateId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FromCurrencyCode"] = new SelectList(_context.Currency, "CurrencyCode", "CurrencyCode", currencyRate.FromCurrencyCode);
            ViewData["ToCurrencyCode"]   = new SelectList(_context.Currency, "CurrencyCode", "CurrencyCode", currencyRate.ToCurrencyCode);
            return(View(currencyRate));
        }
        public async Task <IActionResult> Edit(int id, [Bind("BillOfMaterialsId,ProductAssemblyId,ComponentId,StartDate,EndDate,UnitMeasureCode,Bomlevel,PerAssemblyQty,ModifiedDate")] BillOfMaterials billOfMaterials)
        {
            if (id != billOfMaterials.BillOfMaterialsId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(billOfMaterials);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BillOfMaterialsExists(billOfMaterials.BillOfMaterialsId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ComponentId"]       = new SelectList(_context.Product, "ProductId", "Name", billOfMaterials.ComponentId);
            ViewData["ProductAssemblyId"] = new SelectList(_context.Product, "ProductId", "Name", billOfMaterials.ProductAssemblyId);
            ViewData["UnitMeasureCode"]   = new SelectList(_context.UnitMeasure, "UnitMeasureCode", "UnitMeasureCode", billOfMaterials.UnitMeasureCode);
            return(View(billOfMaterials));
        }
Esempio n. 17
0
        public async Task <IActionResult> Edit(int id, [Bind("ContactTypeId,Name,ModifiedDate")] ContactType contactType)
        {
            if (id != contactType.ContactTypeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(contactType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ContactTypeExists(contactType.ContactTypeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(contactType));
        }
        public void test5()
        {
            var product = _context.Product
                          .OrderBy(p => p.ProductId).First();

            product.Name += "test";
            _context.Update(product);
            Assert.Equal(EntityState.Modified, _context.Entry(product).State);
        }
Esempio n. 19
0
        public async Task <IActionResult> Put([FromBody] ProductUpdateModel model, [FromRoute][Required] int id)
        {
            var product = await _context.Product
                          .FirstOrDefaultAsync(p => p.ProductId == id);

            if (product == null)
            {
                throw new EntryNotFoundException(id);
            }

            _mapper.Map(model, product);

            product.ModifiedDate = DateTime.UtcNow;
            _context.Update(product);

            await _context.SaveChangesAsync();

            return(NoContent());
        }
        public void ShouldTrackChangedEntities()
        {
            var product1 = _context.Product.OrderBy(p => p.ProductId).First();

            product1.Name += " test";
            Assert.Equal(EntityState.Modified, _context.Entry(product1).State);

            var product2 = TestHelpers.CreateProduct("2");

            product2.ProductId = 2;
            _context.Product.Update(product2);
            Assert.Equal(EntityState.Modified, _context.Entry(product2).State);

            //call directly on the context
            var product3 = TestHelpers.CreateProduct("3");

            product3.ProductId = 3;
            _context.Update(product3);
            Assert.Equal(EntityState.Modified, _context.Entry(product3).State);
        }