//Create a method to check which of the two newCompanion or patient is Benificiary private static void CheckBeneficiary(Patient patient, CompanionModel newCompanion, List <Companion> existingCompanion, int?companionTypeId) { //DomainObjectRepository newDomain = new DomainObjectRepository(); //var companionTypeId = newDomain.Get<CompanionType>(ct => ct.CompanionType1 == newCompanion.CompanionType).CompanionTypeID; if (patient.IsBeneficiary == true && (patient.IsBeneficiary == newCompanion.IsBeneficiary && companionTypeId == (int)Enums.CompanionType.Primary)) { throw new PatientsMgtException(1, "error", "Creating new Companion", "The Patient is already benificiary!! " + "You can't have the companion as benificiary"); } if (patient.IsBeneficiary == false && (patient.IsBeneficiary == newCompanion.IsBeneficiary && companionTypeId == (int)Enums.CompanionType.Primary)) { throw new PatientsMgtException(1, "error", "Creating new Companion", "You need to set either the patient or the Companion as Beneficiary "); } // only one Companion asscoiated to the patient should be benificiary and not more var duplicateComp = new Companion(); duplicateComp = existingCompanion.SingleOrDefault(c => c.CompanionCID == newCompanion.CompanionCID); if (duplicateComp != null) { existingCompanion.Remove(duplicateComp); } if (newCompanion.IsBeneficiary == true && existingCompanion != null && existingCompanion.Any(comp => comp.IsBeneficiary == newCompanion.IsBeneficiary)) { throw new PatientsMgtException(1, "error", "Creating new Companion", "There is already one companion associated with the patient declared as beneficiary!!" + "\r\n Only one companion should be beneficiary"); } }
internal static bool UpdateCompanionModel(CompanionModel model) { var cachedModel = companionModels.FirstOrDefault(c => c.GetId() == model.GetId()); if (cachedModel is null) { CustomCompanions.monitor.Log($"No companion match found for {model.GetId()}; Did a content patch update the name?", StardewModdingAPI.LogLevel.Trace); return(false); } // Update our cached model model.Translations = cachedModel.Translations; companionModels[companionModels.IndexOf(cachedModel)] = model; // Update any existing companions using this model foreach (var activeCompanion in activeCompanions.SelectMany(c => c.Companions).Where(c => c.model.GetId() == model.GetId())) { // Do model update activeCompanion.UpdateModel(model); } foreach (var sceneryCompanion in sceneryCompanions.SelectMany(c => c.Companions).Where(c => c.model.GetId() == model.GetId())) { // Do model update sceneryCompanion.UpdateModel(model); } return(true); }
public CompanionViewModel(CompanionModel companionModel) { _companionModel = companionModel; _showHPDialogCommand = new RelayCommand(obj => true, obj => ShowHPDialog()); _searchMonstersCommand = new RelayCommand(obj => true, obj => SearchMonsters()); _viewMonsterCommand = new RelayCommand(obj => true, obj => ViewMonster()); _rollCompanionHPCommand = new RelayCommand(obj => true, obj => RollCompanionHP()); _acceptCommand = new RelayCommand(obj => true, obj => OnAccept()); _rejectCommand = new RelayCommand(obj => true, obj => OnReject()); }
public ActionResult Create(string patientcid) { CompanionModel companion = new CompanionModel(); if (!string.IsNullOrEmpty(patientcid)) { companion.PatientCID = patientcid; } companion.CompanionTypes = _companionManagmentRepository.GetCompanionTypes(); companion.Banks = _patientManagmentRepository.GetBanks(); return(View(companion)); }
public ActionResult Edit(CompanionModel companion) { ValidateCompanion(companion); if (ModelState.IsValid) { companion.ModifiedBy = User.Identity.Name; _companionRepository.UpdateCompanion(companion); Success(string.Format("companion with Civil Id <b>{0}</b> was successfully updated.", companion.CompanionCID), true); return(RedirectToAction("Details", "Companion", new { companionCid = companion.CompanionCID })); } else { Information(string.Format("companion with Civil Id <b>{0}</b> Was Not updated.", companion.CompanionCID), true); companion.CompanionTypes = _companionManagmentRepository.GetCompanionTypes(); companion.Banks = _patientManagmentRepository.GetBanks(); return(View(companion)); } }
public ActionResult Create(CompanionModel companion) { ValidateCompanion(companion); if (ModelState.IsValid) { companion.CreatedBy = User.Identity.Name; _companionRepository.AddCompanion(companion); Success(string.Format("Patient with Civil ID <b>{0}</b> was successfully added.", companion.CompanionCID), true); return(RedirectToAction("List")); } else { Danger(string.Format("Please correct the error list before proceeding"), true); companion.CompanionTypes = _companionManagmentRepository.GetCompanionTypes(); companion.Banks = _patientManagmentRepository.GetBanks(); return(View(companion)); } }
internal static void SummonCompanions(CompanionModel model, int numberToSummon, RingModel summoningRing, Farmer who, GameLocation location) { if (location.characters is null) { CustomCompanions.monitor.Log($"Unable to summon {model.Name} due to the location {location.Name} not having an instantiated GameLocation.characters!"); return; } List <Companion> companions = new List <Companion>(); for (int x = 0; x < numberToSummon; x++) { Companion companion = new Companion(model, who); location.characters.Add(companion); companions.Add(companion); } activeCompanions.Add(new BoundCompanions(summoningRing, companions)); }
internal static bool CompanionHasFullMovementSet(CompanionModel model) { if (model.UpAnimation is null) { return(false); } if (model.RightAnimation is null) { return(false); } if (model.DownAnimation is null) { return(false); } if (model.LeftAnimation is null) { return(false); } return(true); }
public void UpdateCompanionTest() { CompanionModel companion = new CompanionModel() { CompanionCID = "345345901122", CompanionFName = "Newton", CompanionMName = "tim", CompanionLName = "Newoman", CompanionType = "primary", DateIn = new DateTime(2018, 3, 3), DateOut = null, IsActive = true, IBan = "2222222225555", BankName = "bank of america", IsBeneficiary = false, Notes = "Some notes from companion", PatientCID = "333432901010", CreatedBy = "Mounir", }; _companionRepository.UpdateCompanion(companion); }
internal static void SummonCompanions(CompanionModel model, int numberToSummon, Vector2 tile, GameLocation location) { if (location.characters is null) { CustomCompanions.monitor.Log($"Unable to summon {model.Name} due to the location {location.Name} not having an instantiated GameLocation.characters!"); return; } List <Companion> companions = new List <Companion>(); for (int x = 0; x < numberToSummon; x++) { MapCompanion companion = new MapCompanion(model, tile, location); companions.Add(companion); } var sceneryCompanion = new SceneryCompanions(location, tile, companions); if (sceneryCompanions.Any(s => s.Tile == tile && s.Location == location)) { // Clear out old companions, add in the new ones foreach (var scenery in sceneryCompanions.Where(s => s.Tile == tile && s.Location == location)) { scenery.ReplaceAssociatedCompanions(companions, location); } } else { sceneryCompanions.Add(sceneryCompanion); } // Ensures each collision based companion is moved to an empty tile companions.ForEach(c => location.characters.Add(c)); foreach (var companion in companions.Where(c => c.collidesWithOtherCharacters)) { companion.PlaceInEmptyTile(); } }
/// <summary> /// Shows create companion dialog /// </summary> public CompanionModel ShowCreateCompanionDialog(string title, CompanionModel companionModel) { ModalDialog modalDialog = new ModalDialog(); if (_parentWindow != null) { modalDialog.Owner = _parentWindow; } CompanionModel companionModelCopy = new CompanionModel(companionModel); CompanionViewModel companionViewModel = new CompanionViewModel(companionModelCopy); companionViewModel.InitializeMonsterOptions(); CreateCompanionView createCompanionView = new CreateCompanionView(companionViewModel); modalDialog.WindowTitle = title; modalDialog.Body = createCompanionView; modalDialog.Confirmation = createCompanionView.ViewModel; bool?result = ShowDialog(modalDialog); return(result == true ? companionModelCopy : null); }
public CompanionModel GetCompanion(string companioncid) { CompanionModel coModel; var companion = _domainObjectRepository.Get <Companion>(c => c.CompanionCID == companioncid); if (companion != null) { coModel = new CompanionModel() { CompanionCID = companion.CompanionCID, BankName = _domainObjectRepository.Get <Bank>(b => b.BankID == companion.BankID)?.BankName, CompanionFName = companion.CompanionFName, CompanionMName = companion.CompanionMName, CompanionLName = companion.CompanionLName, CompanionType = _domainObjectRepository.Get <CompanionType>(ct => ct.CompanionTypeID == companion.CompanionTypeID)?.CompanionType1, DateIn = companion.DateIn, DateOut = companion.DateOut, IsActive = companion.IsActive == true ? true : false, IBan = companion.IBan, BankCode = _domainObjectRepository.Get <Bank>(b => b.BankID == companion.BankID)?.BankCode, IsBeneficiary = companion.IsBeneficiary == true ? true : false, Notes = companion.Notes, PatientCID = companion.PatientCID, CreatedBy = companion.CreatedBy, CreatedDate = companion.CreatedDate, ModifiedDate = companion.ModifiedDate, Id = companion.Id, ModifiedBy = companion.ModifiedBy }; } else { coModel = new CompanionModel(); } return(coModel); }
private void ValidateCompanion(CompanionModel companion) { var companionType = _companionManagmentRepository.GetCompanionTypes() .Where(c => c.Id == (int)Enums.CompanionType.Primary) .Select(ct => ct.CompanionType).FirstOrDefault(); // get the patient Associated with this companion if (companion.PatientCID != null) { var patient = _patientRepository.GetPatient(companion.PatientCID); if (patient == null && ModelState.IsValidField("PatientCID")) { ModelState.AddModelError("PatientCID", companion.PatientCID + " is an incorrect Patient Cid, There is not patient in our record with this Cid"); } if (patient != null && ModelState.IsValidField("PatientCID")) { if (patient.IsActive) { if (patient.IsBeneficiary && companion.IsBeneficiary) { ModelState.AddModelError("IsBeneficiary", "The patient with " + companion.PatientCID + " CID associated with this companion is already Beneficiary, You can't have the companion as beneficiary"); } if (!patient.IsBeneficiary && !companion.IsBeneficiary) { if (ModelState.IsValidField("CompanionType") && companion.CompanionType == companionType) { ModelState.AddModelError("IsBeneficiary", "The patient with " + companion.PatientCID + " CID associated with this companion is Not Beneficiary, So you need to set this companion as Beneficiary"); } } } } if (patient != null) { if (ModelState.IsValidField("CompanionType") && companion.CompanionType == companionType) { var existingCompanions = _companionRepository.GetCompanions().Where(c => c.PatientCID == companion.PatientCID && c.IsActive); foreach (var comp in existingCompanions.Where(c => c.IsActive == true)) { if (comp.CompanionCID != companion.CompanionCID) { if (comp.CompanionType == companionType) { ModelState.AddModelError("CompanionType", "There is already a companion with the patient declared as Primary, You can't have this companion as primary"); break; } } } } // see if there is a c primary companion with this patient, we can't have two companion as primary } } if (ModelState.IsValidField("IsBeneficiary") && companion.IsBeneficiary == true && companion.IBan == null) { ModelState.AddModelError("IBan", "Since the companion is Beneficiary, you need to enter the Bank Account field"); } if (ModelState.IsValidField("IsBeneficiary") && companion.IsBeneficiary == true && companion.BankName == null) { ModelState.AddModelError("BankName", "Since the companion is Beneficiary, you need to enter the Bank Name field"); } if (ModelState.IsValidField("IsBeneficiary") && companion.IsBeneficiary == false && companion.BankName != null) { ModelState.AddModelError("BankName", "The companion is Not Beneficiary, so no need to enter the Bank Name field"); } if (ModelState.IsValidField("IsBeneficiary") && companion.IsBeneficiary == false && companion.IBan != null) { ModelState.AddModelError("IBan", "The companion is Not Beneficiary, so no need to enter the Bank Account field"); } if (ModelState.IsValidField("isActive") && companion.IsActive == false && companion.DateOut == null) { ModelState.AddModelError("DateOut", "The companion is not active, so you need to enter the Date out field"); } if (ModelState.IsValidField("DateOut") && companion.DateOut != null && companion.IsActive) { ModelState.AddModelError("IsActive", "Date out is set, so the companion Active status should be No"); } // if the companion is not Primary and the user select it to be beneficiary if (ModelState.IsValidField("CompanionType")) { if (companion.IsBeneficiary && companion.CompanionType != companionType) { ModelState.AddModelError("CompanionType", companion.CompanionType + " Can't be Beneficiary, Only " + companionType + " companion who can"); } } }
private void LoadContentPacks(bool isReload = false) { this.Reset(false, isReload); // Load the owned content packs foreach (IContentPack contentPack in Helper.ContentPacks.GetOwned()) { Monitor.Log($"Loading companions from pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} by {contentPack.Manifest.Author}", LogLevel.Debug); var companionFolders = new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "Companions")).GetDirectories(); if (companionFolders.Count() == 0) { Monitor.Log($"No sub-folders found under Companions for the content pack {contentPack.Manifest.Name}!", LogLevel.Warn); continue; } // Load in the companions foreach (var companionFolder in companionFolders) { if (!File.Exists(Path.Combine(companionFolder.FullName, "companion.json"))) { Monitor.Log($"Content pack {contentPack.Manifest.Name} is missing a companion.json under {companionFolder.Name}!", LogLevel.Warn); continue; } CompanionModel companion = contentPack.ReadJsonFile <CompanionModel>(Path.Combine(companionFolder.Parent.Name, companionFolder.Name, "companion.json")); companion.Name = companion.Name.Replace(" ", ""); companion.Owner = contentPack.Manifest.UniqueID; // Save the TileSheet, if one is given if (String.IsNullOrEmpty(companion.TileSheetPath) && !File.Exists(Path.Combine(companionFolder.FullName, "companion.png"))) { Monitor.Log($"Unable to add companion {companion.Name} from {contentPack.Manifest.Name}: No associated companion.png or TileSheetPath given", LogLevel.Warn); continue; } else if (String.IsNullOrEmpty(companion.TileSheetPath)) { companion.TileSheetPath = contentPack.ModContent.GetInternalAssetName(Path.Combine(companionFolder.Parent.Name, companionFolder.Name, "companion.png")).Name; } // Save the PortraitSheet, if one is given if (companion.Portrait != null) { if (!File.Exists(Path.Combine(companionFolder.FullName, "portrait.png"))) { Monitor.Log($"Warning for companion {companion.Name} from {contentPack.Manifest.Name}: Portrait property was given but no portrait.png was found", LogLevel.Warn); } else { companion.PortraitSheetPath = contentPack.ModContent.GetInternalAssetName(Path.Combine(companionFolder.Parent.Name, companionFolder.Name, "portrait.png")).Name; } } if (contentPack.Translation != null) { companion.Translations = contentPack.Translation; } Monitor.Log(companion.ToString(), LogLevel.Trace); // Add the companion to our cache CompanionManager.companionModels.Add(companion); // Cache the full name of the companion, so that it can be reference by a Content Patcher token if (_contentPatcherApi != null) { var assetToken = $"{TOKEN_HEADER}{companion.GetId()}"; AssetManager.idToAssetToken[companion.GetId()] = assetToken; if (!isReload) { var modelObject = Helper.GameContent.Load <TokenModel>(assetToken); //var modelObject = AssetManager.GetCompanionModelObject(Helper.Content.Load<Dictionary<string, object>>(assetToken, ContentSource.GameContent)); trackedModels[$"{CustomCompanions.TOKEN_HEADER}{companion.GetId()}"] = modelObject.Companion; } } } if (_jsonAssetsApi != null && !isReload) { // Load in the rings that will be paired to a companion if (!Directory.Exists(Path.Combine(contentPack.DirectoryPath, "Objects"))) { Monitor.Log($"No summoning rings available from {contentPack.Manifest.Name}, this may be intended", LogLevel.Trace); continue; } foreach (var ringFolder in new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "Objects")).GetDirectories()) { if (!File.Exists(Path.Combine(ringFolder.FullName, "object.json"))) { Monitor.Log($"Content pack {contentPack.Manifest.Name} is missing a object.json under {ringFolder.Name}!", LogLevel.Warn); continue; } RingModel ring = contentPack.ReadJsonFile <RingModel>(Path.Combine(ringFolder.Parent.Name, ringFolder.Name, "object.json")); ring.Owner = contentPack.Manifest.UniqueID; RingManager.rings.Add(ring); } // Generate content.json for Json Assets contentPack.WriteJsonFile("content-pack.json", new ContentPackModel { Name = contentPack.Manifest.Name, Author = contentPack.Manifest.Author, Version = contentPack.Manifest.Version.ToString(), Description = contentPack.Manifest.Description, UniqueID = contentPack.Manifest.UniqueID, UpdateKeys = contentPack.Manifest.UpdateKeys, }); // Load in the associated rings objects (via JA) _jsonAssetsApi.LoadAssets(contentPack.DirectoryPath); } } }
private void UpdateBeneficiary(CompanionModel companion, Companion companionToUpdate, Patient patient) { var ben = _domainObjectRepository.Get <Beneficiary>(b => b.PatientCID == companion.PatientCID); if (ben != null) { if (companionToUpdate.IsActive == false) { ben.CompanionCID = null; if (ben.BeneficiaryCID == companion.CompanionCID) { if (patient.IsBeneficiary == false && patient.IsActive == true) { throw new PatientsMgtException(1, "Error", "Update Companion", "the primary companion associated with the patient is no " + "longer active, and the patient is not beneficiary, " + "Make the patient beneficary or add a another primary companion " + "who is beneficiary before setting this comapnion as inactive"); } else if (patient.IsBeneficiary == true) { ben.BeneficiaryCID = patient.PatientCID; ben.BeneficiaryFName = patient.PatientFName; ben.BeneficiaryLName = patient.PatientLName; ben.BeneficiaryMName = patient.PatientMName; ben.BankID = patient.BankID; ben.IBan = patient.Iban; } } _domainObjectRepository.Update <Beneficiary>(ben); return; } if (companion.IsBeneficiary == true && ben.BeneficiaryCID != companion.CompanionCID) { ben.BeneficiaryCID = companion.CompanionCID; ben.BeneficiaryFName = companion.CompanionFName; ben.BeneficiaryLName = companion.CompanionLName; ben.BeneficiaryMName = companion.CompanionMName; ben.BankID = _domainObjectRepository.Get <Bank>(b => b.BankName == companion.BankName).BankID; ben.IBan = companion.IBan; _domainObjectRepository.Update <Beneficiary>(ben); } if (companion.IsBeneficiary == false && ben.BeneficiaryCID == companion.CompanionCID) { if (patient.IsBeneficiary == false) { throw new PatientsMgtException(1, "Error", "Update Companion", "Neither the patient or the companion are beneficiary, Make one of them beneficiary to make an update"); } else { ben.BeneficiaryCID = patient.PatientCID; ben.BeneficiaryFName = patient.PatientFName; ben.BeneficiaryLName = patient.PatientLName; ben.BeneficiaryMName = patient.PatientMName; ben.BankID = patient.BankID; ben.IBan = patient.Iban; _domainObjectRepository.Update <Beneficiary>(ben); } } //when the companion is not beneficiary but he is primary companion, the beneficiary table companion cid should be update it to take the primary comanion cid if (companionToUpdate.IsActive == true && (companionToUpdate.CompanionTypeID == (int)Enums.CompanionType.Primary)) { if (ben.CompanionCID != companionToUpdate.CompanionCID) { ben.CompanionCID = companionToUpdate.CompanionCID; _domainObjectRepository.Update <Beneficiary>(ben); } } } }
public CompanionModel UpdateCompanion(CompanionModel companion) { var companionToUpdate = _domainObjectRepository.Get <Companion>(c => c.CompanionCID == companion.CompanionCID && c.PatientCID == companion.PatientCID); var newCompanionTypeid = _domainObjectRepository.Get <CompanionType>(ct => ct.CompanionType1 == companion.CompanionType)? .CompanionTypeID; if (companionToUpdate != null) { companionToUpdate.CompanionCID = companion.CompanionCID; companionToUpdate.BankID = _domainObjectRepository.Get <Bank>(b => b.BankName == companion.BankName)?.BankID; companionToUpdate.CompanionFName = companion.CompanionFName; companionToUpdate.CompanionMName = companion.CompanionMName; companionToUpdate.CompanionLName = companion.CompanionLName; companionToUpdate.CompanionTypeID = newCompanionTypeid; companionToUpdate.DateIn = companion.DateIn; companionToUpdate.DateOut = companion.DateOut; companionToUpdate.IsActive = companion.IsActive; companionToUpdate.IBan = companion.IBan; companionToUpdate.BankID = _domainObjectRepository.Get <Bank>(b => b.BankName == companion.BankName)?.BankID; companionToUpdate.IsBeneficiary = companion.IsBeneficiary; companionToUpdate.Notes = companion.Notes; companionToUpdate.PatientCID = companion.PatientCID; companionToUpdate.ModifiedBy = companion.ModifiedBy; if (companion.IsActive == false && companion.DateOut == null) { companionToUpdate.DateOut = DateTime.Now; } else if (companion.IsActive == true) { companionToUpdate.DateOut = null; } // check if the patient is not beneficiary before doing the update to a beneficiary companion var patient = _domainObjectRepository.Get <Patient>(p => p.PatientCID == companion.PatientCID); CompanionRepository companionRepo = new CompanionRepository(); var companionList = companionRepo.GetCompanionListByPatientCid(companion.PatientCID); // Assert that the user make an update according to the rules CheckBeneficiary(patient, companion, companionList, newCompanionTypeid); // no 2 companions should be beneficiary or confelect with the patient CheckCompanionType(companionList.Where(c => c.IsActive == true)?.ToList(), newCompanionTypeid); // No 2 companions should have primary as a type if (companionToUpdate.IsBeneficiary == true && (companionToUpdate.Bank == null || String.IsNullOrEmpty(companionToUpdate.IBan))) { throw new PatientsMgtException(1, "error", "Update a Companion", "You must eneter the bank info! since this companion is beneficiary"); } if (companionToUpdate.IsBeneficiary == true && companionToUpdate.IsActive == false) { throw new PatientsMgtException(1, "error", "Update a Companion", "The companion should be active since is beneficiary"); } if (companionToUpdate.IsBeneficiary == true && companionToUpdate.CompanionTypeID == (int)Enums.CompanionType.Secondary) { throw new PatientsMgtException(1, "error", "Update a Companion", String.Format("The companion should not be {0} since is beneficiary", companionToUpdate?.CompanionType?.CompanionType1)); } if (companionToUpdate.IsActive == false && companionToUpdate.DateOut == null) { throw new PatientsMgtException(1, "error", "Update a Companion", String.Format("You have set the companion as inactive, so the date out should be set", companionToUpdate?.CompanionType?.CompanionType1)); } // whene every rule is complied with, we do an update _domainObjectRepository.Update <Companion>(companionToUpdate); //insert into history when the companion is not active, or date out is set if (companionToUpdate.IsActive == false && companionToUpdate.DateOut != null) { InsertIntoCompanionHistoryTable(companionToUpdate); } //Update the beneficiary table UpdateBeneficiary(companion, companionToUpdate, patient); } return(companion); }
internal void ManualReload(string packUniqueId) { this.RemoveAllCompanions(owner: packUniqueId); // Reset the tracked validation counter this.modelValidationIndex = 0; // Set up the CompanionManager CompanionManager.activeCompanions = CompanionManager.activeCompanions.Where(c => !c.Companions.Any(m => m.model.Owner.Equals(packUniqueId, StringComparison.OrdinalIgnoreCase))).ToList(); CompanionManager.sceneryCompanions = CompanionManager.sceneryCompanions.Where(c => !c.Companions.Any(m => m.model.Owner.Equals(packUniqueId, StringComparison.OrdinalIgnoreCase))).ToList(); // Load the owned content packs foreach (IContentPack contentPack in Helper.ContentPacks.GetOwned().Where(c => c.Manifest.UniqueID.Equals(packUniqueId, StringComparison.OrdinalIgnoreCase))) { Monitor.Log($"Loading companions from pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} by {contentPack.Manifest.Author}", LogLevel.Debug); var companionFolders = new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "Companions")).GetDirectories(); if (companionFolders.Count() == 0) { Monitor.Log($"No sub-folders found under Companions for the content pack {contentPack.Manifest.Name}!", LogLevel.Warn); continue; } // Load in the companions foreach (var companionFolder in companionFolders) { if (!File.Exists(Path.Combine(companionFolder.FullName, "companion.json"))) { Monitor.Log($"Content pack {contentPack.Manifest.Name} is missing a companion.json under {companionFolder.Name}!", LogLevel.Warn); continue; } CompanionModel companion = contentPack.ReadJsonFile <CompanionModel>(Path.Combine(companionFolder.Parent.Name, companionFolder.Name, "companion.json")); companion.Name = companion.Name.Replace(" ", ""); companion.Owner = contentPack.Manifest.UniqueID; Monitor.Log(companion.ToString(), LogLevel.Trace); // Save the TileSheet, if one is given if (String.IsNullOrEmpty(companion.TileSheetPath) && !File.Exists(Path.Combine(companionFolder.FullName, "companion.png"))) { Monitor.Log($"Unable to add companion {companion.Name} from {contentPack.Manifest.Name}: No associated companion.png or TileSheetPath given", LogLevel.Warn); continue; } else if (String.IsNullOrEmpty(companion.TileSheetPath)) { companion.TileSheetPath = contentPack.ModContent.GetInternalAssetName(Path.Combine(companionFolder.Parent.Name, companionFolder.Name, "companion.png")).Name; } // Save the PortraitSheet, if one is given if (companion.Portrait != null) { if (!File.Exists(Path.Combine(companionFolder.FullName, "portrait.png"))) { Monitor.Log($"Warning for companion {companion.Name} from {contentPack.Manifest.Name}: Portrait property was given but no portrait.png was found", LogLevel.Warn); } else { companion.PortraitSheetPath = contentPack.ModContent.GetInternalAssetName(Path.Combine(companionFolder.Parent.Name, companionFolder.Name, "portrait.png")).Name; } } if (contentPack.Translation != null) { companion.Translations = contentPack.Translation; } // Cache the full name of the companion, so that it can be reference by a Content Patcher token if (_contentPatcherApi != null) { var assetToken = $"{TOKEN_HEADER}{companion.GetId()}"; AssetManager.idToAssetToken[companion.GetId()] = assetToken; var modelObject = Helper.GameContent.Load <TokenModel>(assetToken); //var modelObject = AssetManager.GetCompanionModelObject(Helper.Content.Load<Dictionary<string, object>>(assetToken, ContentSource.GameContent)); trackedModels[$"{CustomCompanions.TOKEN_HEADER}{companion.GetId()}"] = modelObject.Companion; } } } this.SpawnSceneryCompanions(Game1.player.currentLocation); // Remove companions that no longer have an existing map tile property this.RemoveOrphanCompanions(Game1.player.currentLocation); }
public void AddCompanion(CompanionModel companion) { var existingRecord = _domainObjectRepository.Get <Companion>( c => c.CompanionCID == companion.CompanionCID && c.PatientCID == companion.PatientCID); if (existingRecord != null) { throw new PatientsMgtException(1, "error", "Create new Companion", "There is aleady a record with the same companion and patient"); } if (!String.IsNullOrEmpty(companion.PatientCID)) { var newCompanionTypeid = _domainObjectRepository.Get <CompanionType>(ct => ct.CompanionType1 == companion.CompanionType)? .CompanionTypeID; #region Validate companion Type //check if already there is a newCompanion associated with the pationcid in table who is primary //we should not have two companions with primary type account CompanionRepository companionRepo = new CompanionRepository(); var companionList = companionRepo.GetCompanionListByPatientCid(companion.PatientCID); if (companionList != null && companionList.Count > 0)//patient is already in table with other newCompanion { //check if this other companion with the same patient that are primary if (newCompanionTypeid == (int)Enums.CompanionType.Primary) { CheckCompanionType(companionList.Where(c => c.IsActive == true)?.ToList(), newCompanionTypeid); } } // #endregion var patient = _domainObjectRepository.Get <Patient>(p => p.PatientCID == companion.PatientCID); if (patient != null) { #region validate beneficiary CheckBeneficiary(patient, companion, companionList, newCompanionTypeid); #endregion Companion newCompanion = new Companion() { CompanionCID = companion.CompanionCID, CompanionFName = companion.CompanionFName, CompanionMName = companion.CompanionMName, CompanionLName = companion.CompanionLName, CompanionTypeID = newCompanionTypeid, DateIn = companion.DateIn, DateOut = companion.DateOut, IsActive = companion.IsActive, // == "Yes" ? true : false, IBan = companion.IBan, BankID = _domainObjectRepository.Get <Bank>(b => b.BankName == companion.BankName)?.BankID, IsBeneficiary = companion.IsBeneficiary, // == "Yes" ? true : false, Notes = companion.Notes, PatientCID = companion.PatientCID, CreatedBy = companion.CreatedBy }; // check if the user entered a bank info when the companion is set as primary and beneficiary _domainObjectRepository.Create <Companion>(newCompanion); // once we created the Companion with a primary type companiontype, we need to call a method that does an insert into Beneficiary table // if the user is not primary then should not be beneficiary if ((newCompanionTypeid == (int)Enums.CompanionType.Primary) && newCompanion.IsActive == true) { // this Beneficiary can be a ptient himself if he is Beneficiary by default InsertIntoBeneficiaryTable(patient, newCompanion); } } } }