Пример #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;
 }