Example #1
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var informationSystem = await _context.Tablelaws.FindAsync(id);

            _context.Tablelaws.Remove(informationSystem);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Example #2
0
        public async Task <IActionResult> Create([Bind("id,infsystem ,position,sp")] law lw)
        {
            if (ModelState.IsValid)
            {
                string        inform = "";
                int           item1  = 0;
                List <string> inf    = new List <string> {
                };
                List <int> numberinf = new List <int> {
                };
                for (int i = 0; lw.infsystem.Length > i; i++)
                {
                    if (lw.infsystem.Substring(i, 1) != ";")
                    {
                        inform = inform + lw.infsystem.Substring(i, 1);
                    }
                    else
                    {
                        inf.Add(inform);
                        numberinf.Add(item1);
                        item1++;
                        inform = "";
                    }
                }
                string        pos      = "";
                List <string> posit    = new List <string> {
                };
                List <int> numberposit = new List <int> {
                };
                int item = 0;
                for (int i = 0; lw.position.Length > i; i++)
                {
                    if (lw.position.Substring(i, 1) != ";")
                    {
                        pos = pos + lw.position.Substring(i, 1);
                    }
                    else
                    {
                        posit.Add(pos);
                        numberposit.Add(item);
                        item++;
                        pos = "";
                    }
                }
                HttpContext.Session.SetString("spodr", lw.sp);
                HttpContext.Session.SetObjectAsJson("numberposit", numberposit);
                HttpContext.Session.SetObjectAsJson("nemberinf", numberinf);
                HttpContext.Session.SetObjectAsJson("posit", posit);
                HttpContext.Session.SetObjectAsJson("inf", inf);
                _context.Add(lw);
                await _context.SaveChangesAsync();

                return(Redirect("../Tablelaws/Create"));
                // return RedirectToAction(nameof(Index));
            }
            return(View("../DocumentsIBs/Index", await _context.DocumentsIB.ToListAsync()));
        }
Example #3
0
        public async Task <IActionResult> Create([Bind("id,address,port,login,password")] Mail mail)
        {
            if (ModelState.IsValid)
            {
                _context.Add(mail);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(mail));
        }
Example #4
0
        public async Task <IActionResult> Create([Bind("id,ListSystem,lvrol")] InformationSystem informationSystem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(informationSystem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(informationSystem));
        }
Example #5
0
        public async Task <IActionResult> Create([Bind("id,name,text")] DocumentsIB documentsIB)
        {
            if (ModelState.IsValid)
            {
                _context.Add(documentsIB);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(documentsIB));
        }
Example #6
0
        public async Task <IActionResult> Create([Bind("id,subdiv,group")] Subdivition subdivition)
        {
            if (ModelState.IsValid)
            {
                _context.Add(subdivition);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(subdivition));
        }
Example #7
0
        public async Task <IActionResult> Create([Bind("id,examp")] example example)
        {
            if (ModelState.IsValid)
            {
                _context.Add(example);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(example));
        }
Example #8
0
        public async Task <IActionResult> Create([Bind("id,rollic")] Rool rool)
        {
            if (ModelState.IsValid)
            {
                _context.Add(rool);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(rool));
        }
Example #9
0
        public async Task <IActionResult> Create([Bind("id,Position,postlistlvl")] PostList postList)
        {
            if (ModelState.IsValid)
            {
                _context.Add(postList);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(postList));
        }
