Exemplo n.º 1
0
        public ActionResult Create(CarModelFormStub model)
        {
            //bool isNameExist = RepoCarModel.Find().Where(p => p.name == model.Name).Count() > 0;

            if (ModelState.IsValid)
            {
                car_model dbItem = new car_model();
                dbItem = model.GetDbObject(dbItem);

                try
                {
                    RepoCarModel.Save(dbItem);
                }
                catch (Exception e)
                {
                    model.FillCarBrandOptions(RepoCarBrand.FindAll());
                    return(View("Form", model));
                }

                //message
                string template = HttpContext.GetGlobalResourceObject("MyGlobalMessage", "CreateSuccess").ToString();
                this.SetMessage(model.Name, template);

                return(RedirectToAction("Index"));
            }
            else
            {
                model.FillCarBrandOptions(RepoCarBrand.FindAll());
                return(View("Form", model));
            }
        }
Exemplo n.º 2
0
 public CarModelFormStub(car_model dbItem, List <Business.Entities.car_brand> listCarBrand)
     : this(listCarBrand)
 {
     this.Id         = dbItem.id;
     this.Name       = dbItem.name;
     this.IdCarBrand = dbItem.id_car_brand;
     this.Capacity   = dbItem.capacity;
 }
Exemplo n.º 3
0
 public car_model GetDbObject(car_model dbItem)
 {
     dbItem.id           = this.Id;
     dbItem.name         = this.Name;
     dbItem.id_car_brand = this.IdCarBrand;
     dbItem.capacity     = this.Capacity;
     ;
     return(dbItem);
 }
Exemplo n.º 4
0
 public CarModelPresentationStub(car_model dbItem)
 {
     this.Id           = dbItem.id;
     this.IdCarModel   = dbItem.id;
     this.Name         = dbItem.name;
     this.IdCarBrand   = dbItem.id_car_brand;
     this.CarBrandName = dbItem.car_brand != null ? dbItem.car_brand.name : "";
     this.Capacity     = dbItem.capacity;
 }
Exemplo n.º 5
0
        public ActionResult Edit(Guid id)
        {
            car_model car_model = RepoCarModel.FindByPk(id);
            List <Business.Entities.car_brand> listCarBrand = RepoCarBrand.FindAll();
            CarModelFormStub formStub = new CarModelFormStub(car_model, listCarBrand);

            ViewBag.name = car_model.name;
            return(View("Form", formStub));
        }
Exemplo n.º 6
0
 public void Save(car_model dbItem)
 {
     if (dbItem.id == Guid.Empty) //create
     {
         dbItem.id = Guid.NewGuid();
         car_model checkUnique = context.car_model.Where(x => x.id == dbItem.id).FirstOrDefault();
         while (checkUnique != null)
         {
             dbItem.id   = Guid.NewGuid();
             checkUnique = context.car_model.Where(x => x.id == dbItem.id).FirstOrDefault();
         }
         context.car_model.Add(dbItem);
     }
     else //edit
     {
         var entry = context.Entry(dbItem);
         entry.State = EntityState.Modified;
     }
     context.SaveChanges();
 }
        public override void ImportRow(CsvRow csv)
        {
            // throw new NotImplementedException();
            var rec = unitOfWork.GetObjectByKey <car_model>(csv[0].ToInt());

            if (rec == null)
            {
                rec = new car_model(unitOfWork);
            }

            rec.id_car_model = csv[0].ToInt();
            rec.id_car_make  = unitOfWork.GetObjectByKey <car_make>(csv[1].ToInt());
            rec.name         = csv[2].Truncate(100);
            rec.id_car_type  = unitOfWork.GetObjectByKey <car_type>(csv[5].ToInt());
            rec.Save();

            //  Console.WriteLine($"{rec.id_car_make.name} {rec.name}");
            if (rowCnt % 100 == 0)
            {
                unitOfWork.CommitChanges();
            }
        }
Exemplo n.º 8
0
 public void Delete(car_model dbItem)
 {
     context.car_model.Remove(dbItem);
     context.SaveChanges();
 }