Beispiel #1
0
        public async Task <IActionResult> ConfirmEmail(string userId, string code)
        {
            if (userId == null || code == null)
            {
                return(RedirectToAction(nameof(HomeController.Index), "Home"));
            }
            var user = await _userManager.FindByIdAsync(userId);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{userId}'.");
            }
            var result = await _userManager.ConfirmEmailAsync(user, code);

            if (result.Succeeded)
            {
                await dbNavant.NavchRobs.AddAsync(new NavchRob { User = userId, PIB = user.PIB });

                await dbNavant.NaukRobs.AddAsync(new NaukRob { User = userId, PIB = user.PIB });

                await dbNavant.MetodRobs.AddAsync(new MetodRob { User = userId, PIB = user.PIB });

                await dbNavant.OrgRobs.AddAsync(new OrgRob { User = userId, PIB = user.PIB });

                await dbNavant.NormatKilkistBalivOrgRobs.AddAsync(new NormatKilkistBalivOrgRob { User = userId, PIB = user.PIB });

                dbNavant.SaveChanges();
                var RegCode = dbRegist.RegisterBufs.Where(buf => buf.PIB == user.PIB);
                dbRegist.RegisterBufs.RemoveRange(RegCode);
                dbRegist.SaveChanges();
            }
            return(View(result.Succeeded ? "ConfirmEmail" : "Error"));
        }
Beispiel #2
0
        public async Task <IActionResult> OnPostImport()
        {
            IFormFile     fileExcel   = Request.Form.Files[0];
            string        papkaName   = "Upload";
            string        webRootPath = _hostingEnvironment.WebRootPath;
            string        newPath     = Path.Combine(webRootPath, papkaName);
            StringBuilder sb          = new StringBuilder();

            if (!Directory.Exists(newPath))
            {
                Directory.CreateDirectory(newPath);
            }
            if (fileExcel.Length > 0)
            {
                string sFileExtension = Path.GetExtension(fileExcel.FileName).ToLower();
                ISheet sheet;
                string fullPath = Path.Combine(newPath, fileExcel.FileName);
                using (var stream = new FileStream(fullPath, FileMode.Create))
                {
                    fileExcel.CopyTo(stream);
                    stream.Position = 0;
                    if (sFileExtension == ".xls")
                    {
                        HSSFWorkbook hssfwb = new HSSFWorkbook(stream);
                        sheet = hssfwb.GetSheetAt(0);
                    }
                    else
                    {
                        XSSFWorkbook hssfwb = new XSSFWorkbook(stream);
                        sheet = hssfwb.GetSheetAt(0);
                    }
                    List <Navantagennya> navantagennyaList = new List <Navantagennya>();
                    IRow headerRow = sheet.GetRow(0);
                    int  cellCount = headerRow.LastCellNum;
                    sb.Append("<table class='table'><tr>");
                    for (int j = 0; j < cellCount; j++)
                    {
                        ICell cell = headerRow.GetCell(j);
                        if (cell == null || string.IsNullOrWhiteSpace(cell.ToString()))
                        {
                            continue;
                        }
                        sb.Append("<th>" + cell.ToString() + "</th>");
                    }
                    sb.Append("</tr>");
                    sb.AppendLine("<tr>");

                    for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++) //Read Excel File
                    {
                        IRow row = sheet.GetRow(i);
                        if (row == null)
                        {
                            continue;
                        }
                        if (row.Cells.All(d => d.CellType == CellType.Blank))
                        {
                            continue;
                        }
                        for (int j = row.FirstCellNum; j < cellCount; j++)
                        {
                            if (row.GetCell(j) != null)
                            {
                                sb.Append("<td>" + row.GetCell(j).ToString() + "</td>");
                            }
                        }
                        sb.AppendLine("</tr>");

                        navantagennyaList.Add(new Navantagennya
                        {
                            NumberPP   = ConvertCellToInt(row.GetCell(0)),
                            NumberDisc = ConvertCellToInt(row.GetCell(1)),
                            Nazva      = ConvertCellToString(row.GetCell(2)),
                            Grupa      = ConvertCellToString(row.GetCell(3)),
                            Kurs       = ConvertCellToInt(row.GetCell(4)),
                            Studentiv  = ConvertCellToInt(row.GetCell(5)),
                            Grup       = ConvertCellToInt(row.GetCell(6)),
                            Pidgrup    = ConvertCellToInt(row.GetCell(7)),
                            Semestr    = row.GetCell(8).ToString(),
                            Lekcii     = ConvertCellToDouble(row.GetCell(9)),
                            Consultant = ConvertCellToDouble(row.GetCell(10)),
                            Laborant   = ConvertCellToDouble(row.GetCell(11)),
                            Praktuchni = ConvertCellToDouble(row.GetCell(12)),
                            Modul      = ConvertCellToDouble(row.GetCell(13)),
                            Kursovi    = ConvertCellToDouble(row.GetCell(14)),
                            Zalik      = ConvertCellToDouble(row.GetCell(15)),
                            Isput      = ConvertCellToDouble(row.GetCell(16)),
                            Dyplom     = ConvertCellToDouble(row.GetCell(17)),
                            DEK        = ConvertCellToDouble(row.GetCell(18)),
                            Aspiranty  = ConvertCellToDouble(row.GetCell(19)),
                            Praktyka   = ConvertCellToDouble(row.GetCell(20)),
                            Kontrolny  = ConvertCellToDouble(row.GetCell(21)),
                            Vsyogo     = ConvertCellToDouble(row.GetCell(22)),
                            Primitka   = ConvertCellToString(row.GetCell(23)),
                            Vikladach  = row.GetCell(24).ToString()
                        });
                    }
                    sb.Append("</table>");
                    await dbNavant.Navantagennyas.AddRangeAsync(navantagennyaList);

                    dbNavant.SaveChanges();
                }
            }
            return(this.Content(sb.ToString()));
        }