public int CreateUserDashboardWidget(int userId, UserDashboardWidgetDto userDashboardWidget) { int userDashboardId; if (userDashboardWidget.PageId == null) { var newUserDashboard = new UserDashboard { UserId = userId, Name = userDashboardWidget.PageName }; _context.UserDashboard.Add(newUserDashboard); _context.SaveChanges(); userDashboardId = newUserDashboard.Id; } else { var existingUserDashboard = _context.UserDashboard.Include(x => x.UserDashboardWidgets) .FirstOrDefault(x => x.Id == userDashboardWidget.PageId); if (existingUserDashboard == null) { return(0); } userDashboardId = existingUserDashboard.Id; _context.UserDashboardWidget.RemoveRange(existingUserDashboard.UserDashboardWidgets); _context.SaveChanges(); } foreach (var item in from lgDto in userDashboardWidget.Item.Lg.ToList() let widgetName = userDashboardWidget.Widget.FirstOrDefault(w => w.IndexId == Convert.ToInt32(lgDto.I)) ?.Name let widgetId = _context.Widget.SingleOrDefault(x => x.Name == widgetName)?.Id select new UserDashboardWidget { CreatedAt = DateTime.Now, CreatedById = userId, Height = lgDto.H, Width = lgDto.W, XAxis = lgDto.X, YAxis = lgDto.Y, UserDashboardId = userDashboardId, WidgetId = widgetId, Index = lgDto.I }) { _context.UserDashboardWidget.Add(item); _context.SaveChanges(); } return(userDashboardId); }
public void Create() { new TestOrganizationUnitsBuilder(_context, _tenantId).Create(); new TestSubscriptionPaymentBuilder(_context, _tenantId).Create(); _context.SaveChanges(); }
public ActionResult SubCities_Create([DataSourceRequest] DataSourceRequest request, SubCity subCity) { if (ModelState.IsValid) { var entity = new SubCity { Name = subCity.Name, Code = subCity.Code }; db.SubCities.Add(entity); db.SaveChanges(); subCity.SubCityId = entity.SubCityId; } return(Json(new[] { subCity }.ToDataSourceResult(request, ModelState))); }
public IActionResult About() { var s = HttpContext.Session.GetString("testsession"); //事务操作 using (var context = new TradeDbContext(_serviceProvider.GetRequiredService <DbContextOptions <TradeDbContext> >())) { Guid departmentId = Guid.NewGuid(); //增加一个部门 context.Departments.Add( new Vic.Core.Domain.Entities.Department { ID = departmentId, Code = "BD", Name = "商务部", ParentId = Guid.Empty } ); context.Roles.Add(new Vic.Core.Domain.Entities.Role() { ID = Guid.NewGuid(), Code = "Aduit", CreateTime = DateTime.Now, Name = "认证员", Remarks = "认证员" }); //增加一个超级管理员用户 context.Users.Add( new Vic.Core.Domain.Entities.User { UserName = "******", Password = "******", //暂不进行加密 Name = "管理员", DepartmentId = departmentId } ); context.CustomerUser.Add(new Vic.Core.Domain.Entities.CustomerUser() { Mobile = "13430932507", AuthenticationVerify = 1, VerifyResult = 0, NickName = "VIC", RealName = "VIC LI", Type = 1, Status = 1, PassWord = "******", TPassWord = "******", CreatorID = Vic.Core.Utils.ConstDefine.SuperAdminID }); context.SaveChanges(); } ViewData["Message"] = "Your application description page."; return(View()); }
public void Create() { new DefaultEditionCreator(_context).Create(); new DefaultLanguagesCreator(_context).Create(); new HostRoleAndUserCreator(_context).Create(); new DefaultSettingsCreator(_context).Create(); _context.SaveChanges(); }
private void AddSettingIfNotExists(string name, string value, int?tenantId = null) { if (_context.Settings.IgnoreQueryFilters().Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null)) { return; } _context.Settings.Add(new Setting(tenantId, null, name, value)); _context.SaveChanges(); }
public ActionResult UnitOfMeasurements_Create([DataSourceRequest] DataSourceRequest request, UnitOfMeasurement unitOfMeasurement) { if (ModelState.IsValid) { var entity = new UnitOfMeasurement { Name = unitOfMeasurement.Name, Code = unitOfMeasurement.Code, Symbol = unitOfMeasurement.Symbol, Weight = unitOfMeasurement.Weight }; db.UnitOfMeasurements.Add(entity); db.SaveChanges(); unitOfMeasurement.UnitOfMeasurementId = entity.UnitOfMeasurementId; } return(Json(new[] { unitOfMeasurement }.ToDataSourceResult(request, ModelState))); }
public ActionResult CommodityCategories_Create([DataSourceRequest] DataSourceRequest request, CommodityCategory commodityCategory) { if (ModelState.IsValid) { var entity = new CommodityCategory { Name = commodityCategory.Name, Code = commodityCategory.Code, Description = commodityCategory.Description, Remark = commodityCategory.Remark }; db.CommodityCategories.Add(entity); db.SaveChanges(); commodityCategory.CommodityCategoryId = entity.CommodityCategoryId; } return(Json(new[] { commodityCategory }.ToDataSourceResult(request, ModelState))); }
private OrganizationUnit CreateOU(string displayName, string code, long?parentId = null) { var ou = _context.OrganizationUnits.Add(new OrganizationUnit(_tenantId, displayName, parentId) { Code = code }).Entity; _context.SaveChanges(); return(ou); }
public ActionResult Commodities_Create([DataSourceRequest] DataSourceRequest request, Commodity commodity) { if (ModelState.IsValid) { var entity = new Commodity { Name = commodity.Name, Code = commodity.Code, UnitOfMeasurementId = commodity.UnitOfMeasurementId, CommodityCategoryId = commodity.CommodityCategoryId }; db.Commodities.Add(entity); db.SaveChanges(); commodity.CommodityId = entity.CommodityId; } return(Json(new[] { commodity }.ToDataSourceResult(request, ModelState))); }
public ActionResult Weredas_Create([DataSourceRequest] DataSourceRequest request, Wereda wereda) { if (ModelState.IsValid) { var entity = new Wereda { Code = wereda.Code, Name = wereda.Name, SubcityId = wereda.SubcityId, Description = wereda.Description, Remark = wereda.Remark }; db.Weredas.Add(entity); db.SaveChanges(); wereda.WeredaId = entity.WeredaId; } return(Json(new[] { wereda }.ToDataSourceResult(request, ModelState))); }
private void AddLanguageIfNotExists(ApplicationLanguage language) { if (_context.Languages.IgnoreQueryFilters().Any(l => l.TenantId == language.TenantId && l.Name == language.Name)) { return; } _context.Languages.Add(language); _context.SaveChanges(); }
public ActionResult Markets_Create([DataSourceRequest] DataSourceRequest request, Market market) { if (ModelState.IsValid) { var entity = new Market { Name = market.Name, Code = market.Code, WeredaId = market.WeredaId, SubcityId = market.SubcityId, Description = market.Description, Remark = market.Remark }; db.Markets.Add(entity); db.SaveChanges(); market.MarketId = entity.MarketId; } return(Json(new[] { market }.ToDataSourceResult(request, ModelState))); }
public IActionResult Delete(int id) { var tag = _context.Tags.Find(id); if (tag == null) { return(NotFound()); } _context.Tags.Remove(tag); _context.SaveChanges(); return(Ok()); }
private SubscriptionPayment CreatePayment(decimal amount, int editionId, int tenantId, int dayCount, string paymentId) { var payment = _context.SubscriptionPayments.Add(new SubscriptionPayment { Amount = amount, EditionId = editionId, TenantId = tenantId, DayCount = dayCount, PaymentId = paymentId }).Entity; _context.SaveChanges(); return(payment); }
private void CreateDefaultTenant() { //Default tenant var defaultTenant = _context.Tenants.IgnoreQueryFilters().FirstOrDefault(t => t.TenancyName == MultiTenancy.Tenant.DefaultTenantName); if (defaultTenant == null) { defaultTenant = new MultiTenancy.Tenant(AbpTenantBase.DefaultTenantName, AbpTenantBase.DefaultTenantName); var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName); if (defaultEdition != null) { defaultTenant.EditionId = defaultEdition.Id; } _context.Tenants.Add(defaultTenant); _context.SaveChanges(); } }
private void CreateEditions() { var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName); if (defaultEdition == null) { defaultEdition = new SubscribableEdition { Name = EditionManager.DefaultEditionName, DisplayName = EditionManager.DefaultEditionName }; _context.Editions.Add(defaultEdition); _context.SaveChanges(); /* Add desired features to the standard edition, if wanted... */ } #if FEATURE_SIGNALR if (defaultEdition.Id > 0) { CreateFeatureIfNotExists(defaultEdition.Id, AppFeatures.ChatFeature, true); CreateFeatureIfNotExists(defaultEdition.Id, AppFeatures.TenantToTenantChatFeature, true); CreateFeatureIfNotExists(defaultEdition.Id, AppFeatures.TenantToHostChatFeature, true); } #endif }
private void CreateHostRoleAndUsers() { //Admin role for host var adminRoleForHost = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == null && r.Name == StaticRoleNames.Host.Admin); if (adminRoleForHost == null) { adminRoleForHost = _context.Roles.Add(new Role(null, StaticRoleNames.Host.Admin, StaticRoleNames.Host.Admin) { IsStatic = true, IsDefault = true }).Entity; _context.SaveChanges(); } //admin user for host var adminUserForHost = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == null && u.UserName == AbpUserBase.AdminUserName); if (adminUserForHost == null) { var user = new User { TenantId = null, UserName = AbpUserBase.AdminUserName, Name = "admin", Surname = "admin", EmailAddress = "*****@*****.**", IsEmailConfirmed = true, ShouldChangePasswordOnNextLogin = true, IsActive = true, Password = "******" //123qwe }; user.SetNormalizedNames(); adminUserForHost = _context.Users.Add(user).Entity; _context.SaveChanges(); //Assign Admin role to admin user _context.UserRoles.Add(new UserRole(null, adminUserForHost.Id, adminRoleForHost.Id)); _context.SaveChanges(); //Grant all permissions var permissions = PermissionFinder .GetAllPermissions(new AppAuthorizationProvider(true)) .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Host)) .ToList(); foreach (var permission in permissions) { _context.Permissions.Add( new RolePermissionSetting { TenantId = null, Name = permission.Name, IsGranted = true, RoleId = adminRoleForHost.Id }); } _context.SaveChanges(); //User account of admin user _context.UserAccounts.Add(new UserAccount { TenantId = null, UserId = adminUserForHost.Id, UserName = AbpUserBase.AdminUserName, EmailAddress = adminUserForHost.EmailAddress }); _context.SaveChanges(); //Notification subscriptions _context.NotificationSubscriptions.Add(new NotificationSubscriptionInfo(SequentialGuidGenerator.Instance.Create(), null, adminUserForHost.Id, AppNotificationNames.NewTenantRegistered)); _context.NotificationSubscriptions.Add(new NotificationSubscriptionInfo(SequentialGuidGenerator.Instance.Create(), null, adminUserForHost.Id, AppNotificationNames.NewUserRegistered)); _context.SaveChanges(); } }
private void CreateRolesAndUsers() { //Admin role var adminRole = _context.Roles.IgnoreQueryFilters().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 }).Entity; _context.SaveChanges(); //Grant all permissions to admin role var permissions = PermissionFinder .GetAllPermissions(new AppAuthorizationProvider(false)) .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(); } //User role var userRole = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == _tenantId && r.Name == StaticRoleNames.Tenants.User); if (userRole == null) { _context.Roles.Add(new Role(_tenantId, StaticRoleNames.Tenants.User, StaticRoleNames.Tenants.User) { IsStatic = true, IsDefault = true }); _context.SaveChanges(); } //admin user var adminUser = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == _tenantId && u.UserName == AbpUserBase.AdminUserName); if (adminUser == null) { adminUser = User.CreateTenantAdminUser(_tenantId, "*****@*****.**"); adminUser.Password = new PasswordHasher <User>(new OptionsWrapper <PasswordHasherOptions>(new PasswordHasherOptions())).HashPassword(adminUser, "123qwe"); adminUser.IsEmailConfirmed = true; adminUser.ShouldChangePasswordOnNextLogin = 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(); //User account of admin user if (_tenantId == 1) { _context.UserAccounts.Add(new UserAccount { TenantId = _tenantId, UserId = adminUser.Id, UserName = AbpUserBase.AdminUserName, EmailAddress = adminUser.EmailAddress }); _context.SaveChanges(); } //Notification subscription _context.NotificationSubscriptions.Add(new NotificationSubscriptionInfo(SequentialGuidGenerator.Instance.Create(), _tenantId, adminUser.Id, AppNotificationNames.NewUserRegistered)); _context.SaveChanges(); } }