Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("AccountabilityTypeId,Description")] AccountabilityType accountabilityType)
        {
            if (id != accountabilityType.AccountabilityTypeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(accountabilityType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AccountabilityTypeExists(accountabilityType.AccountabilityTypeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(accountabilityType));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("AccountabilityTypeId,Description")] AccountabilityType accountabilityType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(accountabilityType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(accountabilityType));
        }
Пример #3
0
        public static void MigrateNorthwindData(NORTHWNDContext oldContext, ApplicationDbContext newContext)
        {
            AccountabilityType customerType = new AccountabilityType {
                Description = "Customers"
            };
            AccountabilityType employeeType = new AccountabilityType {
                Description = "Employees"
            };
            AccountabilityType shipperType = new AccountabilityType {
                Description = "Shippers"
            };
            AccountabilityType supplierType = new AccountabilityType {
                Description = "Suppliers"
            };

            if (!newContext.AccountabilityTypes.Any())
            {
                //accountabilitytypes
                newContext.AccountabilityTypes.Add(customerType);
                newContext.AccountabilityTypes.Add(employeeType);
                newContext.AccountabilityTypes.Add(shipperType);
                newContext.AccountabilityTypes.Add(supplierType);
                newContext.SaveChanges();
            }

            if (!newContext.Parties.Any())
            {
                Party northwind = new Party()
                {
                    Name = "Northwind"
                };
                newContext.Parties.Add(northwind);
                newContext.SaveChanges();

                foreach (var shipper in oldContext.Shippers.ToList())
                {
                    Party party = new Party()
                    {
                        Name = shipper.CompanyName
                    };
                    newContext.Parties.Add(party);
                    newContext.Accountabilities.Add(new Accountability()
                    {
                        Accountable = party, Commissioner = northwind, AccountabilityType = shipperType
                    });
                }

                foreach (var customer in oldContext.Customers.ToList())
                {
                    Party party = new Party()
                    {
                        Name = customer.CompanyName
                    };
                    newContext.Parties.Add(party);
                    newContext.Accountabilities.Add(new Accountability()
                    {
                        Accountable = northwind, Commissioner = party, AccountabilityType = customerType
                    });
                }

                foreach (var supplier in oldContext.Suppliers.ToList())
                {
                    Party party = new Party()
                    {
                        Name = supplier.CompanyName
                    };
                    newContext.Parties.Add(party);
                    newContext.Accountabilities.Add(new Accountability()
                    {
                        Accountable = party, Commissioner = northwind, AccountabilityType = supplierType
                    });
                }

                foreach (var employee in oldContext.Employees.ToList())
                {
                    Party party = new Party()
                    {
                        Name = $"{ employee.FirstName } { employee.LastName }"
                    };
                    newContext.Parties.Add(party);
                    newContext.Accountabilities.Add(new Accountability()
                    {
                        Accountable = party, Commissioner = northwind, AccountabilityType = employeeType
                    });
                }

                newContext.SaveChanges();
            }
        }