public async Task <IActionResult> PutTeacherCookie(long id, TeacherCookie teacherCookie) { if (id != teacherCookie.Id) { return(BadRequest()); } _context.Entry(teacherCookie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TeacherCookieExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <TeacherCookie> > PostTeacherCookie(TeacherCookie teacherCookie) { //delete cookies added a month ago long tempCount = teacherCookie.ExpireCount; var widgets = _context.TeacherCookies.Where(w => tempCount - w.ExpireCount >= 3600 * 24 * Startup.EXPIREDAYS); foreach (TeacherCookie widget in widgets) { _context.TeacherCookies.Remove(widget); } _context.TeacherCookies.Add(teacherCookie); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTeacherCookie", new { id = teacherCookie.Id }, teacherCookie)); }