public void SetUp()
 {
     var repo = new TenantXmlRepository(App.Path + "\\Tenant.Config");
     var service = new TenantService(repo);
     _tenant = service.GetByHostHeader("www.ms121.com");
     Assert.IsNotNull(_tenant, "Tenant should never be null!");
 }
Example #2
0
        public ActionResult Create(TenantCreate model)
        {
            TenantService svc = CreateTenantService();

            svc.CreateTenant(model);

            return(RedirectToAction("Index"));
        }
Example #3
0
        public void SetUp()
        {
            var repo    = new TenantXmlRepository(App.Path + "\\Tenant.Config");
            var service = new TenantService(repo);

            _tenant = service.GetByHostHeader("www.ms121.com");
            Assert.IsNotNull(_tenant, "Tenant should never be null!");
        }
Example #4
0
        public void Configure(string name, TenantManager options)
        {
            Configure(options);

            options.TenantService = TenantService.Get(name);
            options.QuotaService  = QuotaService.Get(name);
            options.TariffService = TariffService.Get(name);
        }
Example #5
0
 public List <Tenant> FindTenants(string login, string passwordHash)
 {
     if (!string.IsNullOrEmpty(passwordHash) && UserService.GetUserByPasswordHash(Tenant.DEFAULT_TENANT, login, passwordHash) == null)
     {
         throw new SecurityException("Invalid login or password.");
     }
     return(TenantService.GetTenants(login, passwordHash).Select(AddRegion).ToList());
 }
Example #6
0
        public ActionResult MyRentalApplications(RentalAppSearchModel model)
        {
            var user  = User.Identity.Name;
            var login = AccountService.GetLoginByEmail(user);

            if (String.IsNullOrWhiteSpace(model.SortOrder))
            {
                model.SortOrder = "Latest Date";
            }
            if (model.RentalStatus == null)
            {
                model.RentalStatus = Service.Models.RentalApplicationStatus.Applied;
            }
            var res = TenantService.GetAllRentApplications(model, login);

            model.PagedInput = new PagedInput
            {
                ActionName      = "MyRentalApplications",
                ControllerName  = "Home",
                PagedLinkValues = new RouteValueDictionary(new { SortOrder = model.SortOrder, SearchString = model.SearchString, RentalStatus = model.RentalStatus })
            };
            var rvr        = new RouteValueDictionary(new { SearchString = model.SearchString, RentalStatus = model.RentalStatus });
            var sortOrders = new List <SortOrderModel>();

            sortOrders.Add(new SortOrderModel {
                SortOrder = "Lowest Rent", ActionName = "MyRentalApplications", RouteValues = rvr.AddRouteValue("SortOrder", "Lowest Rent")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "Highest Rent", ActionName = "MyRentalApplications", RouteValues = rvr.AddRouteValue("SortOrder", "Highest Rent")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "Earliest Date", ActionName = "MyRentalApplications", RouteValues = rvr.AddRouteValue("SortOrder", "Earliest Date")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "Latest Date", ActionName = "MyRentalApplications", RouteValues = rvr.AddRouteValue("SortOrder", "Latest Date")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "Earliest Available", ActionName = "MyRentalApplications", RouteValues = rvr.AddRouteValue("SortOrder", "Earliest Available")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "Latest Available", ActionName = "MyRentalApplications", RouteValues = rvr.AddRouteValue("SortOrder", "Latest Available")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "Accepted First", ActionName = "MyRentalApplications", RouteValues = rvr.AddRouteValue("SortOrder", "Accepted First")
            });
            model.SortOrders  = sortOrders;
            model.SearchCount = res.SearchCount;
            if (String.IsNullOrWhiteSpace(model.SearchString))
            {
                model.Page = 1;
            }
            model.PageCount         = res.Items.PageCount;
            model.Items             = res.Items;
            model.EditUrl           = "/Tenants/Home/EditTenancyApplication";
            model.DeleteUrl         = "/Tenants/Home/DeleteTenancyApplication";
            TempData["CurrentLink"] = "MyRentApps";
            return(View(model));
        }
Example #7
0
        public MongoDbContext(TenantService <Tenant> tenantService)
        {
            _tenantService = tenantService;
            var            tenant   = _tenantService.GetTenantAsync().GetAwaiter().GetResult();
            MongoClient    client   = new MongoClient(tenant.ConnectionString);
            IMongoDatabase database = client.GetDatabase(tenant.Database);

            entities = database.GetCollection <T>(typeof(T).Name);
        }
