Exemple #1
0
        public async Task <ActionResult> Index(string opportunityId)
        {
            OpportunityLineItems lineitems = new OpportunityLineItems();

            try
            {
                ForceClient client = await _client.CreateForceClient();

                lineitems = await _repository.GetOpportunityLineitems(client, opportunityId);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(View("Index", lineitems));
        }
        /// <summary>
        /// Getting line items associated with provided opportunity id
        /// </summary>
        /// <param name="client">Force client instance</param>
        /// <param name="opportunityId">Opportunity Id</param>
        /// <returns></returns>
        public async Task <OpportunityLineItems> GetOpportunityLineitems(ForceClient client, string opportunityId)
        {
            OpportunityLineItems lineItems = new OpportunityLineItems();

            // Getting opportunity details
            Opportunity opportunityDetails = await GetOpportunityById(client, opportunityId);

            lineItems.OpportunityDetails = opportunityDetails;

            // Getting line items
            var lineitems = await client.QueryAsync <OpportunityLineItem>("SELECT ID, Name, UnitPrice, ListPrice, Quantity, Description, OpportunityId, PricebookEntryId From OpportunityLineItem WHERE OpportunityId='" + opportunityId + "' ORDER BY Name ASC");

            if (lineitems.Records.Any())
            {
                lineItems.AllLineItems = lineitems.Records;
            }
            return(lineItems);
        }