Esempio n. 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);
            }
        }
Esempio n. 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();
 }
Esempio n. 3
0
 public void Delete(company dbItem)
 {
     context.companies.Remove(dbItem);
     context.SaveChanges();
 }
Esempio n. 4
0
 public company GetDbObject(company dbItem)
 {
     dbItem.id = this.Id;
     dbItem.name = this.Name;
     return dbItem;
 }
Esempio n. 5
0
 public CompanyFormStub(company dbItem)
     : this()
 {
     this.Id = dbItem.id;
     this.Name = dbItem.name;
 }
Esempio n. 6
0
 public CompanyPresentationStub(company dbItem)
 {
     this.Id = dbItem.id;
     this.Name = dbItem.name;
 }