Ejemplo n.º 1
0
        public async Task CreateTenant(CreateJournalModel model, Stream stream, string journalLogo)
        {
            var roleIds = _applicationDbContext.Roles.Where(x => x.Name == Role.Admin.ToString() || x.Name == Role.JournalAdmin.ToString()).Select(x => x.Id);
            var tenant  = new Tenant {
                JournalName = model.JournalName, JournalPath = model.JournalPath, JournalTitle = model.JournalTitle, IsDisabled = !model.IsActive
            };

            _configuration.GetSection("ArticleComponent");
            var articleComponents = _configuration.GetSection("ArticleComponent").GetChildren().Select(x => x.Value).ToArray();

            using (var transaction = _applicationDbContext.Database.BeginTransaction())
            {
                try
                {
                    _applicationDbContext.Tenants.Add(tenant);
                    var path = _fileService.SaveFile(stream, journalLogo);
                    tenant.JournalLogo = path;
                    var user = new ApplicationUser {
                        UserName = model.Email, Email = model.Email, PhoneNumber = _maskService.RemovePhoneMasking(model.PhoneNumber), FirstName = model.FirstName, LastName = model.LastName, Tenant = tenant, EmailConfirmed = true
                    };
                    await _userManager.CreateAsync(user);

                    foreach (var roleId in roleIds)
                    {
                        _applicationDbContext.UserRoles.Add(new IdentityUserRole <long> {
                            RoleId = roleId, UserId = user.Id
                        });
                    }
                    for (int i = 0; i < articleComponents.Length; i++)
                    {
                        _applicationDbContext.TenantArticleComponent.Add(new TenantArticleComponent
                        {
                            Order  = i + 1,
                            Text   = articleComponents[i],
                            Tenant = tenant
                        });
                    }
                    _applicationDbContext.SaveChanges();

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
        public void SaveSystemAdmin(SystemAdminProfileModel systemAdminProfileModel, Stream fileStream, string fileName)
        {
            var user = GetUser(systemAdminProfileModel.UserId);

            user.FirstName     = systemAdminProfileModel.FirstName;
            user.LastName      = systemAdminProfileModel.LastName;
            user.PhoneNumber   = _maskService.RemovePhoneMasking(systemAdminProfileModel.PhoneNumber);
            user.Country       = systemAdminProfileModel.Country;
            user.City          = systemAdminProfileModel.City;
            user.State         = systemAdminProfileModel.State;
            user.Zip           = systemAdminProfileModel.Zip;
            user.AffiliationNo = systemAdminProfileModel.AffiliationNo;
            string oldImgFile = user.ProfileImage;

            if (fileStream != null && !string.IsNullOrEmpty(fileName))
            {
                user.ProfileImage = _fileService.SaveFile(fileStream, fileName);
            }
            _context.SaveChanges();
            if (fileStream != null && !string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(oldImgFile))
            {
                _fileService.RemoveFile(oldImgFile);
            }
        }