예제 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("id,address,port,login,password")] Mail mail)
        {
            if (id != mail.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(mail);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MailExists(mail.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(mail));
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("id,name,text")] DocumentsIB documentsIB)
        {
            if (id != documentsIB.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(documentsIB);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DocumentsIBExists(documentsIB.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(documentsIB));
        }
예제 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("id,ListSystem,lvrol")] InformationSystem informationSystem)
        {
            if (id != informationSystem.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(informationSystem);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!InformationSystemExists(informationSystem.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(informationSystem));
        }
예제 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("id,subdiv,group")] Subdivition subdivition)
        {
            if (id != subdivition.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(subdivition);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SubdivitionExists(subdivition.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(subdivition));
        }
예제 #5
0
        public async Task <IActionResult> Edit(int id, [Bind("id,examp")] example example)
        {
            if (id != example.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(example);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!exampleExists(example.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(example));
        }
예제 #6
0
        public async Task <IActionResult> Edit(int id, [Bind("id,rollic")] Rool rool)
        {
            if (id != rool.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(rool);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RoolExists(rool.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(rool));
        }
예제 #7
0
        public async Task <IActionResult> Edit(int id, [Bind("id,Position,postlistlvl")] PostList postList)
        {
            if (id != postList.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(postList);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PostListExists(postList.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(postList));
        }
예제 #8
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));
        }