示例#1
0
 public ActionResult Create(Company company)
 {
     if (ModelState.IsValid)
     {
         company.CreatedDate = DateTime.Now;
         db.Companies.Add(company);
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.Cities = this.Cities;
     ViewBag.Title = "添加商家";
     return View(company);
 }
示例#2
0
 public ActionResult Create(Company company)
 {
     if (ModelState.IsValid)
     {
         //创建Company
         company.CreatedDate = DateTime.Now;
         db.Companies.Add(company);
         db.SaveChanges();
         //生成Company.Code
         company.Code = string.Format("{0}{1}{2:000}", db.Cities.Find(company.CityId).Abbr, company.Abbr, company.Id);
         //生成CompanyAdmin
         var user = new User { CompanyId = company.Id, CreatedDate = DateTime.Now, UserName = company.Code, Password = Utility.EncryptHelper.MD5Encrypt("666666"), RoleId = 2 };
         db.Users.Add(user);
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.Cities = this.Cities;
     ViewBag.Title = "添加商家";
     return View(company);
 }
示例#3
0
 public ActionResult Edit(Company company)
 {
     if (ModelState.IsValid)
     {
         var entry = db.Entry(company);
         entry.State = EntityState.Modified;
         // Tell EF do not modify the property 'CreatedDate'
         entry.Property("CreatedDate").IsModified = false;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(company);
 }