public async Task <Tuple <bool, Result <ProfessorApply> > > CreateApply(ProfessorApply apply) { // 传入的字段并不会全,所以要重新初始化一次 Tuple <bool, Result <ProfessorApply> > result; if (_context.Professors.Any(p => p.ProfessorId == apply.ProfessorId) || _context.ProfessorApplies.Any(pa => pa.Name == apply.Name && pa.ProfessorId == apply.ProfessorId && pa.ApplyState == 1)) { result = new Tuple <bool, Result <ProfessorApply> >(false, new Result <ProfessorApply>(400, "Already applied", null)); return(result); } // 置0再保存 apply.ProfessorApplyId = 0; await _context.AddAsync(apply); await _context.SaveChangesAsync(); result = new Tuple <bool, Result <ProfessorApply> >(true, new Result <ProfessorApply>(200, null, apply)); return(result); }
public async Task <Tuple <bool, Result <Professor> > > CreateProfessor(Professor professor) { // 传入的字段并不会全,所以要重新初始化一次 Tuple <bool, Result <Professor> > result; if (_context.Professors.Any(p => p.Name == professor.Name && p.Institution == professor.Institution)) { result = new Tuple <bool, Result <Professor> >(false, new Result <Professor>(400, "Professor already exists", null)); return(result); } // 置0再保存 professor.ProfessorId = 0; await _context.AddAsync(professor); await _context.SaveChangesAsync(); result = new Tuple <bool, Result <Professor> >(true, new Result <Professor>(200, null, professor)); return(result); }