Пример #1
0
        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());
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("id,username,password,role")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
        public async Task <IActionResult> Create([Bind("id,view,reportId,userId,lastAccessTime")] Readership readership)
        {
            if (ModelState.IsValid)
            {
                _context.Add(readership);
                await _context.SaveChangesAsync();

                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));
        }