private void CreateHostRoleAndUsers()
        {
            //Admin role for host

            var adminRoleForHost = _context.Roles.FirstOrDefault(r => r.TenantId == null && r.Name == StaticRoleNames.Host.Admin);

            if (adminRoleForHost == null)
            {
                adminRoleForHost = _context.Roles.Add(new Role {
                    Name = StaticRoleNames.Host.Admin, DisplayName = StaticRoleNames.Host.Admin, IsStatic = true
                });
                _context.SaveChanges();

                //Grant all tenant permissions
                var permissions = PermissionFinder
                                  .GetAllPermissions(new DailyAuthorizationProvider())
                                  .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Host))
                                  .ToList();

                foreach (var permission in permissions)
                {
                    _context.Permissions.Add(
                        new RolePermissionSetting
                    {
                        Name      = permission.Name,
                        IsGranted = true,
                        RoleId    = adminRoleForHost.Id
                    });
                }

                _context.SaveChanges();
            }

            //Admin user for tenancy host

            var adminUserForHost = _context.Users.FirstOrDefault(u => u.TenantId == null && u.UserName == User.AdminUserName);

            if (adminUserForHost == null)
            {
                adminUserForHost = _context.Users.Add(
                    new User
                {
                    UserName         = User.AdminUserName,
                    Name             = "System",
                    Surname          = "Administrator",
                    EmailAddress     = "*****@*****.**",
                    IsEmailConfirmed = true,
                    Password         = new PasswordHasher().HashPassword(User.DefaultPassword)
                });

                _context.SaveChanges();

                _context.UserRoles.Add(new UserRole(null, adminUserForHost.Id, adminRoleForHost.Id));

                _context.SaveChanges();
            }
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "Id,CreateTime,Name,UpdateTime")] WorkUnit workUnit)
        {
            if (ModelState.IsValid)
            {
                db.WorkUnits.Add(workUnit);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(workUnit));
        }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "Id,ContractName,CreateTime,FullName,MobilePhone,Name,TelPhone,UpdateTime")] WorkTeam workTeam)
        {
            if (ModelState.IsValid)
            {
                db.WorkTeams.Add(workTeam);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(workTeam));
        }
        public ActionResult Create([Bind(Include = "Id,CreateTime,Decription,Name,UpdateTime")] Project project)
        {
            if (ModelState.IsValid)
            {
                db.Projects.Add(project);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(project));
        }