Example #10
0
        public async Task <IActionResult> Sign(int id, [Bind("id, fio, subdivision, numberphone, numberroom, inventorynumber, position, documents, baseservers, leadersubdivision, informationsystem, departmentib, departmentoz, status, marh, namecreated,  deportmencreated, positcreated, login, emailcreated, signIT, olduser, neuser")] Request request)
        {
            if (id != request.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    request.marh = request.marh + 1;

                    if (request.marh == 0 || request.marh == 2)
                    {
                        request.status = "Закрыта";
                        string fio  = "";
                        string name = "";
                        int    flag = 0;
                        if (request.marh == 2)
                        {
                            //Формирование ФИО
                            for (int j = 0; j < request.fio.Length; j++)
                            {
                                if (request.fio.Substring(j, 1) == " ")
                                {
                                    flag = flag + 1;
                                }
                                if (flag == 0)
                                {
                                    fio = fio + request.fio.Substring(j, 1);
                                }
                                else
                                {
                                    if (request.fio.Substring(j, 1) == " " && flag == 1)
                                    {
                                    }
                                    else
                                    {
                                        name = name + request.fio.Substring(j, 1);
                                    }
                                }
                            }

                            //Формиривание Описания
                            string subdiv = "";
                            flag = 0;
                            var item = await _context.Subdivitions.ToListAsync();

                            foreach (Subdivition it in item)
                            {
                                if (it.subdiv == request.subdivision)
                                {
                                    subdiv = it.group;
                                }
                            }

                            //Группы  относящиеся к базовым сервисми
                            string group    = "";
                            string internet = "";
                            string netfold  = "";
                            string mailuser = "";
                            for (int j = 0; j < request.baseservers.Length; j++)
                            {
                                if (request.baseservers.Substring(j, 1) != ";")
                                {
                                    group = group + request.baseservers.Substring(j, 1);
                                }
                                else
                                {
                                    if (group == "Доступ в сеть интернет - Ограниченный")
                                    {
                                        internet = "AOG-Internet-Restricted";
                                    }
                                    if (group == "Доступ в сеть интернет - Стандартный")
                                    {
                                        internet = "AOG-Internet-Standard";
                                    }
                                    if (group == "Доступ к сетевому файловому ресурсу")
                                    {
                                        var sub = await _context.Subdivitions.ToListAsync();

                                        foreach (Subdivition gr in sub)
                                        {
                                            if (request.subdivision == gr.subdiv)
                                            {
                                                netfold = gr.group;
                                            }
                                        }
                                    }
                                    if (group == "Электронный почтовый ящик")
                                    {
                                        mailuser = "******";
                                    }
                                    group = "";
                                    j++;
                                }
                            }

                            //Группы ИСиС
                            List <string> isands = new List <string>()
                            {
                            };
                            string text = "";

                            for (int j = 0; j < request.informationsystem.Length; j++)
                            {
                                if (request.informationsystem.Substring(j, 1) != "-")
                                {
                                    text = text + request.informationsystem.Substring(j, 1);
                                }
                                if (request.informationsystem.Substring(j, 1) == ";")
                                {
                                    text = "";
                                }
                                if (request.informationsystem.Substring(j, 1) == "-")
                                {
                                    isands.Add(text);
                                    text = "";

                                    j++;
                                }
                            }

                            if (netfold != "")
                            {
                                isands.Add(netfold);
                            }
                            if (internet != "")
                            {
                                isands.Add(internet);
                            }
                            var runspace = RunspaceFactory.CreateRunspace();
                            runspace.Open();
                            var pipeline = runspace.CreatePipeline();

                            using (PowerShell powerShellInstance = PowerShell.Create())
                            {
                                var initial = InitialSessionState.CreateDefault();
                                Console.WriteLine("Importing ServerManager module");
                                initial.ImportPSModule(new[] { "ServerManager" });
                                powerShellInstance.Runspace = runspace;
                                powerShellInstance.AddScript("Set-ExecutionPolicy Unrestricted");
                                //powerShellInstance.AddScript("Get-ExecutionPolicy");
                                powerShellInstance.Invoke();
                                Command          cmd        = new Command("C:\\Users\\kozlov.aa\\source\\repos\\testad\\testad\\bin\\Debug\\netcoreapp3.1\\powershell\\test.ps1");
                                CommandParameter testParam1 = new CommandParameter("FirstName", name);
                                CommandParameter testParam2 = new CommandParameter("LastName", fio);
                                CommandParameter testParam3 = new CommandParameter("Description", subdiv);
                                CommandParameter testParam4 = new CommandParameter("Office", request.numberroom);
                                CommandParameter testParam5 = new CommandParameter("TelephoneNumber", request.numberphone);
                                CommandParameter testParam6 = new CommandParameter("SAN", request.login);
                                CommandParameter testParam7 = new CommandParameter("Title", request.position);
                                CommandParameter testParam8 = new CommandParameter("Department", request.subdivision);
                                CommandParameter testParam9 = new CommandParameter("Company", "АО Газпром газораспределение Астрахань");
                                //CommandParameter testParam10 = new CommandParameter("Interner", internet);
                                //  CommandParameter testParam11 = new CommandParameter("NetFold", netfold);
                                // CommandParameter testParam12 = new CommandParameter("InformSyst", isands);
                                cmd.Parameters.Add(testParam1);
                                cmd.Parameters.Add(testParam2);
                                cmd.Parameters.Add(testParam3);
                                cmd.Parameters.Add(testParam4);
                                cmd.Parameters.Add(testParam5);
                                cmd.Parameters.Add(testParam6);
                                cmd.Parameters.Add(testParam7);
                                cmd.Parameters.Add(testParam8);
                                cmd.Parameters.Add(testParam9);
                                //  cmd.Parameters.Add(testParam10);
                                //  cmd.Parameters.Add(testParam11);
                                // cmd.Parameters.Add(testParam12);
                                pipeline.Commands.Add(cmd);
                                var results = pipeline.Invoke();
                                pipeline.Dispose();
                                runspace.Dispose();
                                // return View(await _context.Requests.ToListAsync());
                            }
                            //Добавление групп пользователю
                            if (isands != null)
                            {
                                foreach (string ff in isands)
                                {
                                    var runspace1 = RunspaceFactory.CreateRunspace();
                                    runspace1.Open();
                                    var pipeline1 = runspace1.CreatePipeline();

                                    using (PowerShell powerShellInstance = PowerShell.Create())
                                    {
                                        var initial = InitialSessionState.CreateDefault();
                                        Console.WriteLine("Importing ServerManager module");
                                        initial.ImportPSModule(new[] { "ServerManager" });
                                        powerShellInstance.Runspace = runspace1;
                                        powerShellInstance.AddScript("Set-ExecutionPolicy Unrestricted");
                                        //powerShellInstance.AddScript("Get-ExecutionPolicy");
                                        powerShellInstance.Invoke();
                                        Command          cmd         = new Command("C:\\Users\\kozlov.aa\\source\\repos\\testad\\testad\\bin\\Debug\\netcoreapp3.1\\powershell\\test1.ps1");
                                        CommandParameter testParam12 = new CommandParameter("InformSyst", ff);
                                        CommandParameter testParam6  = new CommandParameter("SAN", request.login);
                                        cmd.Parameters.Add(testParam12);
                                        cmd.Parameters.Add(testParam6);
                                        pipeline1.Commands.Add(cmd);
                                        var results1 = pipeline1.Invoke();
                                        pipeline1.Dispose();
                                        runspace1.Dispose();
                                    }
                                }
                            }

                            //Добавление почты
                            var mail = await _context.Mails.ToListAsync();

                            foreach (Mail it in mail)
                            {
                                MailMessage message = new MailMessage();
                                message.IsBodyHtml = true;
                                message.From       = new MailAddress("*****@*****.**", "Информационная система доступа");
                                message.To.Add("*****@*****.**");
                                message.Subject = "Сообщение от ";
                                message.Body    = "<div style=\"color: dark;\"><p style=\"text - align: center;\"><strong>Учетная запись:</strong>" + request.fio + " Идентификатор аккаунта - " + request.login + "</p>" +
                                                  "<p style=\"text - align: justify; \"><strong>Создана в Active Directory:</strong> - ДА</p>" +
                                                  "<p style=\"text - align: justify; \"><strong>Информационные серивисы и ресурсы:&nbsp;</strong>" + request.informationsystem + " " + request.baseservers + "</p>" +
                                                  "<p style=\"text - align: justify; \"><strong></strong></p>" +
                                                  "<p style=\"text - align: justify; \"><strong>Необходимые работы </strong>" + mailuser + " - " + request.fio + "</p>" +
                                                  "</div>";

                                using (SmtpClient client = new SmtpClient(it.address))
                                {
                                    client.Credentials = new NetworkCredential(it.login, it.password);
                                    client.Port        = it.port;
                                    client.EnableSsl   = false;
                                    client.Send(message);
                                }
                            }
                        }
                    }
                    _context.Update(request);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RequestExists(request.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(request));
        }