コード例 #1
0
        public ActionResult Edit(CarBrandFormStub model)
        {
            //bool isNameExist = RepoKompetitor.Find().Where(p => p.name == model.Name && p.id != model.Id).Count() > 0;

            if (ModelState.IsValid)
            {
                car_brand dbItem = RepoCarBrand.FindByPk(model.Id);
                dbItem = model.GetDbObject(dbItem);

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

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

                return(RedirectToAction("Index"));
            }
            else
            {
                car_brand car_brand = RepoCarBrand.FindByPk(model.Id);
                ViewBag.name = car_brand.name;
                return(View("Form", model));
            }
        }
コード例 #2
0
        public ActionResult Edit(System.Guid id)
        {
            car_brand car_brand = RepoCarBrand.FindByPk(id);

            ViewBag.name = car_brand.name;
            CarBrandFormStub formStub = new CarBrandFormStub(car_brand);

            return(View("Form", formStub));
        }
コード例 #3
0
 public void Save(car_brand dbItem)
 {
     if (dbItem.id == Guid.Empty) //create
     {
         dbItem.id = Guid.NewGuid();
         car_brand checkUnique = context.car_brand.Where(x => x.id == dbItem.id).FirstOrDefault();
         while (checkUnique != null)
         {
             dbItem.id   = Guid.NewGuid();
             checkUnique = context.car_brand.Where(x => x.id == dbItem.id).FirstOrDefault();
         }
         context.car_brand.Add(dbItem);
     }
     else //edit
     {
         var entry = context.Entry(dbItem);
         entry.State = EntityState.Modified;
     }
     context.SaveChanges();
 }
コード例 #4
0
        public ActionResult Create(CarBrandFormStub model)
        {
            //bool isNameExist = RepoCarBrand.Find().Where(p => p.name == model.Name).Count() > 0;

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

                RepoCarBrand.Save(dbItem);


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

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View("Form", model));
            }
        }
コード例 #5
0
 public car_brand GetDbObject(car_brand dbItem)
 {
     dbItem.id   = this.Id;
     dbItem.name = this.Name;
     return(dbItem);
 }
コード例 #6
0
 public CarBrandFormStub(car_brand dbItem)
     : this()
 {
     this.Id   = dbItem.id;
     this.Name = dbItem.name;
 }
コード例 #7
0
 public CarBrand(car_brand dbitem)
 {
     CarBrandName = dbitem.name;
 }
コード例 #8
0
 public CarBrandPresentationStub(car_brand dbItem)
 {
     this.Id         = dbItem.id;
     this.IdCarBrand = dbItem.id;
     this.Name       = dbItem.name;
 }
コード例 #9
0
 public void Delete(car_brand dbItem)
 {
     context.car_brand.Remove(dbItem);
     context.SaveChanges();
 }