public void Dispose() { foreach (var preReceiveEnvironment in _preReceiveEnvironments) { EnterpriseHelper.DeletePreReceiveEnvironment(_githubEnterprise.Connection, preReceiveEnvironment); } }
public ActionResult Edit(string key) { if (!string.IsNullOrEmpty(key)) { var viewModel = Db.Enterprises.GetCompleteEnterprise(EnterpriseHelper.GetId(key), true); if (viewModel.Enterprise.IsNew || viewModel.Enterprise.OwnedByAccount) { if (viewModel.Enterprise.OwnedByAccount) { var account = Db.Accounts.GetAccount(HttpContext.User.Identity.Name); if (account.Enabled && account.Enterprises.Contains(EnterpriseHelper.GetId(key))) { //If account is enabled and contains this enterprise return(View(viewModel)); } } else { return(View(viewModel)); } } } return(RedirectToAction("Index")); }
public void UpdateProduct(Product product, string enterpriseId) { using (var session = _documentStore.OpenSession()) { var enterprise = session.Load <Enterprise>(enterpriseId); if (EnterpriseHelper.ValidEditableEnterprise(enterprise, session)) { //Om det är en ny enterprise eller en som är ägd, spara produkten direkt if (enterprise.IsNew || enterprise.OwnedByAccount) { session.Store(product); } else { if (product.Enterprise == enterpriseId) { //If enterprise is existing, save an updated version of the product for approvement var productInDb = session.Load <Product>(product.Id); Mapper.CreateMap <Product, ProductUpdatedVersion>(); var updatedProduct = new ProductUpdatedVersion(); Mapper.Map(product, updatedProduct); productInDb.UpdatedVersion = updatedProduct; } else { _logger.Warn(string.Format("Product: {0} belongs to this enterprise: {1} and was about to be updated to {2} Code:[hT882v563]", product.Id, product.Enterprise, enterpriseId)); } } _logger.Info(string.Format("Product:{0} was updated. Enterprise: {1}. Code:[poO0789b]", product.Id, enterpriseId)); session.SaveChanges(); } } }
public JsonResult GetEnterprisesCloseToMyLocation(string latitude, string longitude) { var enterprises = Db.Enterprises.GetNearbyEnterprises(latitude, longitude); var searchViewModel = new MainSearchViewModel { Enterprises = new List <LightEnterprise>() }; foreach (var enterpriseViewModel in enterprises.Select(enterprise => new LightEnterprise { Key = EnterpriseHelper.GetKey(enterprise.Id), Name = enterprise.Name, LocationInfo = EnterpriseHelper.FormatDisplayStreet(enterprise), DistanceFromMyLocation = string.Empty, Categories = EnterpriseHelper.GetDisplayLabelsCategories(enterprise.Categories), Coordinates = enterprise.Coordinates, })) { searchViewModel.Enterprises.Add(enterpriseViewModel); } var myCoord = new GeoCoordinate(double.Parse(latitude, CultureInfo.InvariantCulture), double.Parse(longitude, CultureInfo.InvariantCulture)); foreach (var enterprise in searchViewModel.Enterprises) { var enterpriseCoord = new GeoCoordinate(enterprise.Coordinates.Lat, enterprise.Coordinates.Lng); var distance = myCoord.GetDistanceTo(enterpriseCoord); enterprise.DistanceFromMyLocation = string.Format("{0}km", Math.Round((distance / 1000), 1)); } return(Json(searchViewModel)); }
internal MaintenanceModeContext(IConnection connection, bool enabled) { _connection = connection; // Ensure maintenance mode is in the desired initial state EnterpriseHelper.SetMaintenanceMode(_connection, enabled); }
public TheDownloadStatusMethod() { _githubEnterprise = EnterpriseHelper.GetAuthenticatedClient(); _preReceiveEnvironmentsClient = _githubEnterprise.Enterprise.PreReceiveEnvironment; var newPreReceiveEnvironment = new NewPreReceiveEnvironment(Helper.MakeNameWithTimestamp("pre-receive"), "https://example.com/foo.zip"); _preReceiveEnvironment = _preReceiveEnvironmentsClient.Create(newPreReceiveEnvironment).Result; }
public ActionResult Index(string q) { if (!string.IsNullOrEmpty(q)) { var enterprise = Db.Enterprises.GetCompleteEnterprise(EnterpriseHelper.GetId(q)); return(View(enterprise)); } return(RedirectToAction("Index", "Home")); }
public TheTriggerDownloadMethod() { _githubEnterprise = EnterpriseHelper.GetAuthenticatedClient(); _preReceiveEnvironmentsClient = _githubEnterprise.Enterprise.PreReceiveEnvironment; var newPreReceiveEnvironment = new NewPreReceiveEnvironment(Helper.MakeNameWithTimestamp("pre-receive"), "https://example.com/foo.zip"); _preReceiveEnvironment = _preReceiveEnvironmentsClient.Create(newPreReceiveEnvironment).Result; EnterpriseHelper.WaitForPreReceiveEnvironmentToComplete(_githubEnterprise.Connection, _preReceiveEnvironment); }
public TheEditMethod() { _githubEnterprise = new ObservableGitHubClient(EnterpriseHelper.GetAuthenticatedClient()); _preReceiveEnvironmentsClient = _githubEnterprise.Enterprise.PreReceiveEnvironment; var newPreReceiveEnvironment = new NewPreReceiveEnvironment(Helper.MakeNameWithTimestamp("pre-receive"), "https://example.com/foo.zip"); _preReceiveEnvironment = _preReceiveEnvironmentsClient.Create(newPreReceiveEnvironment).Wait(); EnterpriseHelper.WaitForPreReceiveEnvironmentToComplete(_githubEnterprise.Connection, _preReceiveEnvironment); }
public async Task CanDeletePreReceiveEnvironment() { var newPreReceiveEnvironment = new NewPreReceiveEnvironment(Helper.MakeNameWithTimestamp("pre-receive"), "https://example.com/foo.zip"); var preReceiveEnvironment = await _preReceiveEnvironmentsClient.Create(newPreReceiveEnvironment); EnterpriseHelper.WaitForPreReceiveEnvironmentToComplete(_githubEnterprise.Connection, preReceiveEnvironment); await _preReceiveEnvironmentsClient.Delete(preReceiveEnvironment.Id); await Assert.ThrowsAsync <NotFoundException>(async() => await _preReceiveEnvironmentsClient.Get(preReceiveEnvironment.Id)); }
public EnterpriseLdapClientTests() { _github = EnterpriseHelper.GetAuthenticatedClient(); NewTeam newTeam = new NewTeam(Helper.MakeNameWithTimestamp("test-team")) { Description = "Test Team" }; _context = _github.CreateTeamContext(EnterpriseHelper.Organization, newTeam).Result; }
public TheGetMethod() { _githubEnterprise = EnterpriseHelper.GetAuthenticatedClient(); _preReceiveEnvironmentsClient = _githubEnterprise.Enterprise.PreReceiveEnvironment; _preReceiveEnvironmentName = Helper.MakeNameWithTimestamp("pre-receive"); _preReceiveEnvironmentUrl = "https://example.com/foo.zip"; var newPreReceiveEnvironment = new NewPreReceiveEnvironment(_preReceiveEnvironmentName, _preReceiveEnvironmentUrl); _preReceiveEnvironment = _preReceiveEnvironmentsClient.Create(newPreReceiveEnvironment).Result; }
public TheGetAllMethod() { _githubEnterprise = EnterpriseHelper.GetAuthenticatedClient(); _preReceiveEnvironmentsClient = _githubEnterprise.Enterprise.PreReceiveEnvironment; _preReceiveEnvironments = new List <PreReceiveEnvironment>(); for (var count = 0; count < 5; count++) { var newPreReceiveEnvironment = new NewPreReceiveEnvironment(Helper.MakeNameWithTimestamp("pre-receive"), "https://example.com/foo.zip"); _preReceiveEnvironments.Add(_preReceiveEnvironmentsClient.Create(newPreReceiveEnvironment).Result); } }
public ActionResult Index(string key) { var viewModel = new EnterpriseViewModel(); if (!string.IsNullOrEmpty(key)) { var enterprise = Db.Enterprises.GetCompleteEnterprise(EnterpriseHelper.GetId(key)).Enterprise; if ((enterprise.IsNew && !enterprise.LockedFromEdit) || (HttpContext.User.Identity.IsAuthenticated && CurrentAccount.IsAdmin)) { viewModel = enterprise; viewModel.ShowForm = true; } } return(View(viewModel)); }
public async Task CanRename() { string renamedUsername = Helper.MakeNameWithTimestamp("user-renamed"); // Create a disposable user for the test using (var context = _github.CreateEnterpriseUserContext(GenerateNewUserDetails()).Result) { var response = await _github.User.Administration.Rename( context.UserLogin, new UserRename(renamedUsername)); Assert.NotNull(response); Assert.StartsWith("Job queued to rename user", response.Message); Assert.EndsWith(context.UserId.ToString(), response.Url); } // Remove user if it was already renamed EnterpriseHelper.DeleteUser(renamedUsername); }
public async Task CanCreatePreReceiveEnvironment() { PreReceiveEnvironment preReceiveEnvironment = null; try { var newPreReceiveEnvironment = new NewPreReceiveEnvironment(Helper.MakeNameWithTimestamp("pre-receive"), "https://example.com/foo.zip"); preReceiveEnvironment = await _preReceiveEnvironmentsClient.Create(newPreReceiveEnvironment); Assert.NotNull(preReceiveEnvironment); Assert.Equal(newPreReceiveEnvironment.Name, preReceiveEnvironment.Name); Assert.Equal(newPreReceiveEnvironment.ImageUrl, preReceiveEnvironment.ImageUrl); } finally { //Cleanup EnterpriseHelper.DeletePreReceiveEnvironment(_githubEnterprise.Connection, preReceiveEnvironment); } }
public JsonResult MainSearch(string searchTerm) { if (string.IsNullOrEmpty(searchTerm)) { return(Json(null)); } var enterprises = Db.Enterprises.MainSearch(searchTerm); var searchViewModel = new MainSearchViewModel { SearchQuery = searchTerm, Enterprises = new List <LightEnterprise>(), Locations = new List <string> { "Tumba", "Tullinge" }, Categories = new List <string>() }; var categories = GeneralHelper.GetCategories().Where(c => c.Text.ToLower().StartsWith(searchTerm.ToLower())); if (categories.Any()) { searchViewModel.Categories = categories.Select(c => c.Text).ToList(); } foreach (var enterpriseViewModel in enterprises.Select(enterprise => new LightEnterprise { Key = EnterpriseHelper.GetKey(enterprise.Id), Name = enterprise.Name, LocationInfo = EnterpriseHelper.FormatDisplayStreet(enterprise), DistanceFromMyLocation = string.Empty, Categories = EnterpriseHelper.GetDisplayLabelsCategories(enterprise.Categories) })) { searchViewModel.Enterprises.Add(enterpriseViewModel); } return(Json(searchViewModel)); }
public UserAdministrationClientTests() { _github = EnterpriseHelper.GetAuthenticatedClient(); }
public ObservableUserAdministrationClientTests() { _github = new ObservableGitHubClient(EnterpriseHelper.GetAuthenticatedClient()); }
public void Dispose() { EnterpriseHelper.DeleteUser(_connection, User.Login); }
public EnterpriseLicenseClientTests() { _github = EnterpriseHelper.GetAuthenticatedClient(); }
public TheGetAllMethod() { _github = EnterpriseHelper.GetAuthenticatedClient(); _organizationsClient = _github.Organization; }
public EnterpriseAdminStatsClientTests() { _github = EnterpriseHelper.GetAuthenticatedClient(); }
public TheDeleteMethod() { _githubEnterprise = new ObservableGitHubClient(EnterpriseHelper.GetAuthenticatedClient()); _preReceiveEnvironmentsClient = _githubEnterprise.Enterprise.PreReceiveEnvironment; }
public void Dispose() { EnterpriseHelper.DeletePreReceiveEnvironment(_githubEnterprise.Connection, _preReceiveEnvironment); }
public EnterpriseManagementConsoleClientTests() { _github = EnterpriseHelper.GetAuthenticatedClient(); }
public void Dispose() { EnterpriseHelper.DeleteUser(User); }
public CompleteEnterpriseViewModel GetCompleteEnterprise(string enterpriseId, bool edit = false) { using (var session = _documentStore.OpenSession()) { var viewModel = new CompleteEnterpriseViewModel(); if (string.IsNullOrEmpty(enterpriseId)) { return(viewModel); } // Load enterprise, include products var enterprise = session.Include <Enterprise>(e => e.Menu.Categories.Select(c => c.Products)).Load(enterpriseId); if (enterprise == null) { return(viewModel); } var menu = enterprise.Menu; var newProducts = new List <string>(); var deletedProductIds = new List <string>(); //Load the modified menu if: edit-mode, has a modified menu, is NOT new, is NOT owned by enterprise if (edit && !string.IsNullOrEmpty(enterprise.ModifiedMenu) && !enterprise.IsNew && !enterprise.OwnedByAccount) { //Get the modified menu instead var modifiedMenu = session.Include <Menu>(e => e.Categories.Select(c => c.Products)).Load <ModifiedMenu>(enterprise.ModifiedMenu); //Get ids of all new products. Products that exist in the Modified-menu but not the original menu newProducts = modifiedMenu.Menu.Categories.SelectMany(c => c.Products).Where(p => !enterprise.Menu.Categories.SelectMany(c => c.Products).Select(p1 => p1).Contains(p)).ToList(); //Get ids of all deleted products. Products that does NOT exist in the Modified-menu but not the original menu deletedProductIds = enterprise.Menu.Categories.SelectMany(c => c.Products).Where(p => !modifiedMenu.Menu.Categories.SelectMany(c => c.Products).Select(p1 => p1).Contains(p)).ToList(); //Set modifiedMenu to menu Mapper.CreateMap <ModifiedMenu, Menu>(); menu = Mapper.Map(modifiedMenu.Menu, menu); } var products = new List <Product>(); // Create to viewmodel var categoriesViewModel = new List <ViewModelCategory>(); if (menu != null) { if (menu.Categories != null) { foreach (var p in menu.Categories.Select(category => session.Load <Product>(category.Products))) { products.AddRange(p); } Mapper.CreateMap <Product, ProductViewModel>(); foreach (var category in menu.Categories) { var categoryViewModel = new ViewModelCategory { Name = category.Name, Id = category.Id, EnterpriseId = enterpriseId, Products = new List <ProductViewModel>() }; foreach (var product in category.Products.Select(productForCategory => products.FirstOrDefault(p => p != null && p.Id == productForCategory))) { if (product == null) { _logger.Warn("Product is null for enterprise {0} ({1})", enterprise.Name, enterprise.Id); continue; } var p = ProductHelper.ModelToViewModel(product); if (edit && p.UpdatedVersion != null) { p.Updated = true; p.OriginalProduct = product; //p.UpdatedVersion = product.UpdatedVersion; Mapper.CreateMap <ProductUpdatedVersion, ProductViewModel>(); Mapper.Map(product.UpdatedVersion, p); } if (edit) { if (newProducts.Contains(p.Id)) { p.New = true; } } p.Enterprise = enterpriseId; p.CategoryId = category.Id; categoryViewModel.Products.Add(p); } categoriesViewModel.Add(categoryViewModel); } if (edit) { //Add deleted products to viewmodel var deletedProducts = session.Load <Product>(deletedProductIds); var deletedProductsViewModel = ProductHelper.ModelToViewModel(deletedProducts.ToList()); foreach (var productViewModel in deletedProductsViewModel) { productViewModel.Deleted = true; } viewModel.DeletedProducts = deletedProductsViewModel; } } } // Add to viewmodel viewModel.ViewModelCategories = categoriesViewModel; viewModel.Enterprise = EnterpriseHelper.ModelToViewModel(enterprise); viewModel.Enterprise.DisplayCategories = EnterpriseHelper.GetDisplayCategories(enterprise.Categories); viewModel.Enterprise.DisplayStreet = string.Format("{0} {1}", enterprise.StreetRoute, enterprise.StreetNumber); if (!edit) { viewModel.Enterprise.ModifiedMenu = null; } return(viewModel); } }
public TheDeleteMethod() { _githubEnterprise = EnterpriseHelper.GetAuthenticatedClient(); _preReceiveEnvironmentsClient = _githubEnterprise.Enterprise.PreReceiveEnvironment; }
public bool UpdateEnterprise(string enterpriseId, Menu menu) { var updated = false; using (var session = _documentStore.OpenSession()) { var enterprise = session.Load <Enterprise>(enterpriseId); try { if (EnterpriseHelper.ValidEditableEnterprise(enterprise, session)) { MenuHelper.ValidateMenu(menu, enterpriseId, session, _logger); if (enterprise.IsNew || enterprise.OwnedByAccount) { var deletedProductsIds = GeneralHelper.CompareLists(enterprise.Menu.Categories.SelectMany(c => c.Products).ToList(), menu.Categories.SelectMany(c => c.Products).ToList()); if (deletedProductsIds.Count > 0) { var deletedProducts = session.Load <Product>(deletedProductsIds); //Delete products that belongs to this enterprise foreach (var deletedProduct in deletedProducts.Where(deletedProduct => deletedProduct != null && deletedProduct.Enterprise == enterpriseId)) { session.Delete(deletedProduct); } } enterprise.Menu = menu; enterprise.LastUpdated = DateTime.Now; } else { var modifiedMenuInDb = session.Load <ModifiedMenu>(MenuHelper.GetModifiedMenuId(enterpriseId)); if (modifiedMenuInDb == null) { var modifiedMenu = new ModifiedMenu { Id = MenuHelper.GetModifiedMenuId(enterpriseId), Menu = menu }; session.Store(modifiedMenu); enterprise.LockedFromEdit = true; enterprise.ModifiedMenu = modifiedMenu.Id; } } session.Store(enterprise); session.SaveChanges(); updated = true; _logger.Info("Updated menu settings for enterprise: " + enterprise.Id); } } catch (Exception ex) { _logger.Fatal(ex.Message, ex); var failedEnterprise = new FailedEnterprise { Enterprise = enterprise, Menu = menu, ErrorMessage = ex.Message }; session.Store(failedEnterprise); session.SaveChanges(); } } return(updated); }