Beispiel #1
0
        public async ValueTask <ActionResult <LeadOutputModel> > GetLeadById(long leadId)
        {
            DataWrapper <LeadDto> dataWrapper = await _repo.GetById(leadId);

            _logger.Info($"Get info about lead with Id: {leadId}");
            return(MakeResponse(dataWrapper, _mapper.Map <LeadOutputModel>));
        }
Beispiel #2
0
        public ActionResult Index(Guid leadId)
        {
            Lead         lead;
            IList <Deal> deals;

            using (var transactionScope = new TransactionScope())
            {
                lead  = _leadRepository.GetById(leadId);
                deals = _dealRepository.GetByLeadId(leadId);
                transactionScope.Complete();
            }

            var employees = _employeeService.GetByIds(deals.Select(deal => deal.MadeByConsultantId).ToArray());

            var viewModel = new IndexDealsViewModel
            {
                LeadId   = leadId,
                LeadName = lead.Name,
                Records  = deals.Select(deal => new IndexDealsRecordViewModel
                {
                    Id = deal.Id.Value,
                    MadeByConsultant =
                        employees.Single(
                            employee =>
                            employee.Id.Value ==
                            deal.MadeByConsultantId).FullName,
                    Value = deal.Value
                }).ToList()
            };

            return(View(viewModel));
        }
Beispiel #3
0
        public void Handle(RegisterDeal message)
        {
            DomainEvents.Register <DealSignedDomainEvent>(DealSignedDomainEventHandler);
            DomainEvents.Register <LeadSignedUpEventEvent>(LeadSignedUpDomainEventHandler);
            _correlationId = message.CorrelationId;
            var lead = _leadRepository.GetById(message.LeadId);

            Deal.Register(message.DealId, lead, message.Value);
            _dealRepository.Flush();
            _bus.Return(ReturnCode.OK);
        }
Beispiel #4
0
        public async ValueTask <string> ValidateLeadInputModel(LeadInputModel leadModel)
        {
            if (leadModel.Id.HasValue)
            {
                var leadId = await _repo.GetById(leadModel.Id.Value);

                if (leadId == null)
                {
                    return("Lead was not found");
                }
            }
            if (string.IsNullOrWhiteSpace(leadModel.FirstName))
            {
                return("Enter the name");
            }
            if (string.IsNullOrWhiteSpace(leadModel.LastName))
            {
                return("Enter the last name");
            }
            if (string.IsNullOrWhiteSpace(leadModel.Password))
            {
                return("Enter a password");
            }
            if (!Regex.IsMatch(leadModel.Password, passwordPattern))
            {
                return("Password have to be between 8 and 20 characters long and contain lowercase, uppercase and number, possible characters: @#$%^&+=*.-_");
            }
            if (string.IsNullOrWhiteSpace(leadModel.Phone))
            {
                return("Enter the phone number");
            }
            if (string.IsNullOrWhiteSpace(leadModel.Address))
            {
                return("Enter the address");
            }
            if (string.IsNullOrWhiteSpace(leadModel.BirthDate))
            {
                return("Enter the date of birth");
            }
            return("");
        }
Beispiel #5
0
        public void Handle(BookVisit message)
        {
            DomainEvents.Register <VisitBookedDomainEvent>(VisitBookedDomainEventHandler);
            var lead = _leadRepository.GetById(message.LeadId);

            Visit.Book(
                message.Id,
                message.AppointmentId,
                lead,
                message.ConsultantId);

            _visitRepository.Flush();
            _bus.Return(ReturnCode.OK);
        }
Beispiel #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="leadId"></param>
        /// <returns></returns>
        public async Task <List <ContactLead> > Get(string leadId)
        {
            var companyId = _httpContextAccessor.HttpContext.Request?.Headers["CompanyId"].FirstOrDefault();
            var lead      = await _leadRepository.GetById(leadId);

            var searchResponse = await _esClient.SearchAsync <ContactLead>(s => s
                                                                           .From(0)
                                                                           .Size(5000)
                                                                           .Sort(ss => ss.Field(f => f.CreatedAt, SortOrder.Descending))
                                                                           .Query(q => q.Term(t => t.LeadId, leadId) && q.Term(t => t.IsDelete, false) && q.Term(t => t.CompanyId, companyId))
                                                                           );

            return(searchResponse?.Documents?.ToList());
        }
Beispiel #7
0
 public LeadDto GetById(Guid id)
 {
     try
     {
         using (var transactionScope = new TransactionScope())
         {
             var employeeDtos = new LeadDtoMapper().Map(_leadRepository.GetById(id));
             transactionScope.Complete();
             return(employeeDtos);
         }
     }
     finally
     {
         _sessionProvider.CloseCurrent();
     }
 }
