Пример #1
0
 public void Insert(Employee Emp)
 {
     Emp.IsActive  = true;
     Emp.IsDeleted = false;
     Emp.CreatedOn = System.DateTime.Now.Date.ToString("dd/MM/yyyy");
     db.Employees.Add(Emp);
     db.SaveChanges();
 }
Пример #2
0
 public void Delete(TEntity entity)
 {
     if (_dbContext.Entry(entity).State == EntityState.Detached)
     {
         _dbSet.Attach(entity);
     }
     _dbSet.Remove(entity);
     _dbContext.SaveChanges();
 }
Пример #3
0
        private void CreateEditions()
        {
            var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);

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

                /* Add desired features to the standard edition, if wanted... */
            }
        }
        public async Task <IActionResult> ConfirmEmail(string userId, string code)
        {
            if (userId == null || code == null)
            {
                return(RedirectToAction(nameof(HomeController.Index), "Home"));
            }
            var user = await _userManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(new RedirectResult(Url.Action("ConfirmationError", "BeyeuBookstore")));
            }
            var result = await _userManager.ConfirmEmailAsync(user, code);

            if (result.Succeeded)
            {
                user.Status = Data.Enums.Status.Active;
                await _userService.UpdateAsync(Mapper.Map <User, UserViewModel>(user));

                await _userManager.AddToRoleAsync(user, "Khách hàng"); // add vao role

                var customer = new Customer();
                customer.UserFK = user.Id;
                _context.Customers.Add(customer);
                _context.SaveChanges();
            }
            return(new RedirectResult(Url.Action("Index", "BeyeuBookstore")));
        }
        public async Task <IActionResult> Register(RegisterViewModel model, UserViewModel userViewModel, AdvertiserViewModel advertiserViewModel, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new Data.Entities.User
                {
                    UserName     = model.Email,
                    Email        = model.Email,
                    FullName     = userViewModel.FullName,
                    Address      = userViewModel.Address,
                    DateCreated  = DateTime.Now,
                    DateModified = DateTime.Now,
                    PhoneNumber  = userViewModel.PhoneNumber,
                    Gender       = Data.Enums.Gender.Other,
                    Status       = Data.Enums.Status.InActive,
                    UserTypeFK   = Const_UserType.Advertiser,
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme, nameof(AccountController.ConfirmEmail), "Advertiser");

                    var content = "Hãy nhấp vào link này để xác nhận tài khoản quảng cáo Bé Yêu Bookstore: " + callbackUrl;

                    SendConfirmEmail(model.Email, content);
                    //await _signInManager.SignInAsync(user, isPersistent: false);
                    //await _userManager.AddToRoleAsync(user, "Quảng cáo"); // add vao role
                    var advertiser = new Advertiser();
                    advertiser.UserFK     = user.Id;
                    advertiser.BrandName  = advertiserViewModel.BrandName;
                    advertiser.UrlToBrand = advertiserViewModel.UrlToBrand;
                    await _userManager.AddToRoleAsync(user, "Quảng cáo"); // add vao role

                    _context.Advertisers.Add(advertiser);
                    _context.SaveChanges();

                    return(new RedirectResult(Url.Action("WaitingConfirmation", "BeyeuBookstore")));
                }
            }

            // If we got this far, something failed, redisplay form
            return(new RedirectResult(Url.Action("SignUp", "BeyeuBookstore")));
        }
        public void Create()
        {
            new TestOrganizationUnitsBuilder(_context, _tenantId).Create();
            new TestSubscriptionPaymentBuilder(_context, _tenantId).Create();
            new TestEditionsBuilder(_context).Create();

            _context.SaveChanges();
        }
Пример #7
0
        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();
        }
Пример #9
0
        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();
        }
        private OrganizationUnit CreateOrganizationUnit(string displayName, string code, long?parentId = null)
        {
            var organizationUnit = _context.OrganizationUnits.Add(new OrganizationUnit(_tenantId, displayName, parentId)
            {
                Code = code
            }).Entity;

            _context.SaveChanges();

            return(organizationUnit);
        }
Пример #11
0
        private void CreateDefaultTenant()
        {
            // Default tenant

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

            if (defaultTenant == null)
            {
                defaultTenant = new 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();
            }
        }
