示例#1
0
        // GET: api/Mail/5
        //  [HttpGet("{id}")]
        public async Task <string> ReplisPassword(int id)
        {
            var participant = await _context.UserInfo.FirstOrDefaultAsync(x => x.IdUsers == Convert.ToInt32(id));

            if (participant != null)
            {
                string       password     = passwordGenerate.GetPassword();
                string       hash         = passwordGenerate.Get_Password_Two_Autentification(password);
                EmailService emailService = new EmailService();
                emailService.SendEmail(participant.Email, "Восстановление пароля", "Ваш новый пароль: " + password);
                var customer = _context.UserInfo.Where(c => c.IdUsers == id).FirstOrDefault();
                customer.Password = hash;
                _context.SaveChanges();
                return("True");
            }

            return("Fals");
        }
示例#2
0
        public string ImportCustomer(string patchname)
        {
            string   result_msage = "";
            int      count_i      = 0;
            int      count_row    = 0;
            string   fileName     = patchname;
            FileInfo file         = new FileInfo(Path.Combine(rootFolders, fileName));

            using (ExcelPackage package = new ExcelPackage(file))
            {
                ExcelWorksheet workSheet = package.Workbook.Worksheets["Пользователи"];
                workSheet.Cells[1, 1].Value           = "Участники";
                workSheet.Cells[1, 1].Style.Font.Size = 14;
                workSheet.Cells[1, 1].Style.Font.Bold = true;
                workSheet.Cells["A1:J1"].Merge        = true;
                int totalRows = workSheet.Dimension.Rows;

                List <UserInfo> customerList = new List <UserInfo>();

                for (int i = 2; i <= totalRows; i++)
                {
                    if (workSheet.Cells[i, 1].Value != null && workSheet.Cells[i, 2].Value != null &&
                        workSheet.Cells[i, 3].Value != null && workSheet.Cells[i, 4].Value != null &&
                        workSheet.Cells[i, 5].Value != null && workSheet.Cells[i, 6].Value != null &&
                        workSheet.Cells[i, 7].Value != null && workSheet.Cells[i, 8].Value != null &&
                        workSheet.Cells[i, 9].Value != null && workSheet.Cells[i, 10].Value != null)
                    {
                        var distantions_test = _context.UserInfo.Where(p => p.Login == workSheet.Cells[i, 1].Value.ToString());
                        if (distantions_test.Count() == 0)
                        {
                            string logo = "http://90.189.158.10/folders/nophoto.png";

                            customerList.Add(new UserInfo
                            {
                                Login      = workSheet.Cells[i, 1].Value.ToString(),
                                Password   = passwordGenerate.Get_Password_Two_Autentification(workSheet.Cells[i, 2].Value.ToString()),
                                Rol        = workSheet.Cells[i, 3].Value.ToString(),
                                Fam        = workSheet.Cells[i, 4].Value.ToString(),
                                Name       = workSheet.Cells[i, 5].Value.ToString(),
                                Patronimic = workSheet.Cells[i, 6].Value.ToString(),
                                Years      = (short)workSheet.Cells[i, 7].Value,
                                Logo       = logo,
                                Email      = workSheet.Cells[i, 8].Value.ToString(),
                                Isman      = (bool)workSheet.Cells[i, 9].Value,
                                IdHelth    = (short)workSheet.Cells[i, 10].Value,
                            });
                            count_i      = i - 3;
                            result_msage = "Все строки успешно сохранены, всего" + count_i + " строк";
                        }
                    }
                    else
                    {
                        result_msage = "Сохранено: " + (count_i) + " строк. " + (count_row - count_i) + " строка не заполнена, проверьте и попробуйте снова";
                        break;
                    }
                }
                _context.UserInfo.AddRange(customerList);
                _context.SaveChanges();

                return(result_msage);
            }
        }