static ConsoleKeyInfo ShowInvoicesByAgent(SalesAgent salesAgent) { var InvoiceList = new List <InvoiceBySalesRep>(); var invoiceQuery = new InvoiceQuery(); var agent = salesAgent.ToString(); var invoices = invoiceQuery.GetInvoiceBySalesAgent(salesAgent.AgentId); var invoicesByAgentView = new View(); invoicesByAgentView.AddMenuText(""); invoicesByAgentView.AddMenuText("Agent Results:"); foreach (var invoice in invoices) { InvoiceList.Add(invoice); invoicesByAgentView.AddMenuText($"{invoice.AgentName} {invoice.InvoiceId} "); } ; invoicesByAgentView.AddMenuText("Press 0 to go BACK."); Console.Write(invoicesByAgentView.GetFullMenu()); ConsoleKeyInfo userOption = Console.ReadKey(); return(userOption); }
public List <SalesAgent> GetInvoiceWithSalesAgentName() { using (var connection = new SqlConnection(_connectionString)) { var cmd = connection.CreateCommand(); cmd.CommandText = @"select e.FirstName + ' ' + e.LastName Name, i.InvoiceId from Employee e join customer c on c.SupportRepId = e.EmployeeId join invoice i on i.CustomerId = c.CustomerId"; connection.Open(); var reader = cmd.ExecuteReader(); var employees = new List <SalesAgent>(); while (reader.Read()) { var employee = new SalesAgent { Name = reader["Name"].ToString(), InvoiceId = int.Parse(reader["InvoiceId"].ToString()) }; employees.Add(employee); } return(employees); } }
public async Task <IActionResult> Edit(int id, [Bind("Id,AgentName,ContactNumber")] SalesAgent salesAgent) { if (id != salesAgent.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(salesAgent); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SalesAgentExists(salesAgent.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(salesAgent)); }
/// <summary> /// Forces a contract refresh for a single sales agent. This operation is only permitted once every 30 minutes. /// </summary> /// <param name="accountId">The account Id of the requestor. The account Id should own the sales agent being refreshed.</param> /// <param name="salesAgentId">The id of the sales agent for which a contract refresh is to be forced.</param> /// <returns>Returns true if the force was successful or false if not.</returns> internal bool ForceContractRefresh(int accountId, int salesAgentId) { SalesAgent salesAgent = this.doctrineShipsRepository.GetSalesAgent(salesAgentId); if (salesAgent != null) { // If the account Id matches the account Id of the sales agent being refreshed, continue. if (accountId == salesAgent.AccountId) { // Has 30 minutes elapsed since the last forced refresh? if (Time.HasElapsed(salesAgent.LastForce, TimeSpan.FromMinutes(30))) { // Reset the ship fit list. ShipFitList = null; // Refresh the contracts for the passed sales agent. this.RefreshContracts(salesAgent, batch: true); // Update the LastForce timestamp and save all changes. salesAgent.LastForce = DateTime.UtcNow; this.doctrineShipsRepository.UpdateSalesAgent(salesAgent); this.doctrineShipsRepository.Save(); // Log the operation and return true. this.logger.LogMessage("Contract Refresh Forced For Sales Agent '" + salesAgent.Name + "'.", 2, "Message", MethodBase.GetCurrentMethod().Name); return(true); } } } return(false); }
public List <SalesAgent> GetAllSalesReps() { using (var connection = new SqlConnection(_connectionString)) { var cmd = connection.CreateCommand(); cmd.CommandText = @"select e.FirstName + ' ' + e.LastName AgentName, e.EmployeeId AgentId from Employee e where e.Title like 'Sales % Agent'"; connection.Open(); var reader = cmd.ExecuteReader(); var salesAgents = new List <SalesAgent>(); while (reader.Read()) { var agent = new SalesAgent { AgentName = reader["AgentName"].ToString(), AgentId = reader["AgentId"].ToString() }; salesAgents.Add(agent); } return(salesAgents); } }
public TransactionViewModel( List <Transaction> transactions, SalesAgent salesAgent) { Transactions = transactions; SalesAgent = salesAgent; }
public ActionResult DeleteConfirmed(int id) { SalesAgent salesAgent = _salesAgentRepository.Get().Where(x => x.SalesAgentId == id).Fetch().FirstOrDefault(); _salesAgentRepository.Delete(salesAgent); return(RedirectToAction("Index")); }
// Provide a query that shows the invoices associated with each sales agent. public List <SalesAgent> GetAgent() { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); var cmd = connection.CreateCommand(); cmd.CommandText = @"select i.InvoiceId, e.FirstName + ' ' + e.LastName as SalesAgent from Invoice i, Employee e where i.InvoiceId = e.EmployeeId ORDER BY SalesAgent;"; var reader = cmd.ExecuteReader(); var salesAgentEmployees = new List <SalesAgent>(); while (reader.Read()) { var employee = new SalesAgent { Name = reader["SalesAgent"].ToString(), InvoiceId = int.Parse(reader["InvoiceId"].ToString()) }; salesAgentEmployees.Add(employee); } return(salesAgentEmployees); } }
/// <summary> /// Updates the state of a sales agent. /// </summary> /// <param name="accountId">The account Id of the requestor. The account Id should own the sales agent being changed.</param> /// <param name="salesAgentId">The id of the sales agent to be changed.</param> /// <param name="isActive">The required boolean state.</param> /// <returns>Returns true if the change was successful or false if not.</returns> internal bool UpdateSalesAgentState(int accountId, int salesAgentId, bool isActive) { SalesAgent salesAgent = this.doctrineShipsRepository.GetSalesAgent(salesAgentId); if (salesAgent != null) { // If the account Id matches the account Id of the sales agent being changed, continue. if (accountId == salesAgent.AccountId) { // Change the state of the sales agent and log the event. salesAgent.IsActive = isActive; this.doctrineShipsRepository.UpdateSalesAgent(salesAgent); this.doctrineShipsRepository.Save(); if (isActive == true) { logger.LogMessage("Sales Agent '" + salesAgent.Name + "' Successfully Enabled For Account Id: " + salesAgent.AccountId, 2, "Message", MethodBase.GetCurrentMethod().Name); } else { logger.LogMessage("Sales Agent '" + salesAgent.Name + "' Successfully Disabled For Account Id: " + salesAgent.AccountId, 2, "Message", MethodBase.GetCurrentMethod().Name); } return(true); } } return(false); }
/// <summary> /// Add a new contract to the database from an EveDataContract. /// </summary> /// <param name="eveDataContract">An EveDataContract object.</param> /// <param name="salesAgent">A SalesAgent object representing the contract owner.</param> /// <param name="batch">Optional parameter with a default of false. Is this addition part of a batch? If so, do not commit.</param> internal Contract AddContract(IEveDataContract eveDataContract, SalesAgent salesAgent, bool batch = false) { Contract newContract = new Contract(); newContract.ContractId = eveDataContract.ContractId; newContract.AssigneeId = eveDataContract.AssigneeId; newContract.StartStationId = eveDataContract.StartStationId; newContract.Status = Conversion.StringToEnum <ContractStatus>(eveDataContract.Status.ToString(), ContractStatus.Deleted); newContract.Type = Conversion.StringToEnum <ContractType>(eveDataContract.Type.ToString(), ContractType.ItemExchange); newContract.Availability = Conversion.StringToEnum <ContractAvailability>(eveDataContract.Availability.ToString(), ContractAvailability.Private); newContract.Price = eveDataContract.Price; newContract.Volume = eveDataContract.Volume; newContract.DateIssued = eveDataContract.DateIssued; newContract.DateExpired = eveDataContract.DateExpired; newContract.IssuerCorpId = eveDataContract.IssuerCorpId; newContract.IssuerId = eveDataContract.IssuerId; newContract.ForCorp = eveDataContract.ForCorp; newContract.IsValid = false; // Populate the contract title/description field. if (eveDataContract.Title == string.Empty) { newContract.Title = "None"; } else { newContract.Title = eveDataContract.Title; } // Populate the remaining contract details. These calls are cached. newContract.SolarSystemId = this.eveDataSource.GetStationSolarSystemId(newContract.StartStationId); newContract.SolarSystemName = this.eveDataSource.GetSolarSystemName(newContract.SolarSystemId); newContract.StartStationName = this.eveDataSource.GetStationName(newContract.StartStationId); // Attempt to match the contract contents to a ship fit id. newContract.ShipFitId = this.ContractShipFitMatch(newContract.ContractId, salesAgent); // If the ship fit was matched, set the contract as valid. if (newContract.ShipFitId != 0) { newContract.IsValid = true; } // Validate the new contract. if (this.doctrineShipsValidation.Contract(newContract).IsValid == true) { // Add the populated contract object to the database. this.doctrineShipsRepository.CreateContract(newContract); // If this addition is not part of a batch, commit changes to the database. if (batch == false) { this.doctrineShipsRepository.Save(); } } return(newContract); }
static void Main(string[] args) { var run = true; while (run) { ConsoleKeyInfo userInput = MainMenu(); switch (userInput.KeyChar) { case '0': run = false; break; case '1': ConsoleKeyInfo userOption = SelectInvoiceQueryType(); switch (userOption.KeyChar) { case '1': //Provide a query that shows the invoices associated with each sales agent. The resultant table should include the Sales Agent's full name. _selectedAgent = SelectSalesAgent(); var invoicesBySelectedAgent = ShowInvoicesByAgent(_selectedAgent); break; case '2': //Provide a query that shows the Invoice Total, Customer name, Country and Sale Agent name for all invoices. var allInvoices = ShowAllInvoices(); break; case '3': //Looking at the InvoiceLine table, provide a query that COUNTs the number of line items for an Invoice with a parameterized Id from user input (use ExecuteScalar) _selectedInvoiceId = SelectInvoiceId(); var invId = int.Parse(_selectedInvoiceId); var countLineItems = CountLineItems(invId); break; default: break; } break; case '2': //INSERT a new invoice with parameters for customerid and billing address _customerId = SelectCustomerId(); var custId = int.Parse(_customerId); _billingAddress = GrabBillingAddress(); var createInvoice = CreateNewInvoice(custId, _billingAddress); break; case '3': //UPDATE an Employee's name with a parameter for Employee Id and new name _selectedEmployeeId = SelectEmployeeId(); var empId = int.Parse(_selectedEmployeeId); _updatedEmployeeFirstName = UpdatedFirstName(empId); _updatedEmployeeLastName = UpdatedLastName(empId); var updateEmployeeName = UpdateEmployeeName(empId, _updatedEmployeeFirstName, _updatedEmployeeLastName); break; default: break; } } }
/// <summary> /// Refresh the contracts of a single sales agent from EveData. /// </summary> /// <param name="salesAgents">A sales agent object.</param> /// <param name="batch">Optional parameter with a default of false. Is this refresh part of a batch? If so, do not commit.</param> internal void RefreshContracts(SalesAgent salesAgent, bool batch = false) { // Fetch the sales agent's contracts from EveData. IEnumerable <IEveDataContract> eveDataContracts = this.eveDataSource.GetContracts(salesAgent.ApiId, salesAgent.ApiKey, salesAgent.SalesAgentId, salesAgent.IsCorp); if (eveDataContracts != null && eveDataContracts.Any() != false) { // Fetch a hashset of the current contract ids in the database. HashSet <long> existingContractIds = this.doctrineShipsRepository.GetSalesAgentContractIds(salesAgent.SalesAgentId, salesAgent.IsCorp); foreach (var eveDataContract in eveDataContracts) { // If the sales agent is a character but the current contract is on behalf of a corporation, skip it. // (The contract should be handled and listed under a corporation agent instead). if (salesAgent.IsCorp == false && eveDataContract.ForCorp == true) { continue; } // If the contract is not of type 'ItemExchange' then skip it. if (eveDataContract.Type != EveDataContractType.ItemExchange) { continue; } // Does the contract already exist in the database? if (existingContractIds.Contains(eveDataContract.ContractId)) { // If the status of the Eve contract is no longer 'Outstanding', delete it from the database. if (eveDataContract.Status != EveDataContractStatus.Outstanding) { this.doctrineShipsRepository.DeleteContract(eveDataContract.ContractId); } } else { // Only attempt to add a contract if it is currently of status 'Outstanding'. if (eveDataContract.Status == EveDataContractStatus.Outstanding) { this.AddContract(eveDataContract, salesAgent, batch: true); } } } // Set the agent's last refresh time. salesAgent.LastContractRefresh = DateTime.UtcNow; // Update the agent's timestamp in the database. this.doctrineShipsRepository.UpdateSalesAgent(salesAgent); // If this addition is not part of a batch, commit changes to the database. if (batch == false) { this.doctrineShipsRepository.Save(); } } }
public ActionResult Edit([Bind(Include = "SalesAgentId,Name,Surname,Rank,PhoneNumber,HireDate,SaleValue,Sales")] SalesAgent salesAgent) { if (ModelState.IsValid) { _salesAgentRepository.Update(salesAgent); return(RedirectToAction("Index")); } return(View(salesAgent)); }
public TransactionViewModel( List <Transaction> transactions, decimal monthlyTarget, SalesAgent salesAgent) { Transactions = transactions; MonthlyTarget = monthlyTarget; SalesAgent = salesAgent; }
public async Task <IActionResult> Create([Bind("Id,AgentName,ContactNumber")] SalesAgent salesAgent) { if (ModelState.IsValid) { _context.Add(salesAgent); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(salesAgent)); }
// GET: SalesAgents/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SalesAgent salesAgent = _salesAgentRepository.Get().Where(x => x.SalesAgentId == id).Fetch().FirstOrDefault(); if (salesAgent == null) { return(HttpNotFound()); } return(View(salesAgent)); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } SalesAgent = await _context.SalesAgent.FirstOrDefaultAsync(m => m.Id == id); if (SalesAgent == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } SalesAgent = await _context.SalesAgent.FindAsync(id); if (SalesAgent != null) { _context.SalesAgent.Remove(SalesAgent); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
internal IValidationResult SalesAgent(SalesAgent salesAgent) { IValidationResult validationResult = new ValidationResult(); // Is the salesAgent id valid? if (salesAgent.SalesAgentId <= 0 || salesAgent.SalesAgentId > int.MaxValue) { validationResult.AddError("SalesAgentId.Range", "SalesAgentId can not be less than or equal to 0. Also, the upper limit cannot exceed the max value of the int data type."); } // Does the salesAgent already exist in the database? if (this.doctrineShipsRepository.GetSalesAgent(salesAgent.SalesAgentId) != null) { validationResult.AddError("SalesAgentId.Exists", "SalesAgentId already exists in the database."); } return(validationResult); }
/// <summary> /// <para>Deletes a sales agent from an accountId and a salesAgentId.</para> /// </summary> /// <param name="accountId">The account Id of the requestor. The account Id should own the sales agent being deleted.</param> /// <param name="salesAgent">The Id of the sales agent to be deleted.</param> /// <returns>Returns true if the deletion was successful or false if not.</returns> internal bool DeleteSalesAgent(int accountId, int salesAgentId) { SalesAgent salesAgent = this.doctrineShipsRepository.GetSalesAgent(salesAgentId); if (salesAgent != null) { // If the account Id matches the account Id of the sales agent being deleted, continue. if (accountId == salesAgent.AccountId) { // Delete the sales agent and log the event. this.doctrineShipsRepository.DeleteSalesAgent(salesAgent.SalesAgentId); this.doctrineShipsRepository.Save(); logger.LogMessage("Sales Agent '" + salesAgent.Name + "' Successfully Deleted For Account Id: " + salesAgent.AccountId, 1, "Message", MethodBase.GetCurrentMethod().Name); return(true); } } return(false); }
public ActionResult Create(SalesAgent salesAgent) { var validation = new SalesAgentValidation(); var result = validation.Validate(salesAgent); if (result.IsValid) { _salesAgentRepository.Create(salesAgent); return(RedirectToAction("Index")); } ModelState.Clear(); foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.ErrorMessage); } return(View(salesAgent)); }
/// <summary> /// Attempts to match a contract's contents to a ship fit. /// </summary> /// <param name="contractId">The id of the contract to be matched.</param> /// <param name="salesAgent">A sales agent object representing the contract owner.</param> /// <returns>An integer ship fit id or 0 if no match was made.</returns> internal int ContractShipFitMatch(long contractId, SalesAgent salesAgent) { int shipFitId = 0; // Fetch the list of items included in the contract. IEnumerable <IEveDataContractItem> contractItems = this.eveDataSource.GetContractItems(salesAgent.ApiId, salesAgent.ApiKey, contractId, salesAgent.SalesAgentId, salesAgent.IsCorp); if (contractItems != null && contractItems.Any() == true) { string concatComponents = string.Empty; IEnumerable <ShipFitComponent> compressedContractItems = new List <ShipFitComponent>(); // Compress the contract items components list, removing duplicates but adding the quantities. compressedContractItems = contractItems .OrderBy(o => o.TypeId) .GroupBy(u => u.TypeId) .Select(x => new ShipFitComponent() { ComponentId = x.Key, Quantity = x.Sum(p => p.Quantity) }); // Concatenate all components and their quantities into a single string. foreach (var item in compressedContractItems) { concatComponents += item.ComponentId + item.Quantity; } // Generate a hash for the fitting and salt it with the sales agent's account id. This permits identical fits across accounts. string fittingHash = Security.GenerateHash(concatComponents, salesAgent.AccountId.ToString()); // Attempt to find a ship fit with the same components list as the contract. if (!ShipFitList.TryGetValue(fittingHash, out shipFitId)) { shipFitId = 0; } } return(shipFitId); }
public static List <SalesAgent> GetAgentsInformation(int numberOfSaleAgents) { var agents = new List <SalesAgent>(); for (int i = 0; i < numberOfSaleAgents; i++) { Console.WriteLine($"\nSäljare nr. {i + 1}"); var salesAgent = new SalesAgent(); Console.Write("Namn: "); salesAgent.Name = Console.ReadLine(); Console.Write("Personnummer: "); salesAgent.IdentityNumber = Console.ReadLine(); Console.Write("Distrikt: "); salesAgent.District = Console.ReadLine(); Console.Write("Antal sålda artiklar: "); salesAgent.NumberOfSales = GetNumberOfSales(); agents.Add(salesAgent); } return(agents); }
public void UpdateSalesAgent(SalesAgent salesAgent) { SalesAgentOperations.UpdateSalesAgent(salesAgent); }
internal void UpdateSalesAgent(SalesAgent salesAgent) { salesAgent.ObjectState = ObjectState.Modified; this.unitOfWork.Repository <SalesAgent>().Update(salesAgent); }
internal SalesAgent AddSalesAgent(SalesAgent salesAgent) { this.unitOfWork.Repository <SalesAgent>().Insert(salesAgent); return(salesAgent); }
internal SalesAgent CreateSalesAgent(SalesAgent salesAgent) { salesAgent.ObjectState = ObjectState.Added; this.unitOfWork.Repository <SalesAgent>().Insert(salesAgent); return(salesAgent); }
public SalesAgent AddSalesAgent(SalesAgent salesAgent) { return(SalesAgentOperations.AddSalesAgent(salesAgent)); }
public IValidationResult SalesAgent(SalesAgent salesAgent) { return(SalesAgentCheck.SalesAgent(salesAgent)); }
public SalesAgent CreateSalesAgent(SalesAgent salesAgent) { return(SalesAgentOperations.CreateSalesAgent(salesAgent)); }