Exemple #1
0
        public async Task <ActionResult <Contact_OpportunityDTO> > GetOpportunity([FromBody] Contact_OpportunityDTO Contact_OpportunityDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            Opportunity Opportunity = await OpportunityService.Get(Contact_OpportunityDTO.Id);

            return(new Contact_OpportunityDTO(Opportunity));
        }
        public async Task <ActionResult <List <Opportunity_ContactDTO> > > SingleListEmail([FromBody] Opportunity_OpportunityEmailFilterDTO Opportunity_OpportunityEmailFilterDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            if (Opportunity_OpportunityEmailFilterDTO.OpportunityId == null || Opportunity_OpportunityEmailFilterDTO.OpportunityId.Equal.HasValue == false)
            {
                return(new List <Opportunity_ContactDTO>());
            }
            Opportunity Opportunity = await OpportunityService.Get(Opportunity_OpportunityEmailFilterDTO.OpportunityId.Equal.Value);

            if (Opportunity == null)
            {
                return(new List <Opportunity_ContactDTO>());
            }

            List <string> Emails = new List <string>();

            Emails.Add(Opportunity.Company?.Email);
            Emails.AddRange(Opportunity.OpportunityContactMappings?.Select(x => x.Contact?.Email).ToList());
            Emails = Emails.Where(x => x != null).ToList();
            if (Opportunity_OpportunityEmailFilterDTO.Email.HasValue && !string.IsNullOrWhiteSpace(Opportunity_OpportunityEmailFilterDTO.Email.StartWith))
            {
                Emails = Emails.Where(x => x.StartsWith(Opportunity_OpportunityEmailFilterDTO.Email.StartWith)).ToList();
            }
            List <Opportunity_ContactDTO> Results = Emails.Select(x => new Opportunity_ContactDTO {
                Email = x
            }).ToList();

            return(Results);
        }