public async Task <IActionResult> Create(InviteEditModel model) { if (ModelState.IsValid) { try { PersonView person = await this.personService.GetCurrentPersonViewAsync(); InviteCode code = await this.inviteService.InsertAsync(model, person); return(this.Json(AjaxResult.CreateByContext(code))); } catch (ModelException ex) { return(this.Json(ex.ToAjaxResult())); } catch (Exception ex) { return(this.Json(AjaxResult.CreateByMessage(ex.Message, false))); } } else { return(this.Json(ModelState.ToAjaxResult())); } }
/// <summary> /// 插入邀请码 /// </summary> public async Task <InviteCode> InsertAsync(InviteEditModel model, PersonView person) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (person == null) { throw new ArgumentNullException(nameof(person)); } using (var work = this.dbFactory.StartWork()) { if (await work.InviteCode.IsExistCodeAsync(model.Code)) { throw new ModelException(nameof(model.Code), "该邀请码已存在"); } else { InviteCode code = new InviteCode { Code = model.Code, Id = GuidHelper.CreateSequential(), PersonId = person.Id }; await work.InviteCode.InsertAsync(code); return(code); } } }
public IActionResult Create() { InviteEditModel model = new InviteEditModel { Code = "" }; return(View(model)); }