/// <summary> /// Refresh the market details for a ship fit. /// </summary> /// <param name="shipFit">A doctrine ships ship fit.</param> /// <param name="settingProfile">A doctrine ships account setting profile.</param> internal void RefreshShipFitMarketDetails(ShipFit shipFit, SettingProfile settingProfile) { // Only update the ship fit prices if they are older than 5 minutes. if (Time.HasElapsed(shipFit.LastPriceRefresh, TimeSpan.FromMinutes(5)) == true) { // Update the buy and sell prices of all ship fit components. this.RefreshShipFitComponentsPrices(shipFit, settingProfile); // Ship Fit Calculations. shipFit.BuyPrice = shipFit.ShipFitComponents.Sum(x => (x.BuyPrice * x.Quantity)); shipFit.SellPrice = shipFit.ShipFitComponents.Sum(x => (x.SellPrice * x.Quantity)); shipFit.ShippingCost = shipFit.FitPackagedVolume * settingProfile.ShippingCostPerM3; shipFit.ContractReward = (shipFit.SellPrice * settingProfile.ContractMarkupPercentage) + shipFit.ShippingCost + settingProfile.ContractBrokerFee; shipFit.BuyOrderProfit = shipFit.ContractReward - shipFit.BuyPrice; shipFit.SellOrderProfit = shipFit.ContractReward - shipFit.SellPrice; // Set the ship fit's last price refresh timestamp to the current date & time. shipFit.LastPriceRefresh = DateTime.UtcNow; // Update the ship fit in the database. this.doctrineShipsRepository.UpdateShipFit(shipFit); // Commit changes to the database. this.doctrineShipsRepository.Save(); } }
public ActionResult UpdateSettings(AccountSettingsViewModel viewModel) { if (ModelState.IsValid) { // Create an Auto Mapper map between the setting profile entity and the view model. Mapper.CreateMap <AccountSettingsViewModel, SettingProfile>(); // Convert the currently logged-in account id to an integer. viewModel.AccountId = Conversion.StringToInt32(User.Identity.Name); // Populate a setting profile with automapper and pass it back to the service layer for update. SettingProfile settingProfile = Mapper.Map <AccountSettingsViewModel, SettingProfile>(viewModel); var result = this.doctrineShipsServices.UpdateSettingProfile(settingProfile); // If the result is false, something did not validate in the service layer. if (result != false) { TempData["Status"] = "The settings were successfully updated."; } else { TempData["Status"] = "Error: The settings were not updated, a validation error occured."; } return(RedirectToAction("Settings")); } else { return(View("~/Views/Account/Settings.cshtml", viewModel)); } }
/// <summary> /// Adds a default setting profile to an account. This method does not commit to the database itself. /// </summary> /// <param name="accountId">The id of the account for which a setting profile should be generated.</param> /// <returns>The new setting profile id or 0 if an error occurs.</returns> internal int AddDefaultSettingProfile(int accountId) { int settingProfileId = 0; // Fetch the default setting profile (Id 0). var defaultSettingProfile = this.doctrineShipsRepository.GetSettingProfileReadOnly(0); if (defaultSettingProfile != null) { // Create an Auto Mapper map between setting profile entities, ignoring the primary key. Mapper.CreateMap <SettingProfile, SettingProfile>() .ForMember(x => x.SettingProfileId, opt => opt.Ignore()) .ForMember(x => x.AccountId, opt => opt.Ignore()); // Assign the default setting profile to a new setting profile object. SettingProfile newSettingProfile = Mapper.Map <SettingProfile, SettingProfile>(defaultSettingProfile); // Assign the passed account id to the new object. newSettingProfile.AccountId = accountId; // Add the new setting profile and read it back to capture the new auto-generated id. newSettingProfile = this.doctrineShipsRepository.CreateSettingProfile(newSettingProfile); // Assign the new setting profile id as the return value. settingProfileId = newSettingProfile.SettingProfileId; } else { // If a default setting profile is not found, log it and throw an exception. logger.LogMessage("A Default Setting Profile Was Not Found.", 0, "Message", MethodBase.GetCurrentMethod().Name); throw new ArgumentException("A Default Setting Profile Was Not Found."); } return(settingProfileId); }
/// <summary> /// Refresh the market prices of all components in a ship fit. /// </summary> /// <param name="shipFit">A doctrine ships ship fit.</param> /// <param name="settingProfile">A doctrine ships account setting profile.</param> internal void RefreshShipFitComponentsPrices(ShipFit shipFit, SettingProfile settingProfile) { double buyPrice; double sellPrice; IDictionary <int, double> buyPrices; IDictionary <int, double> sellPrices; // Ensure that there are ship fit components to be refreshed. if (shipFit.ShipFitComponents != null && shipFit.ShipFitComponents.Any() != false) { buyPrices = this.eveDataSource.GetStationBuyPrice(shipFit.ShipFitComponents.Select(x => x.ComponentId).ToList(), settingProfile.BuyStationId); sellPrices = this.eveDataSource.GetStationSellPrice(shipFit.ShipFitComponents.Select(x => x.ComponentId).ToList(), settingProfile.SellStationId); foreach (var item in shipFit.ShipFitComponents) { buyPrices.TryGetValue(item.ComponentId, out buyPrice); sellPrices.TryGetValue(item.ComponentId, out sellPrice); item.BuyPrice = buyPrice * settingProfile.BrokerPercentage; item.SellPrice = sellPrice; item.ObjectState = ObjectState.Modified; } } }
/// <summary> /// Updates a setting profile for a particular account. /// </summary> /// <param name="settingProfile">A setting profile object to be updated.</param> /// <returns>Returns true if the update was successful or false if not.</returns> internal bool UpdateSettingProfile(SettingProfile settingProfile) { // Validate the setting profile updates. if (this.doctrineShipsValidation.SettingProfile(settingProfile).IsValid == true) { // Update the existing record, save and log. this.doctrineShipsRepository.UpdateSettingProfile(settingProfile); this.doctrineShipsRepository.Save(); logger.LogMessage("Setting Profile Updated For Account Id: " + settingProfile.AccountId, 2, "Message", MethodBase.GetCurrentMethod().Name); return(true); } return(false); }
/// <summary> /// Fetches and returns a Doctrine Ships ship fit. /// </summary> /// <param name="shipFitId">The id for which a ship fit object should be returned.</param> /// <param name="settingProfile">A doctrine ships account setting profile.</param> /// <param name="accountId">The currently logged-in account id for security checking.</param> /// <returns>A ship fit object.</returns> internal ShipFit GetShipFitDetail(int shipFitId, int accountId, SettingProfile settingProfile) { ShipFit shipFit = this.doctrineShipsRepository.GetShipFit(shipFitId); if (shipFit != null) { if (accountId == shipFit.AccountId) { // Refresh the market details for the ship fit. this.RefreshShipFitMarketDetails(shipFit, settingProfile); return(shipFit); } } return(null); }
/// <summary> /// <para>Adds a sales agent from an api key and account id.</para> /// </summary> /// <param name="apiId">A valid eve api id (keyID).</param> /// <param name="apiKey">A valid eve api key (vCode).</param> /// <param name="accountId">The id of the account for which a sales agent should be added.</param> /// <returns>Returns a validation result object.</returns> public async Task <IValidationResult> AddSalesAgent(int apiId, string apiKey, int accountId) { IValidationResult validationResult; validationResult = SalesAgentManager.AddSalesAgent(apiId, apiKey, accountId); // If the sales agent addition was successful, notify the account twitter account. if (validationResult.IsValid) { SettingProfile settingProfile = AccountManager.GetAccountSettingProfile(accountId); await TaskManager.SendDirectMessage(this.doctrineShipsSettings.TwitterContext, settingProfile.TwitterHandle, "A Sales Agent Was Added To Account: " + accountId); } return(validationResult); }
/// <summary> /// <para>Deletes a setting profile from an accountId and a settingProfileId.</para> /// </summary> /// <param name="accountId">The account Id of the requestor. The account Id should own the setting profile being deleted.</param> /// <param name="settingProfileId">The Id of the setting profile to be deleted.</param> /// <returns>Returns true if the deletion was successful or false if not.</returns> internal bool DeleteSettingProfile(int accountId, int settingProfileId) { SettingProfile settingProfile = this.doctrineShipsRepository.GetSettingProfile(settingProfileId); if (settingProfile != null) { // If the account Id matches the account Id of the setting profile being deleted, continue. if (accountId == settingProfile.AccountId) { // Delete the setting profile and log the event. this.doctrineShipsRepository.DeleteSettingProfile(settingProfile.SettingProfileId); this.doctrineShipsRepository.Save(); logger.LogMessage("Setting Profile '" + settingProfile.SettingProfileId + "' Successfully Deleted For Account Id: " + settingProfile.AccountId, 1, "Message", MethodBase.GetCurrentMethod().Name); return(true); } } return(false); }
internal void UpdateSettingProfile(SettingProfile settingProfile) { settingProfile.ObjectState = ObjectState.Modified; this.unitOfWork.Repository<SettingProfile>().Update(settingProfile); }
internal SettingProfile AddSettingProfile(SettingProfile settingProfile) { this.unitOfWork.Repository<SettingProfile>().Insert(settingProfile); return settingProfile; }
internal SettingProfile CreateSettingProfile(SettingProfile settingProfile) { settingProfile.ObjectState = ObjectState.Added; this.unitOfWork.Repository<SettingProfile>().Insert(settingProfile); return settingProfile; }
internal IValidationResult SettingProfile(SettingProfile settingProfile) { IValidationResult validationResult = new ValidationResult(); var existingSettingProfile = this.doctrineShipsRepository.GetSettingProfileReadOnly(settingProfile.SettingProfileId); // Does the setting profile exist in the database? if (existingSettingProfile == null) { validationResult.AddError("SettingProfile.Null", "The setting profile being modified does not exist in the database."); } else { // Does the setting profile being modified belong to the requesting account? if (existingSettingProfile.AccountId != settingProfile.AccountId) { validationResult.AddError("SettingProfile.Permission", "The setting profile being modified does not belong to the requesting account."); } } // Null checks. if (settingProfile.TwitterHandle == null) { validationResult.AddError("TwitterHandle.Null", "TwitterHandle cannot be null."); } // Regex checks. if (settingProfile.TwitterHandle != null) { if (!Regex.Match(settingProfile.TwitterHandle, "^@(\\w){1,15}$").Success) { validationResult.AddError("TwitterHandle.Format", "Invalid twitter handle."); } } // Range checks. if (settingProfile.BrokerPercentage < 0 || settingProfile.BrokerPercentage > 100) { validationResult.AddError("BrokerPercentage.Range", "BrokerPercentage is outside of expected ranges."); } if (settingProfile.SalesTaxPercentage < 0 || settingProfile.SalesTaxPercentage > 100) { validationResult.AddError("SalesTaxPercentage.Range", "SalesTaxPercentage is outside of expected ranges."); } if (settingProfile.ContractMarkupPercentage < 0 || settingProfile.ContractMarkupPercentage > 100) { validationResult.AddError("ContractMarkupPercentage.Range", "ContractMarkupPercentage is outside of expected ranges."); } if (settingProfile.ContractBrokerFee < 0 || settingProfile.ContractBrokerFee > double.MaxValue) { validationResult.AddError("ContractBrokerFee.Range", "ContractBrokerFee is outside of expected ranges."); } if (settingProfile.ShippingCostPerM3 < 0 || settingProfile.ShippingCostPerM3 > double.MaxValue) { validationResult.AddError("ShippingCostPerM3.Range", "ShippingCostPerM3 is outside of expected ranges."); } if (settingProfile.BuyStationId < 0 || settingProfile.BuyStationId > int.MaxValue) { validationResult.AddError("BuyStationId.Range", "BuyStationId is outside of expected ranges."); } if (settingProfile.SellStationId < 0 || settingProfile.SellStationId > int.MaxValue) { validationResult.AddError("SellStationId.Range", "SellStationId is outside of expected ranges."); } if (settingProfile.AlertThreshold < 0 || settingProfile.AlertThreshold > int.MaxValue) { validationResult.AddError("AlertThreshold.Range", "AlertThreshold is outside of expected ranges."); } return validationResult; }
public void UpdateSettingProfile(SettingProfile settingProfile) { SettingProfileOperations.UpdateSettingProfile(settingProfile); }
/// <summary> /// Updates a setting profile for a particular account. /// </summary> /// <param name="settingProfile">A setting profile object to be updated.</param> /// <returns>Returns true if the update was successful or false if not.</returns> internal bool UpdateSettingProfile(SettingProfile settingProfile) { // Validate the setting profile updates. if (this.doctrineShipsValidation.SettingProfile(settingProfile).IsValid == true) { // Update the existing record, save and log. this.doctrineShipsRepository.UpdateSettingProfile(settingProfile); this.doctrineShipsRepository.Save(); logger.LogMessage("Setting Profile Updated For Account Id: " + settingProfile.AccountId, 2, "Message", MethodBase.GetCurrentMethod().Name); return true; } return false; }
internal void UpdateSettingProfile(SettingProfile settingProfile) { settingProfile.ObjectState = ObjectState.Modified; this.unitOfWork.Repository <SettingProfile>().Update(settingProfile); }
internal SettingProfile AddSettingProfile(SettingProfile settingProfile) { this.unitOfWork.Repository <SettingProfile>().Insert(settingProfile); return(settingProfile); }
/// <summary> /// Updates a setting profile for a particular account. /// </summary> /// <param name="settingProfile">A setting profile object to be updated.</param> /// <returns>Returns true if the update was successful or false if not.</returns> public bool UpdateSettingProfile(SettingProfile settingProfile) { return AccountManager.UpdateSettingProfile(settingProfile); }
internal IValidationResult SettingProfile(SettingProfile settingProfile) { IValidationResult validationResult = new ValidationResult(); var existingSettingProfile = this.doctrineShipsRepository.GetSettingProfileReadOnly(settingProfile.SettingProfileId); // Does the setting profile exist in the database? if (existingSettingProfile == null) { validationResult.AddError("SettingProfile.Null", "The setting profile being modified does not exist in the database."); } else { // Does the setting profile being modified belong to the requesting account? if (existingSettingProfile.AccountId != settingProfile.AccountId) { validationResult.AddError("SettingProfile.Permission", "The setting profile being modified does not belong to the requesting account."); } } // Null checks. if (settingProfile.TwitterHandle == null) { validationResult.AddError("TwitterHandle.Null", "TwitterHandle cannot be null."); } // Regex checks. if (settingProfile.TwitterHandle != null) { if (!Regex.Match(settingProfile.TwitterHandle, "^@(\\w){1,15}$").Success) { validationResult.AddError("TwitterHandle.Format", "Invalid twitter handle."); } } // Range checks. if (settingProfile.BrokerPercentage < 0 || settingProfile.BrokerPercentage > 100) { validationResult.AddError("BrokerPercentage.Range", "BrokerPercentage is outside of expected ranges."); } if (settingProfile.SalesTaxPercentage < 0 || settingProfile.SalesTaxPercentage > 100) { validationResult.AddError("SalesTaxPercentage.Range", "SalesTaxPercentage is outside of expected ranges."); } if (settingProfile.ContractMarkupPercentage < 0 || settingProfile.ContractMarkupPercentage > 100) { validationResult.AddError("ContractMarkupPercentage.Range", "ContractMarkupPercentage is outside of expected ranges."); } if (settingProfile.ContractBrokerFee < 0 || settingProfile.ContractBrokerFee > double.MaxValue) { validationResult.AddError("ContractBrokerFee.Range", "ContractBrokerFee is outside of expected ranges."); } if (settingProfile.ShippingCostPerM3 < 0 || settingProfile.ShippingCostPerM3 > double.MaxValue) { validationResult.AddError("ShippingCostPerM3.Range", "ShippingCostPerM3 is outside of expected ranges."); } if (settingProfile.BuyStationId < 0 || settingProfile.BuyStationId > int.MaxValue) { validationResult.AddError("BuyStationId.Range", "BuyStationId is outside of expected ranges."); } if (settingProfile.SellStationId < 0 || settingProfile.SellStationId > int.MaxValue) { validationResult.AddError("SellStationId.Range", "SellStationId is outside of expected ranges."); } if (settingProfile.AlertThreshold < 0 || settingProfile.AlertThreshold > int.MaxValue) { validationResult.AddError("AlertThreshold.Range", "AlertThreshold is outside of expected ranges."); } return(validationResult); }
internal SettingProfile CreateSettingProfile(SettingProfile settingProfile) { settingProfile.ObjectState = ObjectState.Added; this.unitOfWork.Repository <SettingProfile>().Insert(settingProfile); return(settingProfile); }
public SettingProfile AddSettingProfile(SettingProfile settingProfile) { return SettingProfileOperations.AddSettingProfile(settingProfile); }
public IValidationResult SettingProfile(SettingProfile settingProfile) { return(AccountCheck.SettingProfile(settingProfile)); }
public SettingProfile AddSettingProfile(SettingProfile settingProfile) { return(SettingProfileOperations.AddSettingProfile(settingProfile)); }
public SettingProfile CreateSettingProfile(SettingProfile settingProfile) { return SettingProfileOperations.CreateSettingProfile(settingProfile); }
public SettingProfile CreateSettingProfile(SettingProfile settingProfile) { return(SettingProfileOperations.CreateSettingProfile(settingProfile)); }
/// <summary> /// Updates a setting profile for a particular account. /// </summary> /// <param name="settingProfile">A setting profile object to be updated.</param> /// <returns>Returns true if the update was successful or false if not.</returns> public bool UpdateSettingProfile(SettingProfile settingProfile) { return(AccountManager.UpdateSettingProfile(settingProfile)); }
/// <summary> /// Fetches and returns a Doctrine Ships ship fit. /// </summary> /// <param name="shipFitId">The id for which a ship fit object should be returned.</param> /// <param name="settingProfile">A doctrine ships account setting profile.</param> /// <param name="accountId">The currently logged-in account id for security checking.</param> /// <returns>A ship fit object.</returns> internal ShipFit GetShipFitDetail(int shipFitId, int accountId, SettingProfile settingProfile) { ShipFit shipFit = this.doctrineShipsRepository.GetShipFit(shipFitId); if (shipFit != null) { if (accountId == shipFit.AccountId) { // Refresh the market details for the ship fit. this.RefreshShipFitMarketDetails(shipFit, settingProfile); return shipFit; } } return null; }
/// <summary> /// Refresh the market prices of all components in a ship fit. /// </summary> /// <param name="shipFit">A doctrine ships ship fit.</param> /// <param name="settingProfile">A doctrine ships account setting profile.</param> internal void RefreshShipFitComponentsPrices(ShipFit shipFit, SettingProfile settingProfile) { double buyPrice; double sellPrice; IDictionary<int, double> buyPrices; IDictionary<int, double> sellPrices; // Ensure that there are ship fit components to be refreshed. if (shipFit.ShipFitComponents != null && shipFit.ShipFitComponents.Any() != false) { buyPrices = this.eveDataSource.GetStationBuyPrice(shipFit.ShipFitComponents.Select(x => x.ComponentId).ToList(), settingProfile.BuyStationId); sellPrices = this.eveDataSource.GetStationSellPrice(shipFit.ShipFitComponents.Select(x => x.ComponentId).ToList(), settingProfile.SellStationId); foreach (var item in shipFit.ShipFitComponents) { buyPrices.TryGetValue(item.ComponentId, out buyPrice); sellPrices.TryGetValue(item.ComponentId, out sellPrice); item.BuyPrice = buyPrice * settingProfile.BrokerPercentage; item.SellPrice = sellPrice; item.ObjectState = ObjectState.Modified; } } }
public IValidationResult SettingProfile(SettingProfile settingProfile) { return AccountCheck.SettingProfile(settingProfile); }