Пример #1
0
        /// <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);
        }
        /// <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;
        }