public async Task <byte[]> GetReportAsync(int?reportId) { var userId = HttpContext.Session.GetInt32("userId"); var readership = from r in _context.Readerships where (r.reportId == reportId && r.userId == userId) select r; //no existing readership if (readership.SingleOrDefault() == null) { var obj = new Readership() { reportId = (int)reportId, userId = (int)userId, lastAccessTime = DateTime.Now, view = 1 }; _context.Add(obj); await _context.SaveChangesAsync(); } else { var rdObj = readership.SingleOrDefault(); rdObj.lastAccessTime = DateTime.Now; rdObj.view = rdObj.view + 1; _context.Update(rdObj); await _context.SaveChangesAsync(); } return(await _context.Reports .Where(ai => ai.id == reportId) .Select(ai => ai.DataFiles) .SingleOrDefaultAsync()); }
public async Task <IActionResult> Edit(int id, [Bind("id,view,reportId,userId,lastAccessTime")] Readership readership) { if (id != readership.id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(readership); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReadershipExists(readership.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["userId"] = new SelectList(_context.Users, "id", "id", readership.userId); ViewData["reportId"] = new SelectList(_context.Reports, "id", "id", readership.reportId); return(View(readership)); }
public async Task <IActionResult> Edit(int id, [Bind("id,username,password,role")] User user) { if (id != user.id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(user); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(user.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(user)); }