Beispiel #5
0
        public ActionResult Create([Bind(Include = "Id,CreateTime,Name,Position,ProjectId,Remark,UpdateTime")] WorkArea workArea)
        {
            if (ModelState.IsValid)
            {
                db.WorkAreas.Add(workArea);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ProjectId = new SelectList(db.Projects, "Id", "Decription", workArea.ProjectId);
            return(View(workArea));
        }
Beispiel #6
0
        public ActionResult Create([Bind(Include = "Id,CreateTime,Description,Name,ParentId,UpdateTime")] WorkType workType)
        {
            if (ModelState.IsValid)
            {
                db.WorkTypes.Add(workType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ParentId = new SelectList(db.WorkTypes, "Id", "Description", workType.ParentId);
            return(View(workType));
        }
        private void CreateRolesAndUsers()
        {
            //Admin role

            var adminRole = _context.Roles.FirstOrDefault(r => r.TenantId == _tenantId && r.Name == StaticRoleNames.Tenants.Admin);

            if (adminRole == null)
            {
                adminRole = _context.Roles.Add(new Role(_tenantId, StaticRoleNames.Tenants.Admin, StaticRoleNames.Tenants.Admin)
                {
                    IsStatic = true
                });
                _context.SaveChanges();

                //Grant all permissions to admin role
                var permissions = PermissionFinder
                                  .GetAllPermissions(new DailyAuthorizationProvider())
                                  .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Tenant))
                                  .ToList();

                foreach (var permission in permissions)
                {
                    _context.Permissions.Add(
                        new RolePermissionSetting
                    {
                        TenantId  = _tenantId,
                        Name      = permission.Name,
                        IsGranted = true,
                        RoleId    = adminRole.Id
                    });
                }

                _context.SaveChanges();
            }

            //admin user

            var adminUser = _context.Users.FirstOrDefault(u => u.TenantId == _tenantId && u.UserName == User.AdminUserName);

            if (adminUser == null)
            {
                adminUser = User.CreateTenantAdminUser(_tenantId, "*****@*****.**", User.DefaultPassword);
                adminUser.IsEmailConfirmed = true;
                adminUser.IsActive         = true;

                _context.Users.Add(adminUser);
                _context.SaveChanges();

                //Assign Admin role to admin user
                _context.UserRoles.Add(new UserRole(_tenantId, adminUser.Id, adminRole.Id));
                _context.SaveChanges();
            }
        }
        public ActionResult Create([Bind(Include = "Id,CreateTime,UpdateTime,WorkTypeId,WorkUnitId")] WorkTypeUnit workTypeUnit)
        {
            if (ModelState.IsValid)
            {
                db.WorkTypeUnits.Add(workTypeUnit);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.WorkTypeId = new SelectList(db.WorkTypes, "Id", "Name", workTypeUnit.WorkTypeId);
            ViewBag.WorkUnitId = new SelectList(db.WorkUnits, "Id", "Name", workTypeUnit.WorkUnitId);
            return(View(workTypeUnit));
        }
        public ActionResult Create([Bind(Include = "Id,Name,ParentId,Remark,WorkAreaId,WorkTypeId")] WorkItem workItem)
        {
            if (ModelState.IsValid)
            {
                db.WorkItems.Add(workItem);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ParentId   = new SelectList(db.WorkItems, "Id", "Name", workItem.ParentId);
            ViewBag.WorkAreaId = new SelectList(db.WorkAreas, "Id", "Name", workItem.WorkAreaId);
            ViewBag.WorkTypeId = new SelectList(db.WorkTypes, "Id", "Name", workItem.WorkTypeId);
            return(View(workItem));
        }
        public ActionResult Create([Bind(Include = "Id,WorkItemId,WorkTypeUnitId,WorkTeamId,Price,Remark,CreateTime,UpdateTime")] WorkItemPrice workItemPrice)
        {
            if (ModelState.IsValid)
            {
                db.WorkItemPrices.Add(workItemPrice);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.WorkItemId     = new SelectList(db.WorkItems, "Id", "Name", workItemPrice.WorkItemId);
            ViewBag.WorkTeamId     = new SelectList(db.WorkTeams, "Id", "Name", workItemPrice.WorkTeamId);
            ViewBag.WorkTypeUnitId = new SelectList(db.WorkTypeUnits, "Id", "Id", workItemPrice.WorkTypeUnitId);
            return(View(workItemPrice));
        }
        public ActionResult Create([Bind(Include = "CurrentDate,WorkItemId,WorkTeamId,WorkPrice,WorkUnitId,WorkQuantity,MixingStationId,OperatorId,Remark")] WorkItemProgress workItemProgress)
        {
            if (ModelState.IsValid)
            {
                db.WorkItemProgresses.Add(workItemProgress);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MixingStationId = new SelectList(db.ConcreteMixingStations, "Id", "Name", workItemProgress.MixingStationId);
            ViewBag.OperatorId      = new SelectList(db.Users, "Id", "Name", workItemProgress.OperatorId);
            ViewBag.WorkItemId      = new SelectList(db.WorkItems, "Id", "Name", workItemProgress.WorkItemId);
            ViewBag.WorkTeamId      = new SelectList(db.WorkTeams, "Id", "Name", workItemProgress.WorkTeamId);
            ViewBag.WorkUnitId      = new SelectList(db.WorkUnits, "Id", "Name", workItemProgress.WorkUnitId);

            return(View(workItemProgress));
        }
Beispiel #12
0
        private void AddSettingIfNotExists(string name, string value, int?tenantId = null)
        {
            if (_context.Settings.Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null))
            {
                return;
            }

            _context.Settings.Add(new Setting(tenantId, null, name, value));
            _context.SaveChanges();
        }
        private void AddLanguageIfNotExists(ApplicationLanguage language)
        {
            if (_context.Languages.Any(l => l.TenantId == language.TenantId && l.Name == language.Name))
            {
                return;
            }

            _context.Languages.Add(language);

            _context.SaveChanges();
        }
        private void CreateUserAndRoles()
        {
            //Default tenant

            var defaultTenant = _context.Tenants.FirstOrDefault(t => t.TenancyName == Tenant.DefaultTenantName);

            if (defaultTenant == null)
            {
                _context.Tenants.Add(new Tenant {
                    TenancyName = Tenant.DefaultTenantName, Name = Tenant.DefaultTenantName
                });
                _context.SaveChanges();
            }
        }
Beispiel #15
0
        private void CreateEditions()
        {
            var defaultEdition = _context.Editions.FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);

            if (defaultEdition == null)
            {
                defaultEdition = new Edition {
                    Name = EditionManager.DefaultEditionName, DisplayName = EditionManager.DefaultEditionName
                };
                _context.Editions.Add(defaultEdition);
                _context.SaveChanges();

                //TODO: Add desired features to the standard edition, if wanted!
            }
        }