Example #8
0
        public AddLeaseWindow(LeaseService leaseService, TenantService tenantService, PropertyService propertyService,
                              AppSettings appSettings)
        {
            SetupStructure(leaseService, appSettings);
            InitializeComponent();

            PropertyCBox.ItemsSource = propertyService.Properties;
            TenantCBox.ItemsSource   = tenantService.Tenants;
            MonthsBox.Text           = _minLeaseMonths.ToString();
        }
        public List <Tenant> FindTenants(string login, string password)
        {
            var hash = !string.IsNullOrEmpty(password) ? Hasher.Base64Hash(password, HashAlg.SHA256) : null;

            if (hash != null && UserService.GetUser(Tenant.DEFAULT_TENANT, login, hash) == null)
            {
                throw new SecurityException("Invalid login or password.");
            }
            return(TenantService.GetTenants(login, hash).Select(AddRegion).ToList());
        }
Example #10
0
        public ActionResult Edit(int id)
        {
            TenantService tenantsvc = new TenantService(Guid.Parse(User.Identity.GetUserId()));

            ViewBag.TenantId = new SelectList(tenantsvc.GetTenants(), "TenantId", "DisplayName");
            PropertyService svc    = CreatePropertyService();
            Property        toEdit = svc.GetPropertyById(id);

            return(View(toEdit));
        }
Example #11
0
        public async Task Start()
        {
            _tenantService = new TenantService(new Uri(_config.TenantServiceUrl), _config.TenantServiceCertificateName, _config.TenantServiceResourceId);

            await RefreshSecrets();

            await ReCreateServiceBusClient();

            ReCreateBlobClient();
        }
Example #12
0
        public ActionResult Get(int id)
        {
            mdlTenant tenant = TenantService.Retrieve(id);

            if (tenant == null)
            {
                return(NotFound($"Tenant with id:{id} not found"));
            }
            return(Ok(tenant));
        }
        public async Task Start()
        {
            _tenantService = new TenantService(_config);

            await RefreshSecrets();
            await ReCreateServiceBusClient();

            ReCreateBlobClient();
            Console.WriteLine("Listening for new messages...");
        }
Example #14
0
        protected override async Task OnInitializedAsync()
        {
            _tenants = await TenantService.GetTenantsAsync();

            _urls      = PageState.Alias.Name;
            _themeList = await ThemeService.GetThemesAsync();

            _themes        = ThemeService.GetThemeControls(_themeList);
            _siteTemplates = await SiteTemplateService.GetSiteTemplatesAsync();
        }