Пример #12
0
        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 (defaultEdition.Id > 0)
            {
                CreateFeatureIfNotExists(defaultEdition.Id, AppFeatures.ChatFeature, true);
                CreateFeatureIfNotExists(defaultEdition.Id, AppFeatures.TenantToTenantChatFeature, true);
                CreateFeatureIfNotExists(defaultEdition.Id, AppFeatures.TenantToHostChatFeature, true);
            }
        }
        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();
            }

            //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 = false;
                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();
            }
        }
        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 = false,
                    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();

                //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();
            }
        }
Пример #15
0
 public void Insert(Department Emp)
 {
     db.Departments.Add(Emp);
     db.SaveChanges();
 }
 public void Insert(JobHistory Jobs)
 {
     db.JobHistories.Add(Jobs);
     db.SaveChanges();
 }
Пример #17
0
 public void Insert(Job Jobs)
 {
     db.Jobs.Add(Jobs);
     db.SaveChanges();
 }
Пример #18
0
 public void Add(Provider Provider)
 {
     _dbContext.Providers.Add(Provider);
     _dbContext.SaveChanges();
 }
Пример #19
0
 public void Add(Client client)
 {
     _dbContext.Clients.Add(client);
     _dbContext.SaveChanges();
 }
 public void Add(MaterialDiscount MaterialDiscount)
 {
     _dbContext.MaterialDiscounts.Add(MaterialDiscount);
     _dbContext.SaveChanges();
 }
 public void Add(ClientDiscount ClientDiscount)
 {
     _dbContext.ClientDiscounts.Add(ClientDiscount);
     _dbContext.SaveChanges();
 }
Пример #22
0
 public void Add(Material Material)
 {
     _dbContext.Materials.Add(Material);
     _dbContext.SaveChanges();
 }
 public void Add(WarehouseStatus WarehouseStatus)
 {
     _dbContext.WarehouseStatuses.Add(WarehouseStatus);
     _dbContext.SaveChanges();
 }
        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();
            }

            // Grant all permissions to admin role for host

            var grantedPermissions = _context.Permissions.IgnoreQueryFilters()
                                     .OfType <RolePermissionSetting>()
                                     .Where(p => p.TenantId == null && p.RoleId == adminRoleForHost.Id)
                                     .Select(p => p.Name)
                                     .ToList();

            var permissions = PermissionFinder
                              .GetAllPermissions(new ERPAuthorizationProvider())
                              .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Host) &&
                                     !grantedPermissions.Contains(p.Name))
                              .ToList();

            if (permissions.Any())
            {
                _context.Permissions.AddRange(
                    permissions.Select(permission => new RolePermissionSetting
                {
                    TenantId  = null,
                    Name      = permission.Name,
                    IsGranted = true,
                    RoleId    = adminRoleForHost.Id
                })
                    );
                _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,
                    IsActive         = true
                };

                user.Password = new PasswordHasher <User>(new OptionsWrapper <PasswordHasherOptions>(new PasswordHasherOptions())).HashPassword(user, "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();

                _context.SaveChanges();
            }
        }
Пример #25
0
 public void Add(Invoice invoice)
 {
     _dbContext.Invoice.Add(invoice);
     _dbContext.SaveChanges();
 }
Пример #26
0
 public void Add(Order Order)
 {
     _dbContext.Orders.Add(Order);
     _dbContext.SaveChanges();
 }
Пример #27
0
 public void Add(Seller seller)
 {
     _dbContext.Sellers.Add(seller);
     _dbContext.SaveChanges();
 }
Пример #28
0
        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 grantedPermissions = _context.Permissions.IgnoreQueryFilters()
                                     .OfType <RolePermissionSetting>()
                                     .Where(p => p.TenantId == _tenantId && p.RoleId == adminRole.Id)
                                     .Select(p => p.Name)
                                     .ToList();

            var permissions = PermissionFinder
                              .GetAllPermissions(new ERPAuthorizationProvider())
                              .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Tenant) &&
                                     !grantedPermissions.Contains(p.Name))
                              .ToList();

            if (permissions.Any())
            {
                _context.Permissions.AddRange(
                    permissions.Select(permission => new RolePermissionSetting
                {
                    TenantId  = _tenantId,
                    Name      = permission.Name,
                    IsGranted = true,
                    RoleId    = adminRole.Id
                })
                    );
                _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.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();
            }
        }