public ActionResult Add(int id) { var model = new SanatoriumViewModel(); if (id > 0) { //编辑 Sanatorium.Models.Sanatorium sanatorium = db.Sanatoriums.Find(id); { if (sanatorium != null) { model.Id = id; model.Name = sanatorium.Name; model.Pics = sanatorium.Pics; model.Region = sanatorium.Region; model.Street = sanatorium.Street; model.Community = sanatorium.Community; model.Address = sanatorium.Address; model.StagingCount = sanatorium.StagingCount; model.CompletionYear = sanatorium.CompletionYear; model.BuildingsCount = sanatorium.BuildingsCount; model.StructureArea = sanatorium.StructureArea; model.FinishArea = sanatorium.FinishArea; model.DoingArea = sanatorium.DoingArea; model.ToDoArea = sanatorium.ToDoArea; model.ShiShiOrg = sanatorium.ShiShiOrg; model.ShiGongOrg = sanatorium.ShiGongOrg; model.StartTime = sanatorium.StartTime; model.FinishTime = sanatorium.FinishTime; model.PredictFinishTime = sanatorium.PredictFinishTime; model.BuildOrg = sanatorium.BuildOrg; model.BuildOrgPrincipal = sanatorium.BuildOrgPrincipal; model.BuildOrgPhone = sanatorium.BuildOrgPhone; model.BuildOrgWeb = sanatorium.BuildOrgWeb; model.DesignOrg = sanatorium.DesignOrg; model.DesignOrgPrincipal = sanatorium.DesignOrgPrincipal; model.DesignOrgPhone = sanatorium.DesignOrgPhone; model.DesignOrgWeb = sanatorium.DesignOrgWeb; model.SupervisionOrg = sanatorium.SupervisionOrg; model.SupervisionOrgPrincipal = sanatorium.SupervisionOrgPrincipal; model.SupervisionOrgPhone = sanatorium.SupervisionOrgPhone; model.SupervisionOrgWeb = sanatorium.SupervisionOrgWeb; model.GongZiPhone = sanatorium.GongZiPhone; model.JuMinPhone = sanatorium.JuMinPhone; model.Remark = sanatorium.Remark; } else { //未找到该项目 } } } //选择项目 //var hremoves = db.HRemoves.Where(h => h.Id > 0).ToList(); //var selectList = new SelectList(hremoves, "Name", "Name"); //ViewData["list"] = selectList; var regions = db.Regions.Where(c => c.Id > 0).ToList(); var regionList = new SelectList(regions, "Name", "Name"); var streets = db.Streets.Where(c => c.Id > 0).ToList(); var streetList = new SelectList(streets, "Name", "Name"); var communitys = db.Communitys.Where(c => c.Id > 0).ToList(); var communityList = new SelectList(communitys, "Name", "Name"); ViewData["regions"] = regionList; ViewData["streets"] = streetList; ViewData["communitys"] = communityList; SetMyAccountViewModel(); return(View(model)); }
public ActionResult Add(SanatoriumViewModel model) { var requestHelper = new RequestHelper(this.Request); if (ModelState.IsValid) { int id = 0; if (model.Id > 0)//修改 { Models.Sanatorium sanatorium = db.Sanatoriums.SingleOrDefault(h => h.Id == model.Id); if (sanatorium != null) { var filePath = requestHelper.SaveImageToServer(); if (!string.IsNullOrEmpty(filePath)) { sanatorium.Pics = filePath; } sanatorium.Name = model.Name; sanatorium.Region = model.Region; sanatorium.Street = model.Street; sanatorium.Community = model.Community; sanatorium.Address = model.Address; sanatorium.ShiShiOrg = model.ShiShiOrg; sanatorium.ShiGongOrg = model.ShiGongOrg; sanatorium.StartTime = model.StartTime.Value; sanatorium.FinishTime = model.FinishTime.Value; sanatorium.PredictFinishTime = model.PredictFinishTime.Value; sanatorium.StructureArea = model.StructureArea; sanatorium.FinishArea = model.FinishArea; sanatorium.DoingArea = model.DoingArea; sanatorium.ToDoArea = model.ToDoArea; sanatorium.BuildingsCount = model.BuildingsCount; sanatorium.StagingCount = model.StagingCount; sanatorium.CompletionYear = model.CompletionYear; sanatorium.BuildOrg = model.BuildOrg; sanatorium.BuildOrgWeb = model.BuildOrgWeb; sanatorium.BuildOrgPrincipal = model.BuildOrgPrincipal; sanatorium.BuildOrgPhone = model.BuildOrgPhone; sanatorium.DesignOrg = model.DesignOrg; sanatorium.DesignOrgWeb = model.DesignOrgWeb; sanatorium.DesignOrgPrincipal = model.DesignOrgPrincipal; sanatorium.DesignOrgPhone = model.DesignOrgPhone; sanatorium.SupervisionOrg = model.SupervisionOrg; sanatorium.SupervisionOrgWeb = model.SupervisionOrgWeb; sanatorium.SupervisionOrgPrincipal = model.SupervisionOrgPrincipal; sanatorium.SupervisionOrgPhone = model.SupervisionOrgPhone; sanatorium.GongZiPhone = model.GongZiPhone; sanatorium.JuMinPhone = model.JuMinPhone; sanatorium.Remark = model.Remark; sanatorium.CreatedOn = DateTime.Now; db.Entry(sanatorium).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); id = sanatorium.Id; } } else { Models.Sanatorium sanatorium = new Models.Sanatorium(); var filePath = requestHelper.SaveImageToServer(); if (!string.IsNullOrEmpty(filePath)) { sanatorium.Pics = filePath; } sanatorium.Name = model.Name; sanatorium.Region = model.Region; sanatorium.Street = model.Street; sanatorium.Community = model.Community; sanatorium.Address = model.Address; sanatorium.ShiShiOrg = model.ShiShiOrg; sanatorium.ShiGongOrg = model.ShiGongOrg; sanatorium.StartTime = model.StartTime.Value; sanatorium.FinishTime = model.FinishTime.Value; sanatorium.PredictFinishTime = model.PredictFinishTime.Value; sanatorium.StructureArea = model.StructureArea; sanatorium.FinishArea = model.FinishArea; sanatorium.DoingArea = model.DoingArea; sanatorium.ToDoArea = model.ToDoArea; sanatorium.BuildingsCount = model.BuildingsCount; sanatorium.StagingCount = model.StagingCount; sanatorium.CompletionYear = model.CompletionYear; sanatorium.BuildOrg = model.BuildOrg; sanatorium.BuildOrgWeb = model.BuildOrgWeb; sanatorium.BuildOrgPrincipal = model.BuildOrgPrincipal; sanatorium.BuildOrgPhone = model.BuildOrgPhone; sanatorium.DesignOrg = model.DesignOrg; sanatorium.DesignOrgWeb = model.DesignOrgWeb; sanatorium.DesignOrgPrincipal = model.DesignOrgPrincipal; sanatorium.DesignOrgPhone = model.DesignOrgPhone; sanatorium.SupervisionOrg = model.SupervisionOrg; sanatorium.SupervisionOrgWeb = model.SupervisionOrgWeb; sanatorium.SupervisionOrgPrincipal = model.SupervisionOrgPrincipal; sanatorium.SupervisionOrgPhone = model.SupervisionOrgPhone; sanatorium.GongZiPhone = model.GongZiPhone; sanatorium.JuMinPhone = model.JuMinPhone; sanatorium.Remark = model.Remark; sanatorium.CreatedOn = DateTime.Now; db.Sanatoriums.Add(sanatorium); db.SaveChanges(); id = sanatorium.Id; } return(RedirectToAction("EditDescriptionInfo", new { id = id })); } SetMyAccountViewModel(); return(View(model)); }