Example #15
0
        public ApiPollControllerTests()
        {
            _context     = Helpers.GetContext("test");
            _currentUser = new ApplicationUser
            {
                Email          = "*****@*****.**",
                FirstName      = "test",
                LastName       = "Test",
                CreatedAt      = DateTime.UtcNow,
                SecurityStamp  = new Guid().ToString(),
                EmailConfirmed = true,
                Id             = 1.ToString(),
                IsDeleted      = false,
                UserDetail     = new UserDetail {
                    AuthorityPercent = 30, LanguagePreference = "tr"
                }
            };
            _context.Users.Add(_currentUser);
            _context.SaveChanges();
            var                        tenantsDbContext  = Helpers.GetTenantContext();
            IPollRepository            pollRepository    = new EntityPollRepository(_context, tenantsDbContext);
            IAsyncRepository <Setting> settingRepository = new EfRepository <Setting>(_context);
            ISettingService            settingService    = new SettingService(settingRepository);
            IUserRepository            userRepository    = new EntityUserRepository(_context, null);
            IUserService               userService       = new UserService(userRepository, null);
            ITenantRepository          tenantRepository  = new EntityTenantRepository(tenantsDbContext);
            IAsyncRepository <Vote>    voteRepository    = new EfRepository <Vote>(_context);
            var                        voteService       = new VoteService(voteRepository, userService);
            ITenantService             tenantService     = new TenantService(tenantRepository, settingService, null);
            IPollService               pollService       = new PollService(pollRepository, settingService, userService, tenantService,
                                                                           voteService, null, null);
            var mapper             = Helpers.GetMapper();
            var tenantProviderMock = new Mock <ITenantProvider>();

            tenantProviderMock.Setup(serv => serv.GetTenantId()).Returns("test");
            _pollLocalizerMock = new Mock <IStringLocalizer <ApiPollController> >();
            IPollApiViewModelService pollApiViewModelService = new PollApiViewModelService(tenantProviderMock.Object,
                                                                                           pollService, mapper, voteService, userService, settingService);
            var genericServiceMock = new Mock <IGenericService>();

            genericServiceMock.Setup(serv => serv.GetBaseUrl(null)).Returns(Task.FromResult("decidehub.com"));
            _controller = new ApiPollController(pollService, mapper, userService, pollApiViewModelService,
                                                _pollLocalizerMock.Object, voteService, genericServiceMock.Object, tenantProviderMock.Object);
            var user = new ClaimsPrincipal(new ClaimsIdentity(new[]
            {
                new Claim(ClaimTypes.PrimarySid, "1")
            }));

            _controller.ControllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext {
                    User = user
                }
            };
        }
        public void SetUp()
        {
            properties = new List <Property>
            {
                new Property {
                    Id      = 1,
                    Address = "Drujba, 6",
                    Area    = 100,
                    Rooms   = 7,
                    Beds    = 3,
                    Rent    = 150
                }
            };

            tenants = new List <Tenant>()
            {
                new Tenant
                {
                    Id             = 1,
                    FirstName      = "Dan",
                    LastName       = "Ivanov",
                    Email          = "*****@*****.**",
                    PhoneNumber    = "0879542734",
                    DateOfMovingIn = DateTime.Now,
                    IsKickedOut    = false,
                    RentedProperty = properties[0]
                }
            };

            payments = new List <Payment>()
            {
                new Payment
                {
                    Id     = 1,
                    Amount = 100,
                    Date   = DateTime.Now,
                    Tenant = tenants[0]
                }
            };

            dbContext = new Mock <RmsContext>();

            dbContext.Setup(p => p.Tenants)
            .Returns(DbContextMock.GetQueryableMockDbSet(tenants));

            dbContext.Setup(p => p.Properties)
            .Returns(DbContextMock.GetQueryableMockDbSet(properties));

            dbContext.Setup(p => p.Payments)
            .Returns(DbContextMock.GetQueryableMockDbSet(payments));

            paymentService  = new PaymentService(dbContext.Object);
            propertyService = new PropertyService(dbContext.Object);
            tenantService   = new TenantService(dbContext.Object, propertyService, paymentService);
        }
        public void TestEnable()
        {
            const string test = "foo";

            try
            {
                // Arrange
                var ts = new TenantService();

                using (new GlobalAdministratorContext())
                {
                    var id = TenantHelper.CreateTenant(test);
                    id.Should().BeGreaterThan(0);

                    var tenant = Entity.Get <Tenant>(id).AsWritable <Tenant>();
                    tenant.IsTenantDisabled = true;
                    tenant.Save();
                }

                // Act
                ts.Enable(test);

                // Assert
                using (new GlobalAdministratorContext())
                {
                    var tid = TenantHelper.GetTenantId(test);
                    tid.Should().BeGreaterThan(0);

                    var result = Entity.Get <Tenant>(tid);
                    result.Should().NotBeNull();
                    result.IsTenantDisabled.Should().BeFalse();
                }

                Action a1 = () => ts.Enable(null);
                a1.ShouldThrow <ArgumentException>().WithMessage("The specified tenantName parameter is invalid.");

                Action a2 = () => ts.Enable(string.Empty);
                a2.ShouldThrow <ArgumentException>().WithMessage("The specified tenantName parameter is invalid.");

                var    notATenant = Guid.NewGuid().ToString();
                Action a3         = () => ts.Enable(notATenant);
                a3.ShouldThrow <Exception>().WithMessage("Tenant " + notATenant + " not found.");
            }
            finally
            {
                using (new GlobalAdministratorContext())
                {
                    var testId = TenantHelper.GetTenantId(test);
                    if (testId > 0)
                    {
                        TenantHelper.DeleteTenant(testId);
                    }
                }
            }
        }
Example #18
0
        public string GetCampaign(int tenant)
        {
            var t = TenantService.GetTenant(tenant);

            if (t != null && !string.IsNullOrWhiteSpace(t.Campaign))
            {
                return(t.Campaign);
            }

            return(null);
        }
