示例#1
0
 public IActionResult Edit([Bind("BrandID,BrandName," +
                                 "BrandCompany,BrandCountry,BrandStartDate,BrandEndingDate," +
                                 "BrandCharacteristic,BrandCategory,BrandDescription")] Brand brand)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _db.Update(brand);
             _db.SaveChanges();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!BrandExists(brand.BrandID))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction("Brands"));
     }
     return(View(brand));
 }
示例#2
0
 public IActionResult Edit([Bind("CarID,BrandID,OwnerID,CarRegistrationNumber," +
                                 "CarPhoto,CarNumberOfBody,CarNumberOfMotor,CarNumberOfPassport," +
                                 "CarReleaseDate,CarRegistrationDate," +
                                 "CarLastCheckupDate,CarColor,CarDescription")] Car car)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _db.Update(car);
             _db.SaveChanges();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!CarExists(car.CarID))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction("Cars"));
     }
     ViewData["BrandID"] = new SelectList(_db.Brands, "BrandID", "BrandName", car.BrandID);
     ViewData["OwnerID"] = new SelectList(_db.Owners, "OwnerID", "OwnerName", car.OwnerID);
     return(View(car));
 }
示例#3
0
 public IActionResult Edit([Bind("OwnerID,OwnerName,OwnerBirthDate,OwnerAddress," +
                                 "OwnerPassport,OwnerNumberOfDriverLicense,OwnerLicenseDeliveryDate,OwnerLicenseValidityDate," +
                                 "OwnerCategory,OwnerMoreInformation")] Owner owner)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _db.Update(owner);
             _db.SaveChanges();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!OwnerExists(owner.OwnerID))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction("Owners"));
     }
     return(View(owner));
 }
示例#4
0
        private static void InitializeBrands(UchetContext db, int brandsNumber)
        {
            db.Database.EnsureCreated();

            // Проверка занесены ли Brands
            if (db.Brands.Any())
            {
                return;   // База данных инициализирована
            }

            string   brandName;
            string   brandCompany;
            string   brandCountry;
            DateTime brandStartDate;
            DateTime brandEndingDate;
            string   brandCharacteristic;
            string   brandCategory;
            string   brandDescription;


            Random randObj = new Random(1);

            //Заполнение таблицы емкостей
            for (int BrandID = 1; BrandID <= brandsNumber; BrandID++)
            {
                brandName      = MyRandom.RandomString(7);
                brandCompany   = MyRandom.RandomString(10);
                brandCountry   = MyRandom.RandomString(10);
                brandStartDate = new DateTime(randObj.Next(1990, 2016),
                                              randObj.Next(1, 12),
                                              randObj.Next(1, 28));
                brandEndingDate = new DateTime(randObj.Next(1990, 2016),
                                               randObj.Next(1, 12),
                                               randObj.Next(1, 28));
                brandCharacteristic = MyRandom.RandomString(15);
                brandCategory       = MyRandom.RandomString(7);
                brandDescription    = MyRandom.RandomString(10);


                db.Brands.Add(new Brand {
                    BrandName           = brandName,
                    BrandCompany        = brandCompany,
                    BrandCountry        = brandCountry,
                    BrandStartDate      = brandStartDate,
                    BrandEndingDate     = brandEndingDate,
                    BrandCharacteristic = brandCharacteristic,
                    BrandCategory       = brandCategory,
                    BrandDescription    = brandDescription
                });
            }

            //сохранение изменений в базу данных, связанную с объектом контекста
            db.SaveChanges();
        }
