Exemplo n.º 1
0
        public JsonResult SaveScore(int testscore, int testid, DateTime testtime)
        {
            var   name        = User.Identity.Name;
            var   phonenumber = @User.Claims.SingleOrDefault(s => s.Type == System.Security.Claims.ClaimTypes.MobilePhone).Value;
            var   userid      = _context.User.First(item => item.PhoneNumber == phonenumber).Id;
            var   testname    = _context.Testlist.First(item => item.Id == testid).Testname;
            Score score       = new Score()
            {
                UserId    = userid,
                Testscore = testscore,
                Testid    = testid,
                Testname  = testname,
                Testtime  = testtime,
            };

            _context.Add(score);
            _context.SaveChanges();

            return(new JsonResult("OK"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Scene,Testname,Class,Info")] Testlist testlist)
        {
            if (ModelState.IsValid)
            {
                _context.Add(testlist);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(testlist));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,Title,Info,Time,Fromid,Fromname,Class")] News news)
        {
            if (ModelState.IsValid)
            {
                _context.Add(news);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(news));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Register([Bind("Id,Name,PhoneNumber,Password,Class,Term,Role")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Login)));
            }
            return(View(user));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Id,Testid,Question,Info,Op1,Op2,Op3,Op4,Answ,Mark")] Test test)
        {
            if (ModelState.IsValid)
            {
                _context.Add(test);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(test));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("Id,Name,Info,Path,Size,Class")] Upload upload)
        {
            string path  = null;
            var    files = Request.Form.Files;

            foreach (var file in files)
            {
                string webRootPath = _hostingEnvironment.WebRootPath;
                if (file.Length > 0)
                {
                    string fileExt     = Path.GetExtension(file.FileName);           //文件扩展名
                    long   fileSize    = file.Length;                                //获得文件大小,以字节为单位
                    string newFileName = System.Guid.NewGuid().ToString() + fileExt; //随机生成新的文件名
                    var    filePath    = webRootPath + "/upload/" + newFileName;
                    path = filePath;

                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        file.CopyTo(stream);
                    }
                }
            }
            upload.Path = path;
            FileInfo f    = new FileInfo(path);
            double   size = f.Length / 1024;

            Math.Round(size, 2);
            upload.Size = size.ToString() + "KB";

            if (ModelState.IsValid)
            {
                _context.Add(upload);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(upload));
        }