/// <summary>
        /// Private method that converts the form data to XML
        /// </summary>
        /// <param name="vm"></param>
        /// <returns>An <see cref="XElement"/></returns>
        private XElement ViewModelToXML(PAFFormViewModel vm)
        {
            XElement root = new XElement("SmartPAF");

            PropertyInfo[] properties = typeof(PAFFormViewModel).GetProperties();
            foreach (PropertyInfo property in properties)
            {
                if (property.Name != "Components" && property.Name != "job" && property.Name != "JobList" && property.Name != "Users" && property.Name != "DocumentId" && property.Name != "PAFTypeChoices")
                {
                    root.Add(new XElement(property.Name, property.GetValue(vm), new XAttribute("id", property.Name)));
                }
            }
            SmartUser      author   = _repository.Users.FirstOrDefault(x => x.UserId == vm.AuthorUserId);
            SmartJob       smartJob = _repository.Jobs.FirstOrDefault(x => x.JobId == vm.JobId);
            JobDescription job      = new JobDescription(smartJob);

            root.Add(new XElement("AuthorName", author?.DisplayName ?? "Unknown", new XAttribute("AuthorName", author?.DisplayName ?? "Unknown")));
            XElement xJob = new XElement("JobDescription");

            xJob.Add(new XElement("ClassTitle", job.ClassTitle, new XAttribute("id", "ClassTitle")));
            xJob.Add(new XElement("WorkingTitle", job.WorkingTitle, new XAttribute("id", "WorkingTitle")));
            xJob.Add(new XElement("Grade", job.Grade, new XAttribute("id", "Grade")));
            xJob.Add(new XElement("WorkingHours", job.WorkingHours, new XAttribute("id", "WorkingHours")));
            xJob.Add(new XElement("JobId", job.SmartJobId, new XAttribute("id", "JobId")));
            root.Add(xJob);
            return(root);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:SmartDocs.Models.ViewModels.JobDescriptionListViewModeltem"/> class.
 /// </summary>
 /// <remarks>
 /// Class constructor that takes a <see cref="T:SmartDocs.Models.SmartJob"/> parameter
 /// </remarks>
 /// <param name="dbJob">The <see cref="T:SmartDocs.Models.SmartJob"/>.</param>
 public JobDescriptionListViewModeltem(SmartJob dbJob)
 {
     JobId   = dbJob.JobId;
     JobName = dbJob.JobName;
     Grade   = dbJob.JobDataXml.Element("Grade").Value;
     Rank    = dbJob.JobDataXml.Element("Rank").Value;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:SmartDocs.Models.Types.JobDescriptionListItem"/> class.
 /// </summary>
 /// <remarks>
 /// Constructor that takes a <see cref="T:SmartDocs.Models.SmartJob"/> parameter
 /// </remarks>
 /// <param name="dBJob">A <see cref="T:SmartDocs.Models.SmartJob"/>.</param>
 public JobDescriptionListItem(SmartJob dBJob)
 {
     JobId       = dBJob.JobId;
     Rank        = dBJob.JobDataXml.Element("Rank").Value;
     Grade       = dBJob.JobDataXml.Element("Grade").Value;
     DisplayName = dBJob.JobName;
 }
Exemple #4
0
        public IActionResult Create([Bind("WorkingTitle,Grade,WorkingHours,Rank,Categories")] JobDescriptionViewModel form)
        {
            if (!ModelState.IsValid)
            {
                // model state validation failed, return VM to user with validation error messages
                ViewData["Title"] = "Create a Job Description: Error";
                return(View(form));
            }
            else
            {
                // POST is valid

                // create a JobDescription Object via the constructor that accepts a JobDescriptionViewModel object
                // I need to do this because I need the .JobDescriptionToXml() method to write the Job Description data
                // to the SmartJob entity JobData field, which is XML.
                JobDescription job   = new JobDescription(form);
                SmartJob       DbJob = new SmartJob
                {
                    JobName    = $"{job.Rank}-{job.WorkingTitle}",
                    JobDataXml = job.JobDescriptionToXml() // call the JobDescription method to convert Job Data to XML and write to entity column
                };
                // EF context saves are encapsulated in the IDocumentRepository instance
                _repository.SaveJob(DbJob);
                // return the user to the Index view
                return(RedirectToAction(nameof(Index)));
            }
        }
Exemple #5
0
        public IActionResult Edit(int id)
        {
            SmartJob job = _repository.Jobs.FirstOrDefault(j => j.JobId == id);
            JobDescriptionViewModel vm = new JobDescriptionViewModel(job);

            ViewData["Title"] = "Edit Job Description";
            return(View(vm));
        }
Exemple #6
0
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            SmartJob smartJob = await dbContext.SmartJobs.FindAsync(id);

            if (smartJob == null)
            {
                return(RedirectToAction("Index"));
            }

            return(View(smartJob));
        }
Exemple #7
0
        public ActionResult Edit(int ID = -1)
        {
            SmartJob smartJob = null;

            if (ID == -1)
            {
                smartJob               = new SmartJob();
                smartJob.ID            = -1;
                smartJob.IsActive      = true;
                smartJob.ExecutionMode = ExecutionModeEnum.Regular;
                smartJob.Rule          = new Rule()
                {
                    RegularPeriod = PeriodEnum.Minute
                };
                smartJob.Events = new List <JobEvent>();
            }
            else
            {
                smartJob = dbContext.SmartJobs.Include("Rule").Include("CreditsNet").Include("Events").Include("CreatedBy").FirstOrDefault(x => x.ID == ID);

                if (smartJob == null)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    if (!User.IsInRole("Admin"))
                    {
                        var identity = HttpContext.GetOwinContext().Authentication.GetExternalIdentity(DefaultAuthenticationTypes.ApplicationCookie);

                        var user = dbContext.Users.FirstOrDefault(x => x.Email == identity.Name);

                        if (user.Id != smartJob.CreatedBy.Id)
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                }
            }

            return(View(smartJob));
        }
        public async Task <JsonResult> AddNewTask(NewTaskModel model)
        {
            var result = new ApiJsonResult();

            try
            {
                using (var dbContext = new DatabaseContext())
                {
                    var user = dbContext.Users.FirstOrDefault(x => x.ApiKey == model.ApiKey);
                    if (user == null)
                    {
                        result.IsSuccess = false;
                        result.Message   = "The key value is wrong";
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(model.Name))
                        {
                            result.IsSuccess = false;
                            result.Message   = "The name value is required";
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(model.Network))
                            {
                                result.IsSuccess = false;
                                result.Message   = "The network value is required";
                            }
                            else
                            {
                                if (model.Network != "testnet-r4_2" && model.Network != "DevsDappsTestnet" && model.Network != "CreditsNetwork")
                                {
                                    result.IsSuccess = false;
                                    result.Message   = "The network value is wrong. Supported values: 'testnet-r4_2', 'DevsDappsTestnet', 'CreditsNetwork'";
                                }
                                else
                                {
                                    if (string.IsNullOrEmpty(model.Method))
                                    {
                                        result.IsSuccess = false;
                                        result.Message   = "The method value is required";
                                    }
                                    else
                                    {
                                        if (string.IsNullOrEmpty(model.Address))
                                        {
                                            result.IsSuccess = false;
                                            result.Message   = "The address value is required";
                                        }
                                        else
                                        {
                                            if (string.IsNullOrEmpty(model.ExecutionMode))
                                            {
                                                result.IsSuccess = false;
                                                result.Message   = "The executionMode value is required";
                                            }
                                            else
                                            {
                                                if (model.ExecutionMode == "Regular")
                                                {
                                                    if (CheckDate(model.RegularDateFrom) == DateTime.MinValue)
                                                    {
                                                        result.IsSuccess = false;
                                                        result.Message   = "The regularDateFrom value is wrong. Supported mask: mm-DD-YYYY-hh-MM-ss";
                                                    }
                                                    else if (CheckDate(model.RegularDateTo) == DateTime.MinValue)
                                                    {
                                                        result.IsSuccess = false;
                                                        result.Message   = "The regularDateTo value is wrong. Supported mask: mm-DD-YYYY-hh-MM-ss";
                                                    }
                                                    else if (CheckPeriodName(model.RegularPeriod) == 0)
                                                    {
                                                        result.IsSuccess = false;
                                                        result.Message   = "The regularPeriod value is wrong. Supported values: 'Minutes', 'Hours', 'Days'";
                                                    }
                                                    else if (CheckPeriodValue(model.RegularValue) == 0)
                                                    {
                                                        result.IsSuccess = false;
                                                        result.Message   = "The regularValue value is wrong. Supported values: 1, 2, 3, and so on...";
                                                    }
                                                }
                                                else if (model.ExecutionMode == "Once")
                                                {
                                                    if (CheckDate(model.OnceDate) == DateTime.MinValue)
                                                    {
                                                        result.IsSuccess = false;
                                                        result.Message   = "The onceDate value is wrong. Supported mask: mm-DD-YYYY-hh-MM-ss";
                                                    }
                                                }
                                                else if (model.ExecutionMode == "InSeconds")
                                                {
                                                    if (CheckInSeconds(model.InSecondsValue) == false)
                                                    {
                                                        result.IsSuccess = false;
                                                        result.Message   = "The InSecondsValue value is wrong. Value must be integer value";
                                                    }
                                                    else
                                                    {
                                                        var seconds       = Convert.ToInt32(model.InSecondsValue);
                                                        var dateExecution = DateTime.Now.AddSeconds(seconds);
                                                        model.OnceDate = dateExecution.ToString("MM-dd-yyyy-HH-mm-ss");
                                                    }
                                                }
                                                else if (model.ExecutionMode == "CronExpression")
                                                {
                                                }
                                                else
                                                {
                                                    result.IsSuccess = false;
                                                    result.Message   = "The executionMode value is wrong. Supported values: 'Regular', 'Once', 'CronExpression'";
                                                }

                                                //Ошибок нет, создаем новую задачу
                                                if (!result.IsSuccess)
                                                {
                                                    var smartJob = new SmartJob();
                                                    smartJob           = new SmartJob();
                                                    smartJob.CreatedBy = user;
                                                    smartJob.CreatedAt = DateTime.Now;
                                                    smartJob.Rule      = new Rule();
                                                    smartJob.Events    = new List <JobEvent>();
                                                    smartJob.Name      = model.Name;
                                                    smartJob.IsActive  = true;
                                                    smartJob.Method    = model.Method;
                                                    smartJob.Address   = model.Address;
                                                    smartJob.IsDeleted = false;
                                                    smartJob.DeleteTaskAfterExecution = model.DeleteTaskAfterExecution == "1";
                                                    smartJob.CreditsNet           = dbContext.CreditsNets.FirstOrDefault(x => x.Name == model.Network);
                                                    smartJob.ExecutionMode        = CheckExecutionMode(model.ExecutionMode);
                                                    smartJob.Rule.RegularDateFrom = CheckDate(model.RegularDateFrom).ToString("MM/dd/yyyy HH:mm:ss");
                                                    smartJob.Rule.RegularDateTo   = CheckDate(model.RegularDateTo).ToString("MM/dd/yyyy HH:mm:ss");
                                                    smartJob.Rule.RegularPeriod   = ConvertPeriod(model.RegularPeriod);
                                                    smartJob.Rule.RegularValue    = CheckPeriodValue(model.RegularValue);
                                                    smartJob.Rule.OnceDate        = CheckDate(model.OnceDate).ToString("MM/dd/yyyy HH:mm:ss");
                                                    smartJob.Rule.CronExpression  = model.CronExpression;
                                                    smartJob.Rule.Presentation    = Rule.GeneratePresentation(smartJob);

                                                    dbContext.SmartJobs.Add(smartJob);
                                                    await dbContext.SaveChangesAsync();

                                                    //Обновляем данные по задаче
                                                    await QuartzTasks.UpdateJob(smartJob.ID);

                                                    result.IsSuccess = true;
                                                    result.Message   = "Action completed";
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (DbEntityValidationException err)
            {
                var outputLines = new List <string>();

                foreach (var eve in err.EntityValidationErrors)
                {
                    outputLines.Add(
                        $"{DateTime.Now}: Entity of type \"{eve.Entry.Entity.GetType().Name}\" in state \"{eve.Entry.State}\" has the following validation errors:");
                    outputLines.AddRange(eve.ValidationErrors.Select(ve =>
                                                                     $"- Property: \"{ve.PropertyName}\", Error: \"{ve.ErrorMessage}\""));
                }

                result.IsSuccess = false;
                result.Message   = String.Join(", ", outputLines.ToArray());
            }
            catch (Exception err)
            {
                result.IsSuccess = false;
                result.Message   = err.ToString();
            }

            return(new JsonResult
            {
                MaxJsonLength = Int32.MaxValue,
                Data = result,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemple #9
0
        public async Task <ActionResult> Edit(SmartJob model)
        {
            var identity = HttpContext.GetOwinContext().Authentication.GetExternalIdentity(DefaultAuthenticationTypes.ApplicationCookie);

            if (identity == null || identity.Name == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                var user = dbContext.Users.FirstOrDefault(x => x.Email == identity.Name);

                if (user == null)
                {
                    return(RedirectToAction("Login", "Account"));
                }
                else if (!user.IsActivated)
                {
                    return(RedirectToAction("WaitActivation", "Account"));
                }

                if (ModelState.IsValid)
                {
                    var smartJob = await dbContext.SmartJobs.Include("Rule").Include("CreditsNet").Include("Events").Include("CreatedBy").FirstOrDefaultAsync(x => x.ID == model.ID);

                    if (smartJob == null)
                    {
                        smartJob           = new SmartJob();
                        smartJob.CreatedBy = user;
                        smartJob.CreatedAt = DateTime.Now;
                        smartJob.Rule      = new Rule();
                        smartJob.Events    = new List <JobEvent>();

                        dbContext.SmartJobs.Add(smartJob);
                    }

                    smartJob.Name       = model.Name;
                    smartJob.IsActive   = model.IsActive;
                    smartJob.Method     = model.Method;
                    smartJob.Address    = model.Address;
                    smartJob.CreditsNet = await dbContext.CreditsNets.FirstOrDefaultAsync(x => x.ID == model.CreditsNet.ID);

                    smartJob.ExecutionMode        = model.ExecutionMode;
                    smartJob.Rule.RegularDateFrom = model.Rule.RegularDateFrom;
                    smartJob.Rule.RegularDateTo   = model.Rule.RegularDateTo;
                    smartJob.Rule.RegularPeriod   = model.Rule.RegularPeriod;
                    smartJob.Rule.RegularValue    = model.Rule.RegularValue;
                    smartJob.Rule.OnceDate        = model.Rule.OnceDate;
                    smartJob.Rule.CronExpression  = model.Rule.CronExpression;
                    smartJob.Rule.Presentation    = Rule.GeneratePresentation(smartJob);

                    await dbContext.SaveChangesAsync();

                    //Обновляем данные по задаче
                    await QuartzTasks.UpdateJob(smartJob.ID);

                    return(RedirectToAction("Index", "Home"));
                }

                return(View(model));
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:SmartDocs.Models.ViewModels.JobDescriptionViewModel"/> class.
        /// </summary>
        /// <remarks>
        /// Class Constructor that takes a <see cref="SmartDocs.Models.SmartJob"/> parameter.
        /// </remarks>
        /// <param name="job">A <see cref="SmartDocs.Models.SmartJob"/>.</param>
        public JobDescriptionViewModel(SmartJob job)
        {
            JobId = job.JobId;
            // populate the Rank List via the DefaultRankList method below
            Ranks = DefaultRankList();


            // create an empty list of JobDescription Categories to be populated from DB Job XML column data
            List <JobDescriptionCategory> results = new List <JobDescriptionCategory>();
            // retrieve the XML data column for the job to parse for Job Data
            XElement root = job.JobDataXml;

            // assign the simple values
            WorkingTitle = root.Element("WorkingTitle").Value;
            Grade        = root.Element("Grade").Value;
            WorkingHours = root.Element("WorkingHours").Value;
            Rank         = root.Element("Rank").Value;

            // pull all of the Categories from the root element
            // categories are stored in the root's "Categories" child, which contains "Category" children
            IEnumerable <XElement> CategoryList = root.Element("Categories").Elements("Category");

            // loop through the list of Categories and build a JobDescriptionCategory class object for each
            foreach (XElement category in CategoryList)
            {
                // create a new JobDescriptionCategory object, and set the Letter, Weight, and Title from the XElement's children
                JobDescriptionCategory cat = new JobDescriptionCategory
                {
                    Letter = category.Element("Letter").Value,
                    Weight = Convert.ToInt32(category.Element("Weight").Value),
                    Title  = category.Element("Title").Value
                };
                // The XElement built from a "Category" has a child named "PositionDescriptionFields" that contains "PositionDescriptionItem" children
                IEnumerable <XElement> positionDescriptionFields = category.Element("PositionDescriptionFields").Elements("PositionDescriptionItem");

                // Loop through the collection of PositionDescriptionFields and create a PositionDescriptionItem class object from each
                foreach (XElement positionDescriptionItem in positionDescriptionFields)
                {
                    // create the PositionDescriptionItem class object
                    PositionDescriptionItem item = new PositionDescriptionItem {
                        Detail = positionDescriptionItem.Value
                    };
                    // add the PositionDescriptionItem class object to the Category's collection
                    cat.PositionDescriptionItems.Add(item);
                }
                // The XElement build from a "Category" has a child named "PerformanceStandardFields" that contains "PerformanceStandardItem" objects
                IEnumerable <XElement> performanceStandardFields = category.Element("PerformanceStandardFields").Elements("PerformanceStandardItem");

                // Loop through the collection of PerformanceStandardFields and create a PerformanceStandardItem class object from each
                foreach (XElement performanceStandardItem in performanceStandardFields)
                {
                    // create a new PerformanceStandardItem class object and populate it's properties from the XML data
                    PerformanceStandardItem item = new PerformanceStandardItem {
                        Initial = performanceStandardItem.Attribute("initial").Value, Detail = performanceStandardItem.Value
                    };
                    // add the PerformanceStandardItem class object to the Category's collection.
                    cat.PerformanceStandardItems.Add(item);
                }
                // the JobDescriptionCategory is built, so add it to the "results" collection
                results.Add(cat);
            }
            // assign the newly built collection of JobDescriptionCategory items named "results" to the class Categories properties
            Categories = results;
        }
Exemple #11
0
        public ActionResult FirstRun()
        {
            var identity = HttpContext.GetOwinContext().Authentication.GetExternalIdentity(DefaultAuthenticationTypes.ApplicationCookie);

            using (var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new DatabaseContext())))
                using (var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new DatabaseContext())))
                    using (var dbContext = new DatabaseContext())
                    {
                        var userId = userManager.FindByName(identity.Name).Id;
                        var admin  = dbContext.Users.FirstOrDefault(x => x.Email == identity.Name);
                        admin.IsActivated = true;
                        dbContext.SaveChanges();

                        if (!roleManager.RoleExists("Admin"))
                        {
                            roleManager.Create(new IdentityRole {
                                Name = "Admin"
                            });
                        }

                        if (!userManager.IsInRole(userId, "Admin"))
                        {
                            userManager.AddToRole(userId, "Admin");
                        }

                        //CreditsNets
                        dbContext.CreditsNets.Add(new CreditsNet {
                            Name = "CreditsNetwork", EndPoint = "http://wallet.credits.com/Main/api/UnsafeTransaction"
                        });
                        dbContext.CreditsNets.Add(new CreditsNet {
                            Name = "testnet-r4_2", EndPoint = "http://wallet.credits.com/testnet-r4_2/api/UnsafeTransaction"
                        });
                        dbContext.CreditsNets.Add(new CreditsNet {
                            Name = "DevsDappsTestnet", EndPoint = "http://wallet.credits.com/DevsDappsTestnet/api/UnsafeTransaction"
                        });
                        dbContext.SaveChanges();

                        //SmartJobs 1
                        var sj = new SmartJob();
                        sj.Address              = "5kXTAm4wYJ6P1DLACk9ehUQEzjUKLHHBKA2EK1yinvz6";
                        sj.CreatedAt            = DateTime.Now;
                        sj.CreatedBy            = admin;
                        sj.CreditsNet           = dbContext.CreditsNets.FirstOrDefault(x => x.Name == "Credits network");
                        sj.Events               = new List <JobEvent>();
                        sj.ExecutionMode        = SmartJob.ExecutionModeEnum.Regular;
                        sj.IsActive             = true;
                        sj.Method               = "Method 1";
                        sj.Name                 = "Задача 1";
                        sj.Rule                 = new Rule();
                        sj.Rule.RegularDateFrom = "10.07.2019 05:05:19";
                        sj.Rule.RegularDateTo   = "31.07.2019 22:03:07";
                        sj.Rule.RegularPeriod   = PeriodEnum.Minute;
                        sj.Rule.RegularValue    = 5;
                        sj.Rule.Presentation    = Rule.GeneratePresentation(sj);
                        dbContext.SmartJobs.Add(sj);

                        //SmartJobs 2
                        sj                   = new SmartJob();
                        sj.Address           = "5kXTAm4wYJ6P1DLACk9ehUQEzjUKLHHBKA2EK1yinvz6";
                        sj.CreatedAt         = DateTime.Now;
                        sj.CreatedBy         = admin;
                        sj.CreditsNet        = dbContext.CreditsNets.FirstOrDefault(x => x.Name == "Test net");
                        sj.Events            = new List <JobEvent>();
                        sj.ExecutionMode     = SmartJob.ExecutionModeEnum.Once;
                        sj.IsActive          = true;
                        sj.Method            = "Method 2";
                        sj.Name              = "Задача 2";
                        sj.Rule              = new Rule();
                        sj.Rule.OnceDate     = "10.07.2019 05:05:19";
                        sj.Rule.Presentation = Rule.GeneratePresentation(sj);
                        dbContext.SmartJobs.Add(sj);

                        //SmartJobs 3
                        sj                     = new SmartJob();
                        sj.Address             = "5kXTAm4wYJ6P1DLACk9ehUQEzjUKLHHBKA2EK1yinvz6";
                        sj.CreatedAt           = DateTime.Now;
                        sj.CreatedBy           = admin;
                        sj.CreditsNet          = dbContext.CreditsNets.FirstOrDefault(x => x.Name == "Devs & dapps");
                        sj.Events              = new List <JobEvent>();
                        sj.ExecutionMode       = SmartJob.ExecutionModeEnum.CronExpression;
                        sj.IsActive            = false;
                        sj.Method              = "Method 3";
                        sj.Name                = "Задача 3";
                        sj.Rule                = new Rule();
                        sj.Rule.CronExpression = "0,13 0,55 0/7 5,16 * ? *";
                        sj.Rule.Presentation   = Rule.GeneratePresentation(sj);
                        dbContext.SmartJobs.Add(sj);

                        //SmartJobs 4
                        sj                      = new SmartJob();
                        sj.Address              = "5kXTAm4wYJ6P1DLACk9ehUQEzjUKLHHBKA2EK1yinvz6";
                        sj.CreatedAt            = DateTime.Now;
                        sj.CreatedBy            = admin;
                        sj.CreditsNet           = dbContext.CreditsNets.FirstOrDefault(x => x.Name == "Credits network");
                        sj.Events               = new List <JobEvent>();
                        sj.ExecutionMode        = SmartJob.ExecutionModeEnum.Regular;
                        sj.IsActive             = true;
                        sj.Method               = "Method 4";
                        sj.Name                 = "Задача 4";
                        sj.Rule                 = new Rule();
                        sj.Rule.RegularDateFrom = "10.07.2019 05:05:19";
                        sj.Rule.RegularDateTo   = "31.07.2019 22:03:07";
                        sj.Rule.RegularPeriod   = PeriodEnum.Minute;
                        sj.Rule.RegularValue    = 5;
                        sj.Rule.Presentation    = Rule.GeneratePresentation(sj);
                        dbContext.SmartJobs.Add(sj);

                        //SmartJobs 5
                        sj                   = new SmartJob();
                        sj.Address           = "5kXTAm4wYJ6P1DLACk9ehUQEzjUKLHHBKA2EK1yinvz6";
                        sj.CreatedAt         = DateTime.Now;
                        sj.CreatedBy         = admin;
                        sj.CreditsNet        = dbContext.CreditsNets.FirstOrDefault(x => x.Name == "Test net");
                        sj.Events            = new List <JobEvent>();
                        sj.ExecutionMode     = SmartJob.ExecutionModeEnum.Once;
                        sj.IsActive          = true;
                        sj.Method            = "Method 5";
                        sj.Name              = "Задача 5";
                        sj.Rule              = new Rule();
                        sj.Rule.OnceDate     = "10.07.2019 05:05:19";
                        sj.Rule.Presentation = Rule.GeneratePresentation(sj);
                        dbContext.SmartJobs.Add(sj);

                        //SmartJobs 6
                        sj                     = new SmartJob();
                        sj.Address             = "5kXTAm4wYJ6P1DLACk9ehUQEzjUKLHHBKA2EK1yinvz6";
                        sj.CreatedAt           = DateTime.Now;
                        sj.CreatedBy           = admin;
                        sj.CreditsNet          = dbContext.CreditsNets.FirstOrDefault(x => x.Name == "Devs & dapps");
                        sj.Events              = new List <JobEvent>();
                        sj.ExecutionMode       = SmartJob.ExecutionModeEnum.CronExpression;
                        sj.IsActive            = false;
                        sj.Method              = "Method 6";
                        sj.Name                = "Задача 6";
                        sj.Rule                = new Rule();
                        sj.Rule.CronExpression = "0,13 0,55 0/7 5,16 * ? *";
                        sj.Rule.Presentation   = Rule.GeneratePresentation(sj);
                        dbContext.SmartJobs.Add(sj);

                        //SmartJobs 7
                        sj                      = new SmartJob();
                        sj.Address              = "5kXTAm4wYJ6P1DLACk9ehUQEzjUKLHHBKA2EK1yinvz6";
                        sj.CreatedAt            = DateTime.Now;
                        sj.CreatedBy            = admin;
                        sj.CreditsNet           = dbContext.CreditsNets.FirstOrDefault(x => x.Name == "Credits network");
                        sj.Events               = new List <JobEvent>();
                        sj.ExecutionMode        = SmartJob.ExecutionModeEnum.Regular;
                        sj.IsActive             = true;
                        sj.Method               = "Method 7";
                        sj.Name                 = "Задача 7";
                        sj.Rule                 = new Rule();
                        sj.Rule.RegularDateFrom = "10.07.2019 05:05:19";
                        sj.Rule.RegularDateTo   = "31.07.2019 22:03:07";
                        sj.Rule.RegularPeriod   = PeriodEnum.Minute;
                        sj.Rule.RegularValue    = 5;
                        sj.Rule.Presentation    = Rule.GeneratePresentation(sj);
                        dbContext.SmartJobs.Add(sj);

                        //SmartJobs 8
                        sj                   = new SmartJob();
                        sj.Address           = "5kXTAm4wYJ6P1DLACk9ehUQEzjUKLHHBKA2EK1yinvz6";
                        sj.CreatedAt         = DateTime.Now;
                        sj.CreatedBy         = admin;
                        sj.CreditsNet        = dbContext.CreditsNets.FirstOrDefault(x => x.Name == "Test net");
                        sj.Events            = new List <JobEvent>();
                        sj.ExecutionMode     = SmartJob.ExecutionModeEnum.Once;
                        sj.IsActive          = true;
                        sj.Method            = "Method 8";
                        sj.Name              = "Задача 8";
                        sj.Rule              = new Rule();
                        sj.Rule.OnceDate     = "10.07.2019 05:05:19";
                        sj.Rule.Presentation = Rule.GeneratePresentation(sj);
                        dbContext.SmartJobs.Add(sj);

                        //SmartJobs 9
                        sj                     = new SmartJob();
                        sj.Address             = "5kXTAm4wYJ6P1DLACk9ehUQEzjUKLHHBKA2EK1yinvz6";
                        sj.CreatedAt           = DateTime.Now;
                        sj.CreatedBy           = admin;
                        sj.CreditsNet          = dbContext.CreditsNets.FirstOrDefault(x => x.Name == "Devs & dapps");
                        sj.Events              = new List <JobEvent>();
                        sj.ExecutionMode       = SmartJob.ExecutionModeEnum.CronExpression;
                        sj.IsActive            = false;
                        sj.Method              = "Method 9";
                        sj.Name                = "Задача 9";
                        sj.Rule                = new Rule();
                        sj.Rule.CronExpression = "0,13 0,55 0/7 5,16 * ? *";
                        sj.Rule.Presentation   = Rule.GeneratePresentation(sj);
                        dbContext.SmartJobs.Add(sj);

                        //10
                        sj                      = new SmartJob();
                        sj.Address              = "5kXTAm4wYJ6P1DLACk9ehUQEzjUKLHHBKA2EK1yinvz6";
                        sj.CreatedAt            = DateTime.Now;
                        sj.CreatedBy            = admin;
                        sj.CreditsNet           = dbContext.CreditsNets.FirstOrDefault(x => x.Name == "Credits network");
                        sj.Events               = new List <JobEvent>();
                        sj.ExecutionMode        = SmartJob.ExecutionModeEnum.Regular;
                        sj.IsActive             = true;
                        sj.Method               = "Method 10";
                        sj.Name                 = "Задача 10";
                        sj.Rule                 = new Rule();
                        sj.Rule.RegularDateFrom = "10.07.2019 05:05:19";
                        sj.Rule.RegularDateTo   = "31.07.2019 22:03:07";
                        sj.Rule.RegularPeriod   = PeriodEnum.Minute;
                        sj.Rule.RegularValue    = 5;
                        sj.Rule.Presentation    = Rule.GeneratePresentation(sj);
                        dbContext.SmartJobs.Add(sj);

                        //SmartJobs 11
                        sj                   = new SmartJob();
                        sj.Address           = "5kXTAm4wYJ6P1DLACk9ehUQEzjUKLHHBKA2EK1yinvz6";
                        sj.CreatedAt         = DateTime.Now;
                        sj.CreatedBy         = admin;
                        sj.CreditsNet        = dbContext.CreditsNets.FirstOrDefault(x => x.Name == "Test net");
                        sj.Events            = new List <JobEvent>();
                        sj.ExecutionMode     = SmartJob.ExecutionModeEnum.Once;
                        sj.IsActive          = true;
                        sj.Method            = "Method 11";
                        sj.Name              = "Задача 11";
                        sj.Rule              = new Rule();
                        sj.Rule.OnceDate     = "10.07.2019 05:05:19";
                        sj.Rule.Presentation = Rule.GeneratePresentation(sj);
                        dbContext.SmartJobs.Add(sj);

                        //SmartJobs 12
                        sj                     = new SmartJob();
                        sj.Address             = "5kXTAm4wYJ6P1DLACk9ehUQEzjUKLHHBKA2EK1yinvz6";
                        sj.CreatedAt           = DateTime.Now;
                        sj.CreatedBy           = admin;
                        sj.CreditsNet          = dbContext.CreditsNets.FirstOrDefault(x => x.Name == "Devs & dapps");
                        sj.Events              = new List <JobEvent>();
                        sj.ExecutionMode       = SmartJob.ExecutionModeEnum.CronExpression;
                        sj.IsActive            = false;
                        sj.Method              = "Method 12";
                        sj.Name                = "Задача 12";
                        sj.Rule                = new Rule();
                        sj.Rule.CronExpression = "0,13 0,55 0/7 5,16 * ? *";
                        sj.Rule.Presentation   = Rule.GeneratePresentation(sj);
                        dbContext.SmartJobs.Add(sj);

                        dbContext.SaveChanges();

                        var date = new DateTime(2019, 1, 1);
                        foreach (var sJob in dbContext.SmartJobs.ToList())
                        {
                            for (int i = 0; i < 45; i++)
                            {
                                var sEvent = new JobEvent()
                                {
                                    SmartJob     = sJob,
                                    IsSuccessed  = true,
                                    RequestDate  = date.AddMinutes(i),
                                    ResponseDate = date.AddMinutes(i).AddSeconds(i),
                                    Text         = "Ok!"
                                };

                                dbContext.JobEvents.Add(sEvent);
                                dbContext.SaveChanges();
                            }

                            date = date.AddHours(1);
                        }
                    }

            return(RedirectToAction("Index", "Home"));
        }