예제 #1
0
        static void CertificateUpdate(CertificateData cert, SelectableMenuOptions options)
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine($"Certificate edit : {cert.Businessname}");

            var certificatesoptions = new SelectableMenu <Action>(options);
            var props = cert.GetType().GetProperties();

            foreach (var prop in props)
            {
                var name  = prop.Name;
                var value = prop.GetValue(cert);

                value = name == "Password" ? "****" : value;

                certificatesoptions.Add($"{name} : {value}", () =>
                {
                    if (name != "Id")
                    {
                        UpdateCertificateValue(cert, name, options);
                    }
                    else
                    {
                        CertificateUpdate(cert, options);
                    }
                });
            }
            certificatesoptions.Add("Back", () =>
            {
                Console.Clear();
            });

            certificatesoptions.Draw().Invoke();
        }
예제 #2
0
        static void NewCertificateValue(CertificateData cert, string Name, SelectableMenuOptions options)
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine($"Editing value : {Name}");
            Console.WriteLine($"New value : ");
            var stin = Console.ReadLine();
            var prop = cert.GetType().GetProperties().Where(x => x.Name == Name).FirstOrDefault();

            prop.SetValue(cert, stin);

            NewCertificate(cert, options);
        }
예제 #3
0
        static void NewCertificate(CertificateData cert, SelectableMenuOptions options)
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine($"New CertificateData");
            var certificatesoptions = new SelectableMenu <Action>(options);
            var props = cert.GetType().GetProperties();

            foreach (var prop in props)
            {
                var name  = prop.Name;
                var value = prop.GetValue(cert);

                value = name == "Password" ? "****" : value;

                certificatesoptions.Add($"{name} : {value}", () =>
                {
                    if (name != "Id")
                    {
                        NewCertificateValue(cert, name, options);
                    }
                    else
                    {
                        NewCertificate(cert, options);
                    }
                });
            }

            certificatesoptions.Add("Save", () =>
            {
                try
                {
                    certificatedatarepo.Add(cert);
                    _logger?.Info("NewCertificate()", "Certificate added into repository.");
                    CreateMainMenu(options);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Validation errors : { ex.Message }");
                    Console.ReadLine();
                    NewCertificate(cert, options);
                }
            });

            certificatesoptions.Add("Cancel", () =>
            {
                CreateMainMenu(options);
            });

            certificatesoptions.Draw().Invoke();
        }
예제 #4
0
        static void UpdateCertificateValue(CertificateData cert, string Name, SelectableMenuOptions options)
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine($"Editing value : {Name}");
            Console.WriteLine($"New value : ");
            var stin = Console.ReadLine();
            var certificatesoptions = new SelectableMenu <Action>(options);

            var prop = cert.GetType().GetProperties().Where(x => x.Name == Name).FirstOrDefault();

            prop.SetValue(cert, stin);
            try
            {
                var newcertificate = new CertificateData(cert.Id, cert.Password, cert.Path, cert.Businessname);

                certificatesoptions.Add("Save", () =>
                {
                    certificatedatarepo.Update(newcertificate);
                    _logger?.Info("UpdateCertificateValue()", "Certificate updated into repository.");
                    CertificateUpdate(newcertificate, options);
                });

                certificatesoptions.Add("Cancel", () =>
                {
                    NewCertificate(newcertificate, options);
                });
                certificatesoptions.Draw().Invoke();
            }
            catch (Exception ex)
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"Entity validation errors : { ex.Message }");
                Console.ReadLine();
                UpdateCertificateValue(cert, Name, options);
            }
        }