public SaveGalaxyResponse SaveGalaxyContainer(GalaxyContainer container) { var result = new SaveGalaxyResponse(); _wrapper.GalaxyContainerRepository.AddOne <GalaxyContainer>(container); result.GalaxyContainerId = container.Id; result.Success = true; return(result); }
/// <summary> /// Creates a default galaxy if needed. /// </summary> public void CreateDefaultGalaxyIfNecessary() { if (this.GetDefaultGalaxy().Success == false) { CasualGodComplex.Galaxy galaxy = CasualGodComplex.Galaxy.Generate(new CasualGodComplex.Galaxies.Spiral(), new Random(12345)).Result; GalaxyContainer ctr = new GalaxyContainer("Default"); ctr.SetGalaxy(galaxy); SaveGalaxyResponse response = this.SaveGalaxyContainer(ctr); } }
public GalaxyIndexViewModel(IAuthenticationService authenticationService, IObjectService objectService, int seed, bool saveSeed, string galaxyName = "Default", string cookie = "") { _seed = seed; _success = false; _authenticationService = authenticationService; _objectService = objectService; _galaxy = CasualGodComplex.Galaxy.Generate(new CasualGodComplex.Galaxies.Spiral(), new Random(seed)).Result; // For personalization, load in some player details. if (!string.IsNullOrEmpty(cookie)) { // Try to look up the player using their session Identifier (just a basic cookie) GetPlayerByCookieResponse playerByWebCookie = _authenticationService.GetPlayerByWebCookie(cookie); // The method returns a container object that has .Success property set to TRUE when the // player was found via a cookie that was not expired. if (playerByWebCookie.Success == true) { _player = playerByWebCookie.Player; if (saveSeed == true) { if (_player.IsAdmin) { GalaxyContainer ctr = new GalaxyContainer(galaxyName); ctr.SetGalaxy(_galaxy); SaveGalaxyResponse response = _objectService.SaveGalaxyContainer(ctr); _success = response.Success; if (_success) { _message = "Saved galaxy as " + galaxyName; } else { _message = "Tried to save galaxy as " + galaxyName + " but failed."; } } else { _success = false; _message = "Cannot save galaxy because you are not an administrator."; } } else { _message = "Fill in the form to save this galaxy."; } } else { // Is this necessary? _player = null; _message = "You are not logged in, no attempt to save will be made."; } } }