コード例 #1
0
        /// <summary>
        /// Insert Opportunity.
        /// </summary>
        /// <param name="request"></param>
        /// <returns>HttpResponseMessage</returns>
        public InsertOpportunityResponse InsertOpportunity(InsertOpportunityRequest request)
        {
            Logger.Current.Verbose("Request for inserting an opportunity");
            if (request.opportunityViewModel.Image != null)
            {
                SaveImageResponse imageResponse = imageService.SaveImage(new SaveImageRequest()
                {
                    ImageCategory = ImageCategory.OpportunityProfile,
                    ViewModel     = request.opportunityViewModel.Image,
                    AccountId     = request.AccountId
                });
                request.opportunityViewModel.Image = imageResponse.ImageViewModel;
            }
            Opportunity opportunity = Mapper.Map <OpportunityViewModel, Opportunity>(request.opportunityViewModel);

            opportunity.IsDeleted = false;
            bool isOpportunityUnique = opportunityRepository.IsOpportunityUnique(opportunity);

            if (!isOpportunityUnique)
            {
                var message = "[|Opportunity with name|] \"" + opportunity.OpportunityName + "\" [|already exists.|]";
                throw new UnsupportedOperationException(message);
            }
            isOpportunityValid(opportunity);
            OpportunityTableType opportunityTableType = Mapper.Map <OpportunityViewModel, OpportunityTableType>(request.opportunityViewModel);
            OpportunityTableType newOpportunityType   = opportunityRepository.InsertOpportunity(opportunityTableType);
            // opportunityRepository.Insert(opportunity);
            Opportunity newOpportunity = opportunityRepository.FindBy(newOpportunityType.OpportunityID);

            if (indexingService.Index <Opportunity>(newOpportunity) > 0)
            {
                Logger.Current.Verbose("Indexed the opportunity successfully");
            }


            return(new InsertOpportunityResponse());
        }