Пример #1
0
        public ActionResult Index()
        {
            var existing = _context.Employees.ToList();

            foreach (var employee in existing)
            {
                _context.Employees.Remove(employee);
            }

            _context.SaveChanges();

            // Without Managers
            var users = _context.Users.Where(u => u.ReportingPersonId == null).ToList();

            SaveEmployees(users);

            for (int i = 0; i < 70; i++)
            {
                // With Managers
                var subEmployees = _context.Users.Where(u => u.ReportingPersonId == i).ToList();
                SaveEmployees(subEmployees);
            }

            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public ActionResult Create(ScheduledJobViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var jobInfo = new JobInfoModel
                {
                    JobType        = "Scheduled",
                    CronExpression = vm.CronExpression,
                    Url            = vm.Url
                };

                var newScheduledJob = new ScheduledJob
                {
                    Name    = vm.Name,
                    JobInfo = JsonConvert.SerializeObject(jobInfo)
                };

                _db.ScheduledJobs.Add(newScheduledJob);
                _db.SaveChanges();

                try
                {
                    // Create Hangfire Job
                    RecurringJob.AddOrUpdate(vm.Name, () => WebClientHelper.InvokeUrl(vm.Url), vm.CronExpression);
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex) {
                    ViewBag.jobException = "Invalid cron expression";
                }
            }

            return(View(vm));
        }