Beispiel #8
0
        public Lead GetLead(int id)
        {
            Lead lead = null;

            try
            {
                lead = new Lead();
                lead = _leadRepository.GetById(id);
                if (lead == null)
                {
                    return(null);
                }
                return(lead);
            }
            catch
            {
                //обрабатываем ошибку, записываем в логи
                return(lead);
            }
        }
        public ActionResult Index(Guid leadId)
        {
            Lead          lead;
            IList <Visit> bookedVisits;
            IList <Visit> completedVisits;

            using (var transactionScope = new TransactionScope())
            {
                lead            = _leadRepository.GetById(leadId);
                bookedVisits    = _visitRepository.GetBookedByLeadId(leadId);
                completedVisits = _visitRepository.GetCompletedByLeadId(leadId);
                transactionScope.Complete();
            }

            var consultantIds = bookedVisits
                                .Union(completedVisits)
                                .Where(x => x.ConsultantId.HasValue)
                                .Select(x => x.ConsultantId.Value)
                                .ToArray();

            var consultants = _employeeService.GetByIds(consultantIds);

            var appointmentIds = bookedVisits
                                 .Union(completedVisits)
                                 .Select(x => x.AppointmentId.Value)
                                 .ToArray();

            var appointments = _appointmentService.GetByIds(appointmentIds);

            var viewModel = new IndexVisitsViewModel
            {
                LeadId       = leadId,
                LeadName     = lead.Name,
                BookedVisits = (from visit in bookedVisits
                                join appointment in appointments
                                on visit.AppointmentId equals appointment.Id.Value
                                join joinConsultant in consultants
                                on visit.ConsultantId equals joinConsultant.Id
                                into joinConsultants
                                from consultant in joinConsultants.DefaultIfEmpty()
                                select new IndexVisitsRecordViewModel
                {
                    Id = visit.Id.Value,
                    Start = appointment.Start,
                    End = appointment.End,
                    ConsultantName = consultant != null ? consultant.FullName : null
                }).ToList(),
                CompletedVisits = (from visit in completedVisits
                                   join appointment in appointments
                                   on visit.AppointmentId equals appointment.Id.Value
                                   join joinConsultant in consultants
                                   on visit.ConsultantId equals joinConsultant.Id
                                   into joinConsultants
                                   from consultant in joinConsultants.DefaultIfEmpty()
                                   select new IndexVisitsRecordViewModel
                {
                    Id = visit.Id.Value,
                    Start = appointment.Start,
                    End = appointment.End,
                    ConsultantName = consultant != null ? consultant.FullName : null
                }).ToList()
            };

            //var viewModel2 = new IndexVisitsViewModel
            //                    {
            //                        LeadId = leadId,
            //                        LeadName = lead.Name,
            //                        BookedVisits = bookedVisits.Select(visit => new IndexVisitsRecordViewModel
            //                                                                        {
            //                                                                            Id = visit.Id.Value,
            //                                                                            Start =
            //                                                                                appointments.Single(
            //                                                                                    x =>
            //                                                                                    x.Id ==
            //                                                                                    visit.AppointmentId).Start,
            //                                                                            End =
            //                                                                                appointments.Single(
            //                                                                                    x =>
            //                                                                                    x.Id ==
            //                                                                                    visit.AppointmentId).End,
            //                                                                            ConsultantName =
            //                                                                                visit.ConsultantId.HasValue
            //                                                                                    ? consultants.Single(
            //                                                                                        x =>
            //                                                                                        x.Id ==
            //                                                                                        visit.
            //                                                                                            ConsultantId)
            //                                                                                          .
            //                                                                                          FullName
            //                                                                                    : null
            //                                                                        }).ToList(),
            //                        CompletedVisits = completedVisits.Select(visit => new IndexVisitsRecordViewModel
            //                                                                              {
            //                                                                                  Id = visit.Id.Value,
            //                                                                                  Start =
            //                                                                                      appointments.Single(
            //                                                                                          x =>
            //                                                                                          x.Id ==
            //                                                                                          visit.
            //                                                                                              AppointmentId).Start,
            //                                                                                  End =
            //                                                                                      appointments.Single(
            //                                                                                          x =>
            //                                                                                          x.Id ==
            //                                                                                          visit.
            //                                                                                              AppointmentId).End,
            //                                                                                  ConsultantName =
            //                                                                                      visit.ConsultantId.
            //                                                                                          HasValue
            //                                                                                          ? consultants.
            //                                                                                                Single(
            //                                                                                                    x =>
            //                                                                                                    x.Id ==
            //                                                                                                    visit.
            //                                                                                                        ConsultantId)
            //                                                                                                .FullName
            //                                                                                          : null
            //                                                                              }).ToList(),
            //                    };

            return(View(viewModel));
        }
Beispiel #10
0
        public async Task <IActionResult> GetById([FromQuery] string id)
        {
            var data = await _leadRepository.GetById(id);

            return(Ok(data));
        }