Exemplo n.º 1
0
 public IActionResult Add(LeadViewModel model)
 {
     if (ModelState.IsValid)
     {
         _repository.AddLead(Mapper.Map <Lead>(model));
         //_repository
         ViewBag.Message = "Saved Record: " + model.Name;
         ModelState.Clear();
     }
     else
     {
         ViewBag.Message = "Model didn't validate";
     }
     return(View());
 }
Exemplo n.º 2
0
        public async Task <RegisterLeadOutput> RegisterLead(RegisterLeadInput request)
        {
            var status = await _leadRepository.AddStatus(request.StatusDescription);

            //var allStatusLead = await _leadRepository.ListAllStatusLead();
            //if (!allStatusLead.Any())
            //throw new DefaultException((int)HttpStatusCode.InternalServerError, "Nenhum status lead encontrado.");

            LeadEntity input = new LeadEntity()
            {
                CustomerName  = request.CustomerName,
                CustomerEmail = request.CustomerEmail,
                CustomerPhone = request.CustomerPhone,
                StatusId      = status.Id
            };

            var lead = await _leadRepository.AddLead(input);

            foreach (var item in request.Opportunities)
            {
                var opportunity = new OpportunityEntity()
                {
                    LeadId      = lead.Id,
                    Description = item
                };
                await _leadRepository.AddOpportunities(opportunity);
            }

            var opportunitiesOfLead = await _leadRepository.ListOpportunitiesByLeadId(lead.Id);

            var leadDto = lead.CreateDto();

            leadDto.Opportunities = new List <OpportunityDto>();
            opportunitiesOfLead.ToList().ForEach(item => leadDto.Opportunities.Add(item.CreateDto()));

            return(new RegisterLeadOutput()
            {
                Method = "RegisterLead",
                Result = lead != default ? "SUCCESS" : "ERROR",
                Payload = leadDto
            });