Example #19
0
        public string GetAffiliateId(int tenant)
        {
            var t = TenantService.GetTenant(tenant);

            if (t != null && !string.IsNullOrWhiteSpace(t.AffiliateId))
            {
                return(t.AffiliateId);
            }

            return(null);
        }
Example #20
0
 public ToolController(
     ILogger <ConsentController> _logger,
     IStringLocalizer <ToolController> _l,
     TenantService _tenantService,
     TenantDbContext _tenantDb)
 {
     tenantService = _tenantService;
     tenantDb      = _tenantDb;
     logger        = _logger;
     l             = _l;
 }
Example #21
0
 public void SetAccessToken(string token)
 {
     Token                = token;
     TenantService        = new TenantService(Token);
     ResourceGroupService = new ResourceGroupService(Token);
     ResourceService      = new ResourceService(Token);
     LogicAppService      = new LogicAppService(Token);
     WorkspacesService    = new WorkspacesService(Token);
     LogAnalyticsService  = new LogAnalyticsService(Token);
     Init();
 }
Example #22
0
        public ActionResult SendRequest(string returnUrl)
        {
            var user  = User.Identity.Name;
            var login = AccountService.GetLoginByEmail(user);
            var model = TenantService.GetTenantRentals(login.Id);

            model.ForEach(x => x.AddressString = x.PropertyAddress.Number + " " + x.PropertyAddress.Street + ", " + x.PropertyAddress.Suburb + ", " + x.PropertyAddress.City + ", " + x.PropertyAddress.PostCode);
            ViewBag.ReturnUrl    = returnUrl;
            ViewBag.RequestTypes = RentalService.GetRequestTypes();
            return(View(model));
        }
Example #23
0
        public ActionResult TenantDashboard(int?steps)
        {
            var user  = User.Identity.Name;
            var login = AccountService.GetLoginByEmail(user);

            var props   = db.TenantProperty.Where(x => x.TenantId == login.Id && x.Property.IsActive && (x.IsActive ?? false));
            var propIds = props.Select(x => x.PropertyId);

            //ApplicationStatusId {1 : Applied, 2 : Accepted, 3: Declined}
            var rentApps     = db.RentalApplication.Where(x => x.PersonId == login.Id && x.IsActive);
            var newApps      = rentApps.Where(x => x.ApplicationStatusId == 1 && !(x.IsViewedByOwner ?? false)).Count();
            var acceptedApps = rentApps.Where(x => x.ApplicationStatusId == 2).Count();
            var pendingApps  = rentApps.Where(x => x.ApplicationStatusId == 1 && (x.IsViewedByOwner ?? false)).Count();
            var declinedApps = rentApps.Where(x => x.ApplicationStatusId == 3).Count();

            // Get Landlord request's statistics
            var landlordreqs             = db.PropertyRequest.Where(x => propIds.Contains(x.Property.Id) && x.IsActive && !x.ToOwner && x.ToTenant && x.RecipientId == login.Id);
            var newLandlordRequests      = landlordreqs.Where(x => x.RequestStatusId == 1).Count();
            var acceptedLandlordRequests = landlordreqs.Where(x => x.RequestStatusId == 2).Count();
            var rejectedLandlordRequests = landlordreqs.Where(x => x.RequestStatusId == 5).Count();

            var tenRequests      = db.PropertyRequest.Where(x => propIds.Contains(x.Property.Id) && x.IsActive && x.ToOwner && !x.ToTenant);
            var newRequests      = tenRequests.Where(x => !x.IsViewed).Count();
            var acceptedRequests = tenRequests.Where(x => x.RequestStatusId == 2).Count();
            var rejRequests      = tenRequests.Where(x => x.RequestStatusId == 5).Count();
            var tenant           = db.Tenant.FirstOrDefault(x => x.Id == login.Id);

            var model = new TenantDashBoardModel
            {
                TenantRentalDashboardData = TenantService.GetRentalInfo(login.Id),
                RentAppsDashboardData     = new TenantRentAppDashboardModel
                {
                    NewItems = newApps,
                    Accepted = acceptedApps,
                    //Pending = pendingApps,
                    Rejected = declinedApps,
                },
                LandLordRequestDashboardData = new LandLordRequestDashboardModel
                {
                    NewItems = newLandlordRequests,
                    Accepted = acceptedLandlordRequests,
                    Rejected = rejectedLandlordRequests
                },
                TenantRequestDashboardData = new TenantRequestDashboardModel
                {
                    Current  = newRequests,
                    Accepted = acceptedRequests,
                    Rejected = rejRequests
                }
            };

            model.IntroSteps = steps.HasValue ? steps.Value : 0;
            return(PartialView("_TenantDashboard", model));
        }
 public HomeController(
     IStringLocalizer <HomeController> _l,
     TenantService _tenantService,
     TenantDbContext _tenantDb,
     SignInManager <AppUser> _signInManager
     )
 {
     l             = _l;
     tenantService = _tenantService;
     tenantDb      = _tenantDb;
     signInManager = _signInManager;
 }
        private bool IsTenant(string username)
        {
            // Fix the Username
            username = username.Split('#').Last();

            // Find the user
            var command = new TenantService();
            var tenants = command.FetchByUsername(username);

            // Check if user
            return(tenants != null && tenants.Any());
        }
