示例#1
0
        public ActionResult Create(CompanyFormStub model)
        {
            //bool isNameExist = RepoCompany.Find().Where(p => p.name == model.Name).Count() > 0;

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

                try
                {
                    RepoCompany.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
            {
                return View("Form", model);
            }
        }
示例#2
0
 public void Save(company dbItem)
 {
     if (dbItem.id == 0) //create
     {
         context.companies.Add(dbItem);
     }
     else //edit
     {
         var entry = context.Entry(dbItem);
         entry.State = EntityState.Modified;
     }
     context.SaveChanges();
 }
示例#3
0
 public void Delete(company dbItem)
 {
     context.companies.Remove(dbItem);
     context.SaveChanges();
 }
示例#4
0
 public company GetDbObject(company dbItem)
 {
     dbItem.id = this.Id;
     dbItem.name = this.Name;
     return dbItem;
 }
示例#5
0
 public CompanyFormStub(company dbItem)
     : this()
 {
     this.Id = dbItem.id;
     this.Name = dbItem.name;
 }
示例#6
0
 public CompanyPresentationStub(company dbItem)
 {
     this.Id = dbItem.id;
     this.Name = dbItem.name;
 }