public async Task <IActionResult> Edit(ProjectMember_EditVD model) { bool isEdit = !string.IsNullOrEmpty(model.Id); bool iseditManger = false; if (!ModelState.IsValid) { return(View(model)); } // ProjectMember_EditVD account = null; ProjectMember pm = null; if (isEdit) { pm = _projectMemberService.GetObject(z => z.Id == model.Id); if (pm == null) { base.SetMessager(MessageType.danger, "信息不存在!"); return(RedirectToAction("Index")); } // pm = _projectMemberService.GetObject(x => x.ProjectId == account.Id && x.Phone == account.ControlId); if (pm != null) { // pm.Id = Guid.NewGuid().ToString("N"); pm.Company = model.Company; pm.Duty = model.Duty; pm.Email = model.Email; //pm.CreateTime = DateTime.Now; pm.Flag = false; pm.Gender = model.Gender; pm.Name = model.Name; pm.Nation = model.Nation; pm.ProjectId = model.ProjectId; pm.Phone = model.Phone; pm.UpdateTime = DateTime.Now; pm.IsLeader = model.IsLeader; pm.IdCard = model.IdCard; pm.Sort = 1; } } else { pm = new ProjectMember() { Id = Guid.NewGuid().ToString("N"), Name = model.Name, Company = model.Company, IdCard = model.IdCard, IsLeader = model.IsLeader, Phone = model.Phone, Gender = model.Gender, Duty = model.Duty, CreateTime = DateTime.Now, Email = model.Email, Flag = false, HeadImgUrl = model.HeadImgUrl, IdCardImgUrl = model.IdCardImgUrl, Nation = model.Nation, ProjectId = model.ProjectId, Sort = model.Sort, UpdateTime = DateTime.Now }; } try { await TryUpdateModelAsync(pm, "", v => v.Name , v => v.IdCard , v => v.Company , v => v.Gender , v => v.Nation , v => v.Phone , v => v.ProjectId , v => v.Sort , v => v.IsLeader , v => v.HeadImgUrl , v => v.IdCardImgUrl ); _projectMemberService.SaveObject(pm); base.SetMessager(MessageType.success, $"{(isEdit ? "修改" : "新增")}成功!"); return(RedirectToAction("Index")); } catch (Exception ex) { base.SetMessager(MessageType.danger, $"{(isEdit ? "修改" : "新增")}失败!" + ex.Message); return(RedirectToAction("Index")); } }
public ActionResult Edit(string id) { bool isEdit = !string.IsNullOrEmpty(id); var vd = new ProjectMember_EditVD(); var activies = _activityService.GetFullList(x => x.IsPublish, x => x.IsPublish, OrderingType.Descending).ToList(); if (activies.Count < 1) { base.SetMessager(MessageType.danger, "请先完善活动主题"); return(RedirectToAction("Index")); } var curactivity = activies.Select(x => x.Id).ToList(); // List<Schedule> list = new List<Schedule>(); var list = _scheduleService.GetFullList(x => curactivity.Contains(x.ActivityId), x => x.Sort, OrderingType.Ascending).ToList().Select(x => x.Id).ToList(); var modellist = _competitionProgramService.GetFullList(x => list.Contains(x.ScheduleId), x => x.CreateTime, OrderingType.Descending).Select(x => x).ToList(); if (isEdit) { var model = _projectMemberService.GetObject(z => z.Id == id); if (model == null) { base.SetMessager(MessageType.danger, "信息不存在!"); return(RedirectToAction("Index")); } vd.Name = model.Name; vd.Id = model.Id; vd.IdCard = model.IdCard; vd.Nation = model.Nation; vd.Phone = model.Phone; vd.ProjectId = model.ProjectId; vd.Sort = model.Sort; vd.IsLeader = model.IsLeader; vd.Gender = model.Gender; vd.Duty = model.Duty; vd.Email = model.Email; vd.Company = model.Company; vd.HeadImgUrl = model.HeadImgUrl; vd.CreateTime = model.CreateTime; vd.UpdateTime = model.UpdateTime; } else { } if (modellist.Count == 0) { base.SetMessager(MessageType.danger, "没有参赛项目"); return(RedirectToAction("Index")); } vd.CompetitionPrograms = modellist; //vd.Schedules = list; vd.IsEdit = isEdit; return(View(vd)); }