Example #26
0
        public string GetSetting(string key, int tenant = Tenant.DEFAULT_TENANT)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("key");
            }
            var bytes = TenantService.GetTenantSettings(tenant, key);

            var result = bytes != null?Encoding.UTF8.GetString(Crypto.GetV(bytes, 2, false)) : null;

            return(result);
        }
Example #27
0
        public ActionResult StartDeprovisioning()
        {
            TempData["PipelineRunning"] = true;
            TempData["Process"]         = "Deprovisioning";

            var tenantService = new TenantService();
            var tenants       = tenantService.FetchByUsername(HttpContext.User.Identity.SplitName());

            DeprovisionTenantSite(tenants);

            return(RedirectToAction("Index", "TenantView"));
        }
Example #28
0
        public ActionResult StartDeprovisioning(string username)
        {
            var tenantService = new TenantService();
            var tenants       = tenantService.FetchByUsername(username);

            TempData["PipelineRunning"] = true;
            TempData["Username"]        = username;

            DeprovisionTenantSite(tenants);

            return(RedirectToAction("Index", "AdminView"));
        }
Example #29
0
        protected override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            var viewResult = filterContext.Result as ViewResult;

            if (viewResult != null)
            {
                viewResult.MasterName = viewResult.MasterName != "IGNORE" ? "_Layout" : "";
            }

            Debug.Assert(filterContext.HttpContext.Request.Url != null, "filterContext.HttpContext.Request.Url != null");
            this.CurrentTenant = TenantService.GetCurrentTenant(filterContext.HttpContext.Request.Url.Host.ToLower());
        }
Example #30
0
        public TenantControl(TenantService tenantService)
        {
            _tenantService = tenantService;
            InitializeComponent();

            var allTenants = _tenantService.Tenants;

            TenantListView.ItemsSource = allTenants;

            _view = (CollectionView)CollectionViewSource.GetDefaultView(TenantListView.ItemsSource);
            _view.SortDescriptions.Add(new SortDescription("Id", ListSortDirection.Ascending));
        }
        public void TestGetTenants()
        {
            // Arrange
            var ts = new TenantService();

            // Act
            var tenants = ts.GetTenants();

            // Assert
            tenants.Should().NotBeNullOrEmpty().And.NotContainNulls();
            tenants.Select(t => t.Name).Should().Contain(RunAsDefaultTenant.DefaultTenantName);
        }
        public async Task Invoke(HttpContext context, TenantService service)
        {
            using (_logger.BeginScope("TenantResolverMiddleware"))
            {
                _logger.LogInformation("Invoing resolver middleware.");
                var originalPath = context.Request.Path.Value;
                var m = Regex.Match(originalPath, "/([a-zA-Z0-9]+)(/.*)?");
                if (!m.Success)
                {
                    throw new ArgumentOutOfRangeException("tenant");
                    //context.Response.StatusCode = 404;
                    //return CompletedTask;
                }

                var tenantGroup = m.Groups[1];
                var realPathGroup = m.Groups[2];

                _logger.LogInformation("Setting tenant.");
                if (!await service.SetTenant(context))
                {
                    throw new Exception("failed");
                }
                _logger.LogInformation("Done setting tenant.");

                /*
                var tenantName = tenantGroup.Value;
                if (!realPathGroup.Success)
                    context.Request.Path = "/";
                else
                    context.Request.Path = realPathGroup.Value;
                    */



                await _next(context);
            }
        }