// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (await _context.User.AsNoTracking().Where(u => u.stuID == User.stuID).CountAsync() > 0 && (await _context.User.AsNoTracking().Where(u => u.stuID == User.stuID).FirstOrDefaultAsync()).Uid != User.Uid ) { return(new ConflictResult()); } if (User.Secret == null || User.Secret == String.Empty) { var user = await _context.User.AsNoTracking().Where(u => u.Uid == User.Uid).FirstOrDefaultAsync(); user.Name = User.Name; user.stuID = User.stuID; user.isManager = User.isManager; _context.Attach(user).State = EntityState.Modified; } else { var user = await _context.User.AsNoTracking().Where(u => u.Uid == User.Uid).FirstOrDefaultAsync(); user.Name = User.Name; user.stuID = User.stuID; user.isManager = User.isManager; user.Secret = Utils.EvaCryptoHelper.Password2Secret(User.Secret); _context.Attach(user).State = EntityState.Modified; } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(User.Uid)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } InterviewTime interview = await _context.Time.AsNoTracking().FirstOrDefaultAsync(r => r.ID == InterviewTime.ID); InterviewTime.Students = new List <int>(); foreach (var x in interview.Students) { InterviewTime.Students.Add(x); } _context.Attach(InterviewTime).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InterviewTimeExists(InterviewTime.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } //添加日期 if (SelectDay != null && SelectTime != null) { //注意剩余前面的那个空格! SelectTime = SelectTime.Substring(0, SelectTime.IndexOf(" 剩余")); InterviewTime interviewTime = await _context.Time.FirstOrDefaultAsync(r => r.Day == SelectDay && r.BeginTime + " " + r.Place == SelectTime); if (interviewTime != null) { if (interviewTime.NowNum == interviewTime.TakenNum) { return(RedirectToPage("../Error")); } InterviewTime oldTime = null; foreach (var x in _context.Time) { try { if (x.Students.Contains(Record.rid)) { oldTime = x; break; } } catch (NullReferenceException e) { throw e; } } if (oldTime != null) { if (oldTime.NowNum > 0) { oldTime.NowNum -= 1; } oldTime.Students.Remove(Record.rid); await _context.SaveChangesAsync(); } interviewTime.NowNum += 1; interviewTime.Students.Add(Record.rid); await _context.SaveChangesAsync(); Record.InterviewID = interviewTime.ID; Record.InterviewTime = $"{SelectDay} {interviewTime.BeginTime}"; } } //重新赋值 var record = _context.Record.AsNoTracking().Where(r => r.rid == Record.rid).FirstOrDefault(); Record.status = record.status; Record.addedDate = record.addedDate; Record.ip = record.ip; Record.strguid = record.strguid; Record.Times = new List <int>(); foreach (var x in TimeDtos) { if (x.IsChoose) { Record.Times.Add(x.ID); } } _context.Attach(Record).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RecordExists(Record.rid)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }