Beispiel #1
0
        public async Task <bool> UserPasswordRecover([FromBody] LoginRequest request)
        {
            //LoginResponse response = new LoginResponse();
            bool userExist = false;

            try
            {
                if (!string.IsNullOrEmpty(request.UserName))
                {
                    var result = _UserRepository.GetLoginDetails(request.UserName);
                    if (result.Count() > 0)
                    {
                        var    user     = result.ToList().FirstOrDefault();
                        string password = Guid.NewGuid().ToString().Replace("-", "");

                        request.ContactId = user.Contact_Id;
                        request.CompanyId = user.Company_Id;
                        request.Password  = password;
                        UserDetailsResponse res = _UserRepository.ResetUserPassword(request);
                        if (res != null && res.Status.ToLower() == "success")
                        {
                            #region Send Mail:-UserPasswordRecover
                            var objEmailGetReq = new EmailGetReq()
                            {
                                Remarks          = password,
                                UserEmail        = request.UserName,
                                DocumentType     = DocType.PWDRECOVER,
                                PlacerUserId     = res.VoyagerUser_Id,
                                SystemCompany_Id = res.SystemCompany_Id
                            };
                            var responseStatusMail = await _emailRepository.GenerateEmail(objEmailGetReq);

                            if (responseStatusMail == null || responseStatusMail.ResponseStatus == null || string.IsNullOrEmpty(responseStatusMail.ResponseStatus.Status))
                            {
                                responseStatusMail.ResponseStatus              = new ResponseStatus();
                                responseStatusMail.ResponseStatus.Status       = "Error";
                                responseStatusMail.ResponseStatus.ErrorMessage = "Mail not sent.";
                            }
                            else if (responseStatusMail.ResponseStatus.Status.ToLower() == "success")
                            {
                                userExist = true;
                            }
                            #endregion
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //return response;
            }
            return(userExist);
        }
Beispiel #2
0
        public async Task <EmailGetRes> GenerateAndSendEmail([FromBody] EmailGetReq request)
        {
            var response = new EmailGetRes();

            try
            {
                response = await _emailRepository.GenerateEmail(request);
            }
            catch (Exception ex)
            {
                response.ResponseStatus.Status       = "Failure";
                response.ResponseStatus.ErrorMessage = "An Error Occurs :- " + ex.Message;
            }
            return(response);
        }
        public async Task <string> SetQuoteDetails(QuoteSetReq request)
        {
            try
            {
                if (!string.IsNullOrEmpty(request.QRFID))
                {
                    if (!string.IsNullOrEmpty(request.EnquiryPipeline))
                    {
                        bool flag = false;
                        if (request.EnquiryPipeline.ToLower() == "costing pipeline")
                        {
                            if (request.IsApproveQuote)
                            {
                                await _MongoContext.mQuote.FindOneAndUpdateAsync(
                                    Builders <mQuote> .Filter.Eq("QRFID", request.QRFID),
                                    Builders <mQuote> .Update.
                                    Set("CurrentPipeline", "Costing Approval Pipeline").
                                    Set("CurrentPipelineStep", "Costing").
                                    Set("Remarks", request.Remarks).
                                    Set("CurrentPipelineSubStep", "Itinerary").
                                    Set("QuoteResult", "Success").
                                    Set("Status", "NewCostingApprovalPipeline").
                                    Set("EditUser", request.PlacerEmail).
                                    Set("EditDate", DateTime.Now)
                                    );

                                await _MongoContext.mQRFPrice.UpdateManyAsync(
                                    Builders <mQRFPrice> .Filter.Eq("QRFID", request.QRFID),
                                    Builders <mQRFPrice> .Update.
                                    Set("ProductAccountant", request.CostingOfficer).
                                    Set("EditUser", request.PlacerEmail).
                                    Set("EditDate", DateTime.Now)
                                    );

                                #region Add Followup
                                request.PlacerEmail    = request.PlacerEmail.ToLower().Trim();
                                request.CostingOfficer = request.CostingOfficer.Trim().ToLower();
                                var CompanyList      = _MongoContext.mCompanies.AsQueryable();
                                var FromUserContacts = CompanyList.Where(x => x.ContactDetails != null && x.ContactDetails.Count > 0 && x.ContactDetails.Any(a => a.MAIL.ToLower() == request.PlacerEmail)).FirstOrDefault()?.ContactDetails;
                                var FromUser         = FromUserContacts?.Where(a => a.MAIL.ToLower() == request.PlacerEmail).FirstOrDefault();
                                var ToUserContacts   = CompanyList.Where(x => x.ContactDetails != null && x.ContactDetails.Count > 0 && x.ContactDetails.Any(a => a.MAIL.ToLower() == request.CostingOfficer)).FirstOrDefault()?.ContactDetails;
                                var ToUser           = ToUserContacts?.Where(a => a.MAIL.ToLower() == request.CostingOfficer).FirstOrDefault();

                                FollowUpSetRes response        = new FollowUpSetRes();
                                FollowUpSetReq followUprequest = new FollowUpSetReq();
                                followUprequest.QRFID = request.QRFID;

                                FollowUpTask task = new FollowUpTask();
                                task.Task             = "Costing Approval Requested";
                                task.FollowUpType     = "Internal";
                                task.FollowUpDateTime = DateTime.Now;

                                task.FromEmail = request.PlacerEmail;
                                if (FromUser != null)
                                {
                                    task.FromName       = FromUser.CommonTitle + " " + FromUser.FIRSTNAME + " " + FromUser.LastNAME;
                                    task.FromContact_Id = FromUser.Contact_Id;
                                }

                                task.ToEmail = request.CostingOfficer;
                                if (ToUser != null)
                                {
                                    task.ToName       = ToUser.CommonTitle + " " + ToUser.FIRSTNAME + " " + ToUser.LastNAME;
                                    task.ToContact_Id = ToUser.Contact_Id;
                                }

                                task.Status = "Pending for Approval";
                                task.Notes  = "Costing Approval Requested";

                                var FollowUpTaskList = new List <FollowUpTask>();
                                FollowUpTaskList.Add(task);

                                followUprequest.FollowUp.Add(new FollowUp
                                {
                                    FollowUp_Id  = Guid.NewGuid().ToString(),
                                    FollowUpTask = FollowUpTaskList,
                                    CreateUser   = request.PlacerEmail,
                                    CreateDate   = DateTime.Now
                                });
                                await _quoteRepository.SetFollowUpForQRF(followUprequest);

                                #endregion
                            }
                            else
                            {
                                #region Add Followup
                                request.PlacerEmail = request.PlacerEmail.ToLower().Trim();
                                var SalesOfficer     = _MongoContext.mQRFPrice.AsQueryable().Where(a => a.QRFID == request.QRFID && a.IsCurrentVersion == true).FirstOrDefault()?.SalesOfficer?.ToLower().Trim();
                                var CompanyList      = _MongoContext.mCompanies.AsQueryable();
                                var FromUserContacts = CompanyList.Where(x => x.ContactDetails != null && x.ContactDetails.Count > 0 && x.ContactDetails.Any(a => a.MAIL.ToLower() == request.PlacerEmail)).FirstOrDefault()?.ContactDetails;
                                var FromUser         = FromUserContacts?.Where(a => a.MAIL.ToLower() == request.PlacerEmail).FirstOrDefault();
                                var ToUserContacts   = CompanyList.Where(x => x.ContactDetails != null && x.ContactDetails.Count > 0 && x.ContactDetails.Any(a => a.MAIL.ToLower() == SalesOfficer)).FirstOrDefault()?.ContactDetails;
                                var ToUser           = ToUserContacts?.Where(a => a.MAIL.ToLower() == SalesOfficer).FirstOrDefault();

                                FollowUpSetRes response        = new FollowUpSetRes();
                                FollowUpSetReq followUprequest = new FollowUpSetReq();
                                followUprequest.QRFID = request.QRFID;

                                FollowUpTask task = new FollowUpTask();
                                task.Task             = "QRF Change Suggested";
                                task.FollowUpType     = "Internal";
                                task.FollowUpDateTime = DateTime.Now;

                                task.FromEmail = request.PlacerEmail;
                                if (FromUser != null)
                                {
                                    task.FromName       = FromUser.CommonTitle + " " + FromUser.FIRSTNAME + " " + FromUser.LastNAME;
                                    task.FromContact_Id = FromUser.Contact_Id;
                                }

                                task.ToEmail = SalesOfficer;
                                if (ToUser != null)
                                {
                                    task.ToName       = ToUser.CommonTitle + " " + ToUser.FIRSTNAME + " " + ToUser.LastNAME;
                                    task.ToContact_Id = ToUser.Contact_Id;
                                }

                                task.Status = "Draft";
                                task.Notes  = "QRF Change Suggested";

                                var FollowUpTaskList = new List <FollowUpTask>();
                                FollowUpTaskList.Add(task);

                                followUprequest.FollowUp.Add(new FollowUp
                                {
                                    FollowUp_Id  = Guid.NewGuid().ToString(),
                                    FollowUpTask = FollowUpTaskList,
                                    CreateUser   = request.PlacerEmail,
                                    CreateDate   = DateTime.Now
                                });
                                await _quoteRepository.SetFollowUpForQRF(followUprequest);

                                #endregion

                                await _MongoContext.mQuote.FindOneAndUpdateAsync(
                                    Builders <mQuote> .Filter.Eq("QRFID", request.QRFID),
                                    Builders <mQuote> .Update.
                                    Set("CurrentPipeline", "Quote Pipeline").
                                    Set("CurrentPipelineStep", "Quote").
                                    Set("Remarks", request.Remarks).
                                    Set("CurrentPipelineSubStep", "AgentInformation").
                                    Set("QuoteResult", "Success").
                                    Set("Status", "NewQuote").
                                    Set("EditUser", request.PlacerEmail).
                                    Set("EditDate", DateTime.Now)
                                    );

                                flag = await SetDataFromCostingToSales(request.QRFID, request.PlacerEmail, request.PlacerUser);
                            }
                        }
                        else if (request.EnquiryPipeline.ToLower() == "amendment pipeline")
                        {
                            await _MongoContext.mQuote.FindOneAndUpdateAsync(
                                Builders <mQuote> .Filter.Eq("QRFID", request.QRFID),
                                Builders <mQuote> .Update.
                                Set("CurrentPipeline", "Costing Approval Pipeline").
                                Set("CurrentPipelineStep", "Costing").
                                Set("Remarks", request.Remarks).
                                Set("CurrentPipelineSubStep", "Itinerary").
                                Set("QuoteResult", "Success").
                                Set("Status", "NewCostingApprovalPipeline").
                                Set("EditUser", request.PlacerEmail).
                                Set("EditDate", DateTime.Now)
                                );

                            await _MongoContext.mQRFPrice.UpdateManyAsync(
                                Builders <mQRFPrice> .Filter.Eq("QRFID", request.QRFID),
                                Builders <mQRFPrice> .Update.
                                Set("ProductAccountant", request.CostingOfficer).
                                Set("EditUser", request.PlacerEmail).
                                Set("EditDate", DateTime.Now)
                                );
                        }
                        else if (request.EnquiryPipeline.ToLower() == "costing approval pipeline")
                        {
                            if (request.IsApproveQuote)
                            {
                                await _MongoContext.mQuote.FindOneAndUpdateAsync(
                                    Builders <mQuote> .Filter.Eq("QRFID", request.QRFID),
                                    Builders <mQuote> .Update.
                                    Set("CurrentPipeline", "Agent Approval Pipeline").
                                    Set("CurrentPipelineStep", "").
                                    Set("Remarks", request.Remarks).
                                    Set("CurrentPipelineSubStep", "").
                                    Set("QuoteResult", "Success").
                                    Set("Status", "NewAgentApprovalPipeline").
                                    Set("EditUser", request.PlacerEmail).
                                    Set("EditDate", DateTime.Now)
                                    );

                                #region Add Followup
                                request.PlacerEmail = request.PlacerEmail.ToLower().Trim();
                                var SalesOfficer     = _MongoContext.mQRFPrice.AsQueryable().Where(a => a.QRFID == request.QRFID && a.IsCurrentVersion == true).FirstOrDefault()?.SalesOfficer?.ToLower().Trim();
                                var CompanyList      = _MongoContext.mCompanies.AsQueryable();
                                var FromUserContacts = CompanyList.Where(x => x.ContactDetails != null && x.ContactDetails.Count > 0 && x.ContactDetails.Any(a => a.MAIL.ToLower() == request.PlacerEmail)).FirstOrDefault()?.ContactDetails;
                                var FromUser         = FromUserContacts?.Where(a => a.MAIL.ToLower() == request.PlacerEmail).FirstOrDefault();
                                var ToUserContacts   = CompanyList.Where(x => x.ContactDetails != null && x.ContactDetails.Count > 0 && x.ContactDetails.Any(a => a.MAIL.ToLower() == SalesOfficer)).FirstOrDefault()?.ContactDetails;
                                var ToUser           = ToUserContacts?.Where(a => a.MAIL.ToLower() == SalesOfficer).FirstOrDefault();

                                FollowUpSetRes response        = new FollowUpSetRes();
                                FollowUpSetReq followUprequest = new FollowUpSetReq();
                                followUprequest.QRFID = request.QRFID;

                                FollowUpTask task = new FollowUpTask();
                                task.Task             = "Costing Approved";
                                task.FollowUpType     = "Internal";
                                task.FollowUpDateTime = DateTime.Now;

                                task.FromEmail = request.PlacerEmail;
                                if (FromUser != null)
                                {
                                    task.FromName       = FromUser.CommonTitle + " " + FromUser.FIRSTNAME + " " + FromUser.LastNAME;
                                    task.FromContact_Id = FromUser.Contact_Id;
                                }

                                task.ToEmail = SalesOfficer;
                                if (ToUser != null)
                                {
                                    task.ToName       = ToUser.CommonTitle + " " + ToUser.FIRSTNAME + " " + ToUser.LastNAME;
                                    task.ToContact_Id = ToUser.Contact_Id;
                                }

                                task.Status = "Replied";
                                task.Notes  = "Costing Approved";

                                var FollowUpTaskList = new List <FollowUpTask>();
                                FollowUpTaskList.Add(task);

                                followUprequest.FollowUp.Add(new FollowUp
                                {
                                    FollowUp_Id  = Guid.NewGuid().ToString(),
                                    FollowUpTask = FollowUpTaskList,
                                    CreateUser   = request.PlacerEmail,
                                    CreateDate   = DateTime.Now
                                });
                                await _quoteRepository.SetFollowUpForQRF(followUprequest);

                                #endregion
                            }
                            else
                            {
                                await _MongoContext.mQuote.FindOneAndUpdateAsync(
                                    Builders <mQuote> .Filter.Eq("QRFID", request.QRFID),
                                    Builders <mQuote> .Update.
                                    Set("CurrentPipeline", "Costing Pipeline").
                                    Set("CurrentPipelineStep", "Itinerary").
                                    Set("Remarks", request.Remarks).
                                    Set("CurrentPipelineSubStep", "").
                                    Set("QuoteResult", "Reject").
                                    Set("Status", "NewCostingPipeline").
                                    Set("EditUser", request.PlacerEmail).
                                    Set("EditDate", DateTime.Now)
                                    );

                                #region Add Followup
                                var CostingOfficer   = _MongoContext.mQRFPrice.AsQueryable().Where(a => a.QRFID == request.QRFID && a.IsCurrentVersion == true).FirstOrDefault()?.CostingOfficer?.ToLower().Trim();
                                var CompanyList      = _MongoContext.mCompanies.AsQueryable();
                                var FromUserContacts = CompanyList.Where(x => x.ContactDetails != null && x.ContactDetails.Count > 0 && x.ContactDetails.Any(a => a.MAIL.ToLower() == request.PlacerEmail)).FirstOrDefault()?.ContactDetails;
                                var FromUser         = FromUserContacts?.Where(a => a.MAIL.ToLower() == request.PlacerEmail.ToLower()).FirstOrDefault();
                                var ToUserContacts   = CompanyList.Where(x => x.ContactDetails != null && x.ContactDetails.Count > 0 && x.ContactDetails.Any(a => a.MAIL.ToLower() == CostingOfficer)).FirstOrDefault()?.ContactDetails;
                                var ToUser           = ToUserContacts?.Where(a => a.MAIL.ToLower() == CostingOfficer).FirstOrDefault();

                                FollowUpSetRes response        = new FollowUpSetRes();
                                FollowUpSetReq followUprequest = new FollowUpSetReq();
                                followUprequest.QRFID = request.QRFID;

                                FollowUpTask task = new FollowUpTask();
                                task.Task             = "Costing Changes Suggested";
                                task.FollowUpType     = "Internal";
                                task.FollowUpDateTime = DateTime.Now;

                                task.FromEmail = request.PlacerEmail;
                                if (FromUser != null)
                                {
                                    task.FromName       = FromUser.CommonTitle + " " + FromUser.FIRSTNAME + " " + FromUser.LastNAME;
                                    task.FromContact_Id = FromUser.Contact_Id;
                                }

                                task.ToEmail = CostingOfficer;
                                if (ToUser != null)
                                {
                                    task.ToName       = ToUser.CommonTitle + " " + ToUser.FIRSTNAME + " " + ToUser.LastNAME;
                                    task.ToContact_Id = ToUser.Contact_Id;
                                }

                                task.Status = "Request";
                                task.Notes  = "Costing Changes Suggested";

                                var FollowUpTaskList = new List <FollowUpTask>();
                                FollowUpTaskList.Add(task);

                                followUprequest.FollowUp.Add(new FollowUp
                                {
                                    FollowUp_Id  = Guid.NewGuid().ToString(),
                                    FollowUpTask = FollowUpTaskList,
                                    CreateUser   = request.PlacerEmail,
                                    CreateDate   = DateTime.Now
                                });
                                await _quoteRepository.SetFollowUpForQRF(followUprequest);

                                #endregion
                            }
                        }

                        #region Send Email
                        string doctype = "";
                        if (request.EnquiryPipeline.ToLower() == "costing pipeline")
                        {
                            if (request.IsApproveQuote)
                            {
                                doctype = DocType.COAPPROVAL;
                            }
                            else
                            {
                                doctype = DocType.COREJECT;
                            }
                        }
                        else if (request.EnquiryPipeline.ToLower() == "amendment pipeline")
                        {
                            doctype = DocType.COAPPROVAL;
                        }
                        else if (request.EnquiryPipeline.ToLower() == "costing approval pipeline")
                        {
                            if (request.IsApproveQuote)
                            {
                                doctype = DocType.CAPAPPROVAL;
                            }
                            else
                            {
                                doctype = DocType.CAPREJECT;
                            }
                        }

                        var objEmailGetReq = new EmailGetReq()
                        {
                            UserName        = request.PlacerUser,
                            UserEmail       = request.PlacerEmail,
                            PlacerUserId    = request.PlacerUserId,
                            QrfId           = request.QRFID,
                            Remarks         = request.Remarks,
                            DocumentType    = doctype,
                            EnquiryPipeline = request.EnquiryPipeline,
                            IsApproveQuote  = request.IsApproveQuote
                        };
                        var responseStatusMail = await _emailRepository.GenerateEmail(objEmailGetReq);

                        if (responseStatusMail == null || responseStatusMail.ResponseStatus == null || string.IsNullOrEmpty(responseStatusMail.ResponseStatus.Status))
                        {
                            responseStatusMail.ResponseStatus              = new ResponseStatus();
                            responseStatusMail.ResponseStatus.Status       = "Error";
                            responseStatusMail.ResponseStatus.ErrorMessage = "Mail not sent.";
                        }
                        #endregion

                        return(request.QRFID);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (MongoWriteException)
            {
                return(null);
            }
        }