日期:2014-05-20 浏览次数:21052 次
[Table("CompanyInfo")]
    public class CompanyInfo
    {
        [Key]
        public int id { get; set; }
        [Required(AllowEmptyStrings=false, ErrorMessage="请输入单位名称")]
        public string CompanyName { get; set; }
        [Required(AllowEmptyStrings=false, ErrorMessage="请选择省份")]
        public string ProvinceId { get; set; }
        [Required(AllowEmptyStrings = false, ErrorMessage = "请选择城市")]
        public string CityId { get; set; }
        public List<AccountInfo> AccountInfos{ get; set; }
        public List<DepartmentId> DepartmentIds { get; set; }
    }
[Table("AccountInfo")]
    public class AccountInfo
    {
        [Key]
        public int id { get; set; }
        [Column("CompanyId")]
        public int CompanyInfoId { get; set; }
        public string AccountName { get; set; }
        public string TaxNumber { get; set; }
        public string Address { get; set; }
        public string Telephone { get; set; }
        public string Account { get; set; }
        public string Bank { get; set; }
    }
[Table("DepartmentId")]
    public class DepartmentId
    {
        [Key]
        public int id { get; set; }
        [Column("CompanyId")]
        public int CompanyInfoId { get; set; }
        [Required(AllowEmptyStrings=false, ErrorMessage="请输入下属部门名称")]
        public string DepartmentName { get; set; }
    }
public ActionResult Edit(int id)
        {
            CompanyInfo companyInfo = CRMDB.CompanyInfos.Include(x => x.AccountInfos).Include(x => x.DepartmentIds).Where(x => x.id == id).Single();
            return View(companyInfo);
        }
[HttpPost]
        public ActionResult Edit(CompanyInfo companyInfo)
        {
            if (ModelState.IsValid)
            {
                
                CRMDB.Entry(companyInfo).State = EntityState.Modified;
                CRMDB.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(companyInfo);
        }