Пример #1
0
        public void UpdateMakes(IExcelDataReader reader)
        {
            reader.Read();

            while (reader.Read())
            {
                int makeID = 0;
                int.TryParse(reader[0].ToString(), out makeID);
                if (makeID <= 0)
                {
                    continue;
                }

                AutoMake make = AutoMakeService.GetByID(makeID);
                if (make == null)
                {
                    make = new AutoMake()
                    {
                        ID      = makeID,
                        Name    = reader[1].ToString(),
                        Name_ru = reader[2].ToString()
                    };

                    AutoMakeService.Create(make);
                }
                else
                {
                    make.Name    = reader[1].ToString();
                    make.Name_ru = reader[2].ToString();

                    AutoMakeService.Edit(make);
                }
            }
        }
Пример #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            AutoMake autoMake = db.AutoMakes.Find(id);

            db.AutoMakes.Remove(autoMake);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #3
0
 public Autos(AutoMake make, string model, string color, int year, int miles, int currentSpeed)
 {
     Make = make;
     Model = model;
     Color = color;
     Year = year;
     Miles = miles;
     CurrentSpeed = currentSpeed;
 }
Пример #4
0
 public ActionResult Edit([Bind(Include = "Id,CarMake")] AutoMake autoMake)
 {
     if (ModelState.IsValid)
     {
         db.Entry(autoMake).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(autoMake));
 }
Пример #5
0
        public ActionResult Create([Bind(Include = "Id,CarMake")] AutoMake autoMake)
        {
            if (ModelState.IsValid)
            {
                db.AutoMakes.Add(autoMake);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(autoMake));
        }
Пример #6
0
        // GET: AutoMakes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AutoMake autoMake = db.AutoMakes.Find(id);

            if (autoMake == null)
            {
                return(HttpNotFound());
            }
            return(View(autoMake));
        }
Пример #7
0
        // GET: AutoModels
        public ActionResult Index()
        {
            SelectList listOfCarMakes = new SelectList(db.AutoMakes.OrderBy(o => o.CarMake), "Id", "CarMake");

            ViewBag.ListOfCarMake = listOfCarMakes;

            AutoMake firstAutoMake = db.AutoMakes.OrderBy(o => o.CarMake).First();
            int      IdCarMake     = firstAutoMake.Id;

            IEnumerable <AutoModel> listOfCarModelByMake = db.AutoModels.Where(c => c.CarMake == IdCarMake).ToList();

            ViewBag.SelectedCarMake = db.AutoMakes.Find(IdCarMake).CarMake;

            return(View(listOfCarModelByMake));
        }
Пример #8
0
        public void UpdateModels(IExcelDataReader reader)
        {
            reader.Read();

            while (reader.Read())
            {
                int modelID = 0;
                int.TryParse(reader[0].ToString(), out modelID);

                int makeID = 0;
                int.TryParse(reader[1].ToString(), out makeID);
                AutoMake make = AutoMakeService.GetByID(makeID);

                if (modelID <= 0 || make == null)
                {
                    continue;
                }

                AutoModel model = AutoModelService.GetByID(modelID);
                if (model == null)
                {
                    model = new AutoModel()
                    {
                        ID      = modelID,
                        MakeID  = makeID,
                        Name    = reader[2].ToString(),
                        Name_ru = reader[3].ToString()
                    };

                    AutoModelService.Create(model);
                }
                else
                {
                    model.MakeID  = makeID;
                    model.Name    = reader[2].ToString();
                    model.Name_ru = reader[3].ToString();

                    AutoModelService.Edit(model);
                }
            }
        }
Пример #9
0
        public void UpdateBothMakeAndModel(IExcelDataReader reader)
        {
            //clear all unused makes and models
            AutoModelService.DeleteUnused();
            //List<AutoModel> unusedModels = AutoModelService.GetAll().Where(model => model.Autoes.FirstOrDefault() == null).ToList();
            //for (int i = 0; i < unusedModels.Count; i++)
            //    AutoModelService.Delete(unusedModels[i]);

            AutoMakeService.DeleteUnused();

            //List<AutoMake> unusedMakes = AutoMakeService.GetAll().Where(make => make.Autoes.FirstOrDefault() == null && make.AutoModels.Count == 0).ToList();
            //for (int i = 0; i < unusedMakes.Count; i++)
            //    AutoMakeService.Delete(unusedMakes[i]);

            //insert new makes and models
            reader.Read();

            List <AutoMake>  newMakes  = new List <AutoMake>();
            List <AutoModel> newModels = new List <AutoModel>();

            int row = 0;

            try
            {
                while (reader.Read())
                {
                    row++;
                    if (reader[0] == null)
                    {
                        break;
                    }

                    int modelID = 0;
                    int.TryParse(reader[0].ToString(), out modelID);

                    int makeID = 0;
                    int.TryParse(reader[1].ToString(), out makeID);

                    if (modelID <= 0 || makeID <= 0)
                    {
                        return;
                    }


                    //AutoMake make = AutoMakeService.GetByID(makeID);
                    //if (make == null)
                    //{
                    AutoMake make = new AutoMake()
                    {
                        ID      = makeID,
                        Name    = reader[5].ToString(),
                        Name_ru = reader[6].ToString()
                    };

                    if (newMakes.FirstOrDefault(item => item.ID == makeID) == null)
                    {
                        newMakes.Add(make);
                    }
                    //AutoMakeService.Create(make);
                    //}

                    //AutoModel model = AutoModelService.GetByID(modelID);
                    //if (model == null)
                    //{
                    AutoModel model = new AutoModel()
                    {
                        ID      = modelID,
                        MakeID  = makeID,
                        Name    = reader[3].ToString(),
                        Name_ru = reader[4].ToString()
                    };
                    if (newModels.FirstOrDefault(item => item.ID == modelID) == null)
                    {
                        newModels.Add(model);
                    }
                    //    //AutoModelService.Create(model);
                    //}
                }

                AutoMakeService.CreateMany(newMakes);
                AutoModelService.CreateMany(newModels);
            }
            catch (Exception ex)
            {
            }
        }