示例#5
0
        private static void InitializeCars(UchetContext db, int carsNumber, int brandsNumber, int ownersNumber)
        {
            db.Database.EnsureCreated();

            // Проверка занесены ли Cars
            if (db.Cars.Any())
            {
                return;   // База данных инициализирована
            }


            int      brandID;
            int      ownerID;
            int      carRegistrationNumber;
            int      carPhoto;
            int      carNumberOfBody;
            int      carNumberOfMotor;
            int      carNumberOfPassport;
            DateTime carReleaseDate;
            DateTime carRegistrationDate;
            DateTime carLastCheckupDate;
            string   carColor;
            string   carDescription;


            Random randObj = new Random(1);

            //Заполнение таблицы емкостей
            for (int OwnerID = 1; OwnerID <= ownersNumber; OwnerID++)
            {
                carColor       = MyRandom.RandomString(7);
                carDescription = MyRandom.RandomString(10);

                carReleaseDate = new DateTime(randObj.Next(1990, 2016),
                                              randObj.Next(1, 12),
                                              randObj.Next(1, 28));
                carRegistrationDate = new DateTime(randObj.Next(1990, 2016),
                                                   randObj.Next(1, 12),
                                                   randObj.Next(1, 28));
                carLastCheckupDate = new DateTime(randObj.Next(1990, 2016),
                                                  randObj.Next(1, 12),
                                                  randObj.Next(1, 28));

                brandID = randObj.Next(1, brandsNumber - 1);
                ownerID = randObj.Next(1, ownersNumber - 1);
                carRegistrationNumber = randObj.Next(1, 60000);
                carPhoto            = randObj.Next(1, 500);
                carNumberOfBody     = randObj.Next(1, 1000);
                carNumberOfMotor    = randObj.Next(1, 1000);
                carNumberOfPassport = randObj.Next(1, 1000);



                db.Cars.Add(new Car
                {
                    BrandID = brandID,
                    OwnerID = ownerID,
                    CarRegistrationNumber = carRegistrationNumber,
                    CarPhoto            = carPhoto,
                    CarNumberOfBody     = carNumberOfBody,
                    CarNumberOfMotor    = carNumberOfMotor,
                    CarNumberOfPassport = carNumberOfPassport,
                    CarReleaseDate      = carReleaseDate,
                    CarRegistrationDate = carRegistrationDate,
                    CarLastCheckupDate  = carLastCheckupDate,
                    CarColor            = carColor,
                    CarDescription      = carDescription,
                });
            }

            //сохранение изменений в базу данных, связанную с объектом контекста
            db.SaveChanges();
        }
示例#6
0
        private static void InitializeOwners(UchetContext db, int ownersNumber)
        {
            db.Database.EnsureCreated();

            // Проверка занесены ли Owners
            if (db.Owners.Any())
            {
                return;   // База данных инициализирована
            }


            string   ownerName;
            DateTime ownerBirthDate;
            string   ownerAddress;
            string   ownerPassport;
            int      ownerNumberOfDriverLicense;
            DateTime ownerLicenseDeliveryDate;
            DateTime ownerLicenseValidityDate;
            string   ownerCategory;
            string   ownerMoreInformation;

            Random randObj = new Random(1);

            //Заполнение таблицы емкостей
            for (int OwnerID = 1; OwnerID <= ownersNumber; OwnerID++)
            {
                ownerName      = MyRandom.RandomString(7);
                ownerAddress   = MyRandom.RandomString(10);
                ownerPassport  = MyRandom.RandomString(10);
                ownerBirthDate = new DateTime(randObj.Next(1990, 2016),
                                              randObj.Next(1, 12),
                                              randObj.Next(1, 28));
                ownerLicenseDeliveryDate = new DateTime(randObj.Next(1990, 2016),
                                                        randObj.Next(1, 12),
                                                        randObj.Next(1, 28));
                ownerLicenseValidityDate = new DateTime(randObj.Next(1990, 2016),
                                                        randObj.Next(1, 12),
                                                        randObj.Next(1, 28));
                ownerCategory = MyRandom.RandomString(15);
                ownerNumberOfDriverLicense = randObj.Next(1, 3000);
                ownerMoreInformation       = MyRandom.RandomString(10);



                db.Owners.Add(new Owner
                {
                    OwnerName                  = ownerName,
                    OwnerBirthDate             = ownerBirthDate,
                    OwnerAddress               = ownerAddress,
                    OwnerPassport              = ownerPassport,
                    OwnerNumberOfDriverLicense = ownerNumberOfDriverLicense,
                    OwnerLicenseDeliveryDate   = ownerLicenseDeliveryDate,
                    OwnerLicenseValidityDate   = ownerLicenseValidityDate,
                    OwnerCategory              = ownerCategory,
                    OwnerMoreInformation       = ownerMoreInformation
                });
            }

            //сохранение изменений в базу данных, связанную с объектом контекста
            db.SaveChanges();
        }