Пример #3
0
        public ActionResult SeedEmailTemplates(Tenant tenant)
        {
            var selectedTenant = db.Tenants.Find(tenant.Id);

            if (selectedTenant != null)
            {
                var connectionString = selectedTenant.ConnectionString;
                if (!string.IsNullOrEmpty(connectionString))
                {
                    using (var tenantContext = new TenantDataContext())
                    {
                        var emailTemplates = tenantContext.EmailTemplates.ToList();

                        using (var context = new GridDataContext(connectionString))
                        {
                            // Select Admin as the Creator
                            var selectedUser = context.Users.FirstOrDefault(u => u.Username == selectedTenant.Email);

                            if (selectedUser != null)
                            {
                                foreach (var emailTemplate in emailTemplates)
                                {
                                    context.EmailTemplates.Add(new Entities.Company.EmailTemplate
                                    {
                                        Name            = emailTemplate.Name,
                                        Content         = emailTemplate.Content,
                                        CreatedOn       = DateTime.UtcNow,
                                        CreatedByUserId = selectedUser.Id
                                    });
                                }
                            }

                            context.SaveChanges();

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

            return(View(tenant));
        }
Пример #4
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var fileDialog = new OpenFileDialog();
            var result     = fileDialog.ShowDialog();

            if (result.GetValueOrDefault())
            {
                var fileName     = fileDialog.FileName;
                var fileContents = File.ReadAllLines(fileName);
                foreach (var line in fileContents)
                {
                    try
                    {
                        var columns = line.Split(',');

                        var newPerson = new Person();

                        if (!string.IsNullOrEmpty(columns[0]))
                        {
                            var names = columns[0].Trim().Split(' ');
                            switch (names.Length)
                            {
                            case 1:
                                newPerson.FirstName = names[0];
                                break;

                            case 2:
                                newPerson.FirstName = names[0];
                                newPerson.LastName  = names[1];
                                break;

                            default:
                                if (names.Length > 2)
                                {
                                    newPerson.FirstName  = names[0];
                                    newPerson.LastName   = names[names.Length - 1];
                                    newPerson.MiddleName = string.Join(" ", names.ToArray(), 1, names.Length - 2);
                                }
                                break;
                            }
                        }

                        if (!string.IsNullOrEmpty(columns[1]))
                        {
                            newPerson.Designation = columns[1].Trim();
                        }

                        if (!string.IsNullOrEmpty(columns[2]))
                        {
                            newPerson.Email = columns[2].Trim().ToLower();
                        }



                        _db.Persons.Add(newPerson);

                        var newCandidate = new Candidate
                        {
                            Source          = CandidatesSource.Unknown,
                            Status          = CandidateStatus.New,
                            PersonId        = newPerson.Id,
                            CreatedByUserId = 1
                        };

                        _db.Candidates.Add(newCandidate);

                        _db.SaveChanges();
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
Пример #5
0
        public ActionResult Seed(Tenant tenant)
        {
            var selectedTenant = db.Tenants.Find(tenant.Id);

            if (selectedTenant != null)
            {
                var connectionString = selectedTenant.ConnectionString;
                if (!string.IsNullOrEmpty(connectionString))
                {
                    using (var context = new GridDataContext(connectionString))
                    {
                        var accessRule = AccessRule.CreateNewUserAccessRule(true);
                        context.AccessRules.Add(accessRule);
                        context.SaveChanges();

                        var person = new Person();
                        context.Persons.Add(person);
                        context.SaveChanges();

                        var manageCompany = new Permission {
                            Title = "Manage Company", PermissionCode = 200
                        };
                        context.Permissions.Add(manageCompany);
                        var manageHRMS = new Permission {
                            Title = "Manage HRMS", PermissionCode = 210
                        };
                        context.Permissions.Add(manageHRMS);
                        var manageSales = new Permission {
                            Title = "Manage Sales", PermissionCode = 220
                        };
                        context.Permissions.Add(manageSales);
                        var manageIT = new Permission {
                            Title = "Manage IT", PermissionCode = 230
                        };
                        context.Permissions.Add(manageIT);
                        var managePMS = new Permission {
                            Title = "Manage PMS", PermissionCode = 240
                        };
                        context.Permissions.Add(managePMS);
                        var manageInventory = new Permission {
                            Title = "Manage Inventory", PermissionCode = 250
                        };
                        context.Permissions.Add(manageInventory);
                        var manageLMS = new Permission {
                            Title = "Manage LMS", PermissionCode = 215
                        };
                        context.Permissions.Add(manageLMS);
                        var manageTimeSheet = new Permission {
                            Title = "Manage TimeSheet", PermissionCode = 300
                        };
                        context.Permissions.Add(manageTimeSheet);
                        var manageRecruit = new Permission {
                            Title = "Manage Recruit", PermissionCode = 500
                        };
                        context.Permissions.Add(manageRecruit);
                        var superPermission = new Permission {
                            Title = "Super Permission", PermissionCode = 9999
                        };
                        context.Permissions.Add(superPermission);
                        var manageTMS = new Permission {
                            Title = "Manage TMS", PermissionCode = 550
                        };
                        context.Permissions.Add(manageTMS);
                        var manageKBS = new Permission {
                            Title = "Manage KBS", PermissionCode = 700
                        };
                        context.Permissions.Add(manageKBS);
                        var viewSettings = new Permission {
                            Title = "View Settings", PermissionCode = 909
                        };
                        context.Permissions.Add(viewSettings);
                        var manageCRM = new Permission {
                            Title = "Manage CRM", PermissionCode = 222
                        };
                        context.Permissions.Add(manageCRM);
                        var manageTicketDesk = new Permission {
                            Title = "Manage Ticket Desk", PermissionCode = 1100
                        };
                        context.Permissions.Add(manageTicketDesk);
                        context.SaveChanges();

                        var adminRole = new Role {
                            Name = "Admin"
                        };
                        context.Roles.Add(adminRole);
                        context.SaveChanges();

                        // Role Permission Mapping
                        var permissions = context.Permissions.ToList();
                        foreach (var permission in permissions)
                        {
                            var newMap = new RolePermission
                            {
                                RoleId       = adminRole.Id,
                                PermissionId = permission.Id
                            };

                            context.RolePermissions.Add(newMap);
                        }
                        context.SaveChanges();

                        // Create User
                        var user = new User
                        {
                            EmployeeCode = "Code",
                            Username     = selectedTenant.Email,
                            Password     = HashHelper.Hash("123456"),
                            AccessRuleId = accessRule.Id,
                            PersonId     = person.Id
                        };

                        context.Users.Add(user);
                        context.SaveChanges();

                        // Role Member Mapping
                        var newMember = new RoleMember
                        {
                            RoleId = adminRole.Id,
                            UserId = user.Id
                        };

                        context.RoleMembers.Add(newMember);
                        context.SaveChanges();

                        return(RedirectToAction("Index"));
                    }
                }
            }
            return(View(tenant));
        }