public async Task <APIResponse> Handle(UpdateLeadPortionCommand updateCommand, CancellationToken cancellationToken)
        {
            try
            {
                var leadData = await repository.LeadRepository.GetLeadById(updateCommand.Id);

                if (leadData == null)
                {
                    return(new APIResponse(HttpStatusCode.NotFound));
                }

                leadData.LeadQuality  = updateCommand.Request.LeadQuality;
                leadData.LeadStatusId = updateCommand.Request.LeadStatus;
                leadData.UpdatedAt    = DateTime.UtcNow;
                leadData.UpdatedBy    = updateCommand.Request.UpdatedBy;

                var leadStatus = new Leadstatus
                {
                    LeadId       = leadData.Id,
                    LeadStatusId = updateCommand.Request.LeadStatus,
                    Date         = DateTime.Now,
                    CreatedAt    = DateTime.Now,
                    CreatedBy    = updateCommand.Request.UpdatedBy,
                };

                leadData.Leadstatus.Add(leadStatus);

                repository.LeadRepository.UpdateLead(leadData);

                await repository.SaveAsync();

                return(new APIResponse(HttpStatusCode.NoContent));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception in method 'UpdateLeadPortionHandler()'");
                var exMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                return(new APIResponse(exMessage, HttpStatusCode.InternalServerError));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles a request
        /// </summary>
        /// <param name="request">The request</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns>
        /// Response from the request
        /// </returns>
        public async Task <APIResponse> Handle(CreateLeadCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var apiStatus = HttpStatusCode.Created;

                var leadCollectionData = await repository.LeadDataRepository.GetLeadWithDetails(request.Request.CustomerPhone1);

                if (leadCollectionData == null)
                {
                    leadCollectionData = mapper.Map <Leaddatacollection>(request.Request);
                    repository.LeadDataRepository.CreateLead(leadCollectionData);
                }
                else
                {
                    var leadRequest       = request.Request.Leads.First();
                    var leadStatusRequest = leadRequest.LeadStatus.First();
                    var isLeadExist       = leadCollectionData.Leads.Any(x => x.EventType == leadRequest.EventType &&
                                                                         x.Category == leadRequest.Category);
                    if (!isLeadExist)
                    {
                        var leadData = new Leads
                        {
                            DataCollectionId = leadCollectionData.Id,
                            Budget           = leadRequest.Budget,
                            Description      = leadRequest.Description,
                            EventDate        = leadRequest.EventDate,
                            EventLocation    = leadRequest.EventLocation,
                            LeadId           = leadRequest.LeadId,
                            LeadMode         = leadRequest.LeadMode,
                            LeadQuality      = leadRequest.LeadQuality,
                            LeadType         = leadRequest.LeadType,
                            Owner            = leadRequest.Owner,
                            OwnerName        = leadRequest.OwnerName,
                            Revenue          = leadRequest.Revenue,
                            EventType        = leadRequest.EventType,
                            Category         = leadRequest.Category,
                            LeadStatusId     = leadRequest.LeadStatusId,
                            Cplvalue         = leadRequest.Cplvalue,
                            CommisionValue   = leadRequest.CommisionValue,
                            WalletStatus     = leadRequest.WalletStatus,
                            CreatedAt        = DateTime.UtcNow,
                            CreatedBy        = request.Request.CreatedBy
                        };

                        var leadStatus = new Leadstatus
                        {
                            LeadId       = leadData.Id,
                            LeadStatusId = leadStatusRequest.LeadStatusId,
                            Date         = DateTime.UtcNow,
                            CreatedAt    = DateTime.UtcNow,
                            CreatedBy    = request.Request.CreatedBy
                        };

                        leadData.Leadstatus.Add(leadStatus);
                        leadCollectionData.Leads.Add(leadData);
                        leadCollectionData.UpdatedAt = DateTime.UtcNow;
                        leadCollectionData.UpdatedBy = request.Request.CreatedBy;
                    }
                    else
                    {
                        apiStatus = HttpStatusCode.Ambiguous;
                    }

                    repository.LeadDataRepository.Update(leadCollectionData);
                }
                await repository.SaveAsync();

                var id = leadCollectionData.Leads.Last().Id;
                return(new APIResponse(new LeadIdDetails {
                    LeadId = id
                }, apiStatus));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception in method 'CreateLeadHandler()'");
                var exMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                return(new APIResponse(exMessage, HttpStatusCode.InternalServerError));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles the specified create command.
        /// </summary>
        /// <param name="createCommand">The create command.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <APIResponse> Handle(CreateLeadAssignCommand createCommand, CancellationToken cancellationToken)
        {
            try
            {
                var leadData = await repository.LeadRepository.GetLeadById(createCommand.LeadId);

                if (leadData == null)
                {
                    return(new APIResponse(HttpStatusCode.NotFound));
                }

                var leadAssignRequest = createCommand.Request;
                var leadStatusRequest = leadAssignRequest.LeadStatusRequest.First();

                var leadAssign = new Leadassign()
                {
                    LeadId         = leadData.Id,
                    LeadSentDate   = leadAssignRequest.LeadSentDate,
                    VendorId       = leadAssignRequest.VendorId,
                    VendorName     = leadAssignRequest.VendorName,
                    Category       = leadAssignRequest.Category,
                    ProposedBudget = leadAssignRequest.ProposedBudget,
                    Packs          = leadAssignRequest.Packs,
                    Remarks        = leadAssignRequest.Remarks,
                    CreatedAt      = leadAssignRequest.CreatedAt,
                    CreatedBy      = leadAssignRequest.CreatedBy,
                };

                var leadStatus = new Leadstatus
                {
                    LeadId       = leadData.Id,
                    LeadStatusId = leadStatusRequest.LeadStatusId,
                    Date         = DateTime.Now,
                    CreatedAt    = DateTime.Now,
                    CreatedBy    = leadAssignRequest.CreatedBy
                };

                leadData.Leadassign.Add(leadAssign);
                leadData.Leadstatus.Add(leadStatus);

                leadData.LeadStatusId = leadStatusRequest.LeadStatusId;
                leadData.UpdatedAt    = DateTime.UtcNow;
                leadData.UpdatedBy    = leadAssignRequest.CreatedBy;

                if (leadData.Leadassign != null && leadData.Leadassign.Count > 0)
                {
                    foreach (var item in leadData.Leadassign)
                    {
                        repository.LeadAssignRepository.CreateLeadAssign(item);
                    }
                }

                await repository.SaveAsync();

                return(new APIResponse(createCommand.Request, HttpStatusCode.Created));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception in method 'CreateAssignLeadHandler'");
                var exMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                return(new APIResponse(exMessage, HttpStatusCode.InternalServerError));
            }
        }