Beispiel #1
0
        /// <summary>
        /// Callback verzenden.
        /// </summary>
        /// <param name="ar"></param>
        private void SendCallback(IAsyncResult ar)
        {
            Tuple <Client, FollowUpTask> tuple = (Tuple <Client, FollowUpTask>)ar.AsyncState;

            Client       client   = tuple.Item1;
            Socket       handler  = client.Socket;
            FollowUpTask followUp = tuple.Item2;

            int sent = handler.EndSend(ar);

#if DEBUG
            Console.WriteLine($"Sent {sent} bytes to {handler.RemoteEndPoint}");
#endif

            switch (followUp)
            {
            case FollowUpTask.RECEIVE_MSG:
                MessageState state = new MessageState(client);
                //handler.BeginReceive(state.Buffer, 0, StateObject.BufferSize, 0, ReceiveCallback, state);
                Receive(client, state.Buffer, 0, StateObject.BufferSize, 0, ReceiveMessageCallback, state);
                break;

            case FollowUpTask.DISCONNECT:
                DisconnectClient(client);
                break;

            default:
                break;
            }
        }
Beispiel #2
0
        public JsonResult SetQuoteFollowUp(FollowUpViewModel model)
        {
            FollowUpSetRes response = new FollowUpSetRes();
            FollowUpSetReq request  = new FollowUpSetReq();

            request.QRFID = model.QRFID;

            if (!string.IsNullOrEmpty(model.FollowUpTime))
            {
                var time = model.FollowUpTime.Split(":");
                model.FollowUpDate = model.FollowUpDate.AddHours(Convert.ToDouble(time[0])).AddMinutes(Convert.ToDouble(time[1]));
            }

            FollowUpTask task = new FollowUpTask();

            task.Task             = model.FollowUpTask;
            task.FollowUpType     = model.FollowUpType;
            task.FollowUpDateTime = model.FollowUpDate;

            task.FromName       = ckUserName;
            task.FromContact_Id = ckUserContactId;
            task.FromEmail      = ckUserEmailId;

            if (model.FollowUpType == "Internal")
            {
                task.ToName       = model.InternalUserName;
                task.ToContact_Id = model.InternalUser.Split("|")[0];
                task.ToEmail      = model.InternalUser.Split("|")[1];
            }
            else
            {
                task.ToName       = model.ExternalUserName;
                task.ToContact_Id = model.ExternalUser.Split("|")[0];
                task.ToEmail      = model.ExternalUser.Split("|")[1];
            }

            task.Status = "Requested";
            task.Notes  = model.Notes;

            var FollowUpTaskList = new List <FollowUpTask>();

            FollowUpTaskList.Add(task);

            request.FollowUp.Add(new FollowUp
            {
                FollowUp_Id  = Guid.NewGuid().ToString(),
                FollowUpTask = FollowUpTaskList,
                CreateUser   = ckUserEmailId,
                CreateDate   = DateTime.Now
            });

            response = salesProviders.SetFollowUpForQRF(request, token).Result;

            if (response != null)
            {
                return(Json(response.ResponseStatus));
            }
            return(Json("failure"));
        }
Beispiel #3
0
        /// <summary>
        /// Verstuurt een packet naar de ingegeven client.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="packet"></param>
        /// <param name="callback"></param>
        /// <param name="task"></param>
        private void SendPacket(Client client, IPacket packet, AsyncCallback callback, FollowUpTask task)
        {
#if DEBUG
            Console.WriteLine($"Sending packet to {client.Socket.RemoteEndPoint}");
#endif
            Socket handler = client.Socket;
            byte[] buffer  = Util.NetworkUtils.CreatePacket(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(packet.ToJson())));
            handler.BeginSend(buffer, 0, buffer.Length, 0, callback, new Tuple <Client, FollowUpTask>(client, task));
        }
        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);
            }
        }