public ActionResult EditCharacter(long id, AddEditCharacterViewModel vModel) { string userId = User.Identity.GetUserId(); ApplicationUser authedUser = UserManager.FindById(userId); IPlayerTemplate obj = PlayerDataCache.Get(new PlayerDataCacheKey(typeof(IPlayerTemplate), authedUser.GlobalIdentityHandle, id)); obj.Name = vModel.DataObject.Name; obj.SurName = vModel.DataObject.SurName; obj.Gender = vModel.DataObject.Gender; obj.SuperSenses = vModel.DataObject.SuperSenses; obj.GamePermissionsRank = vModel.DataObject.GamePermissionsRank; obj.Race = vModel.DataObject.Race; string message; if (obj == null) { message = "That character does not exist"; } else { if (obj.Save(authedUser.GameAccount, authedUser.GetStaffRank(User))) { LoggingUtility.Log("*WEB* - EditCharacter[" + authedUser.GameAccount.GlobalIdentityHandle + "]", LogChannels.AccountActivity); message = "Edit Successful."; } else { message = "Error; edit failed."; } } return(RedirectToAction("ManageCharacters", new { Message = message })); }
/// <summary> /// Dumps everything of a single type into the cache from the filesystem for BackingData /// </summary> /// <typeparam name="T">the type to get and store</typeparam> /// <returns>full or partial success</returns> public bool LoadAllCharactersForAccountToCache(string accountHandle) { string currentBackupDirectory = BaseDirectory + accountHandle + "/" + CurrentDirectoryName; //No current directory? WTF if (!VerifyDirectory(currentBackupDirectory, false)) { return(false); } DirectoryInfo charDirectory = new DirectoryInfo(currentBackupDirectory); foreach (FileInfo file in charDirectory.EnumerateFiles("*.playertemplate", SearchOption.AllDirectories)) { try { byte[] fileData = ReadFile(file); System.Runtime.Remoting.ObjectHandle blankEntity = Activator.CreateInstance("NetMud.Data", "NetMud.Data.Players.PlayerTemplate"); IPlayerTemplate objRef = blankEntity.Unwrap() as IPlayerTemplate; IPlayerTemplate newChar = objRef.FromBytes(fileData) as IPlayerTemplate; PlayerDataCache.Add(newChar); } catch (Exception ex) { LoggingUtility.LogError(ex); //Let it keep going } } return(true); }
public JsonResult <string[]> GetCharacterNamesForAccount(string accountName, string term) { ApplicationUser user = UserManager.FindById(User.Identity.GetUserId()); IEnumerable <IPlayerTemplate> characters = PlayerDataCache.GetAll().Where(chr => chr.AccountHandle.Equals(user.GlobalIdentityHandle) && chr.Name.Contains(term)); return(Json(characters.Select(chr => chr.Name).ToArray())); }
/// <summary> /// Put it in the cache /// </summary> /// <returns>success status</returns> public override bool PersistToCache() { try { PlayerDataCache.Add(this); } catch (Exception ex) { LoggingUtility.LogError(ex, LogChannels.SystemWarnings); return(false); } return(true); }
public ActionResult EditCharacter(long id) { string userId = User.Identity.GetUserId(); ApplicationUser user = UserManager.FindById(userId); IPlayerTemplate obj = PlayerDataCache.Get(new PlayerDataCacheKey(typeof(IPlayerTemplate), user.GlobalIdentityHandle, id)); AddEditCharacterViewModel model = new AddEditCharacterViewModel { AuthedUser = user, DataObject = obj, ValidRaces = TemplateCache.GetAll <IRace>(), ValidGenders = TemplateCache.GetAll <IGender>() }; return(View(model)); }
/// <summary> /// Add a character to this account /// </summary> /// <param name="newChar">the character data to add</param> /// <returns>errors or Empty if successful</returns> public string AddCharacter(IPlayerTemplate newChar) { HashSet <IPlayerTemplate> systemChars = new HashSet <IPlayerTemplate>(PlayerDataCache.GetAll()); if (systemChars.Any(ch => ch.Name.Equals(newChar.Name, StringComparison.InvariantCultureIgnoreCase) && newChar.SurName.Equals(newChar.SurName, StringComparison.InvariantCultureIgnoreCase))) { return("A character with that name already exists, please choose another."); } newChar.AccountHandle = GlobalIdentityHandle; newChar.Create(this, StaffRank.Player); //characters dont need approval yet but your rank is ALWAYS player here systemChars.Add(newChar); Characters = systemChars; return(string.Empty); }
/// <summary> /// Remove this object from the db permenantly /// </summary> /// <returns>success status</returns> public override bool Remove(IAccount remover, StaffRank rank) { DataAccess.FileSystem.PlayerData accessor = new DataAccess.FileSystem.PlayerData(); try { //Remove from cache first PlayerDataCache.Remove(new PlayerDataCacheKey(this)); //Remove it from the file system. accessor.ArchiveCharacter(this); } catch (Exception ex) { LoggingUtility.LogError(ex); return(false); } return(true); }
/// <summary> /// The backing data for this entity /// </summary> public override T Template <T>() { return((T)PlayerDataCache.Get(new PlayerDataCacheKey(typeof(IPlayerTemplate), AccountHandle, TemplateId))); }