public ActionResult Edit(string id) { bool isEdit = !string.IsNullOrEmpty(id); var vd = new Activity_EditVD(); if (isEdit) { var model = _activityService.GetObject(z => z.Id == id); if (model == null) { return(RenderError("信息不存在!")); } vd.Id = model.Id; vd.CoverUrl = model.CoverUrl; vd.Content = model.Content; vd.Description = model.Description; vd.Summary = model.Summary; vd.IsPublish = model.IsPublish; vd.Title = model.Title; vd.ScheduleStatus = model.ScheduleStatus; //vd.Note = model.Note; } vd.IsEdit = isEdit; return(View(vd)); }
public async Task <IActionResult> Edit(Activity_EditVD model) { bool isEdit = !string.IsNullOrEmpty(model.Id); if (!ModelState.IsValid) { return(View(model)); } Activity account = null; if (isEdit) { account = _activityService.GetObject(z => z.Id == model.Id); if (account == null) { base.SetMessager(MessageType.danger, "信息不存在!"); return(RedirectToAction("Index")); } account.ScheduleStatus = model.ScheduleStatus; account.Content = model.Content ?? ""; account.CoverUrl = model.CoverUrl ?? ""; account.Description = model.Description ?? ""; account.IsPublish = true; account.Summary = model.Summary ?? ""; account.Title = model.Title ?? ""; account.ScheduleStatus = model.ScheduleStatus; } else { account = new Activity() { Id = Guid.NewGuid().ToString("N"), Content = model.Content ?? "", CoverUrl = model.CoverUrl ?? "", Description = model.Description ?? "", Flag = false, IsPublish = true, IssueTime = DateTime.Now, Summary = model.Summary ?? "", Title = model.Title ?? "", ScheduleStatus = model.ScheduleStatus }; } try { //if (_accountService.CheckPhoneExisted(account.Id, model.Phone)) //{ // ModelState.AddModelError("Phone", "手机号码重复"); // return View(model); //} // await this.TryUpdateModelAsync<Activity>(account, "" //, z => //, z => z.Phone //, z => z.Note); await this.TryUpdateModelAsync(account, "", v => v.Title, v => v.Content, v => v.Summary, v => v.Flag, v => v.IsPublish, v => v.CoverUrl ); this._activityService.SaveObject(account); base.SetMessager(MessageType.success, $"{(isEdit ? "修改" : "新增")}成功!"); return(RedirectToAction("Index")); } catch (Exception) { base.SetMessager(MessageType.danger, $"{(isEdit ? "修改" : "新增")}失败!"); return(RedirectToAction("Index")); } }