예제 #1
0
        public void ProcessMentorRequests()
        {
            foreach (var inboundSms in InboundMessages.Where(x => x.DateTimeWhenProcessed == null))
            {
                foreach (var mentorRequest in MentorRequests.Where(x => x.DateTimeWhenProcessed == null))
                {
                    if (mentorRequest.OutboundSms.ToPhoneNumber == inboundSms.FromPhoneNumber)
                    {
                        if (IsAcceptanceResponse(inboundSms))
                        {
                            _db.Delete <MentorRequest>(mentorRequest);
                            _db.Delete <SmsDto>(inboundSms);
                            mentorRequest.RequestAccepted       = true;
                            inboundSms.DateTimeWhenProcessed    = DateTime.Now;
                            mentorRequest.DateTimeWhenProcessed = DateTime.Now;
                            mentorRequest.InboundSms            = inboundSms;
                            _db.Add <MentorRequest>(mentorRequest);
                            _db.Add <SmsDto>(inboundSms);
                            //follow-up steps:
                            ResponseProcessedConfirmation(inboundSms);
                            _db.Delete <Mentor>(mentorRequest.Mentor);
                            mentorRequest.Mentor.IsAvailable = false;
                            _db.Add <Mentor>(mentorRequest.Mentor);
                            //NOTIFY SIGNALR TEAM
                            _recResponder.MentorRequestResponse(mentorRequest);
                        }
                        else if (IsRejectionResponse(inboundSms))
                        {
                            _db.Delete <MentorRequest>(mentorRequest);
                            _db.Delete <SmsDto>(inboundSms);
                            mentorRequest.RequestAccepted       = false;
                            inboundSms.DateTimeWhenProcessed    = DateTime.Now;
                            mentorRequest.DateTimeWhenProcessed = DateTime.Now;
                            mentorRequest.InboundSms            = inboundSms;
                            _db.Add <MentorRequest>(mentorRequest);
                            _db.Add <SmsDto>(inboundSms);
                            //follow-up steps:
                            ResponseProcessedConfirmation(inboundSms);
                            //NOTIFY SIGNALR TEAM
                            _recResponder.MentorRequestResponse(mentorRequest);
                        }
                        else
                        {
                            _db.Delete <SmsDto>(inboundSms);
                            inboundSms.DateTimeWhenProcessed = DateTime.Now;
                            UnIdentifiedResponse(inboundSms, mentorRequest.OutboundSms);
                            _db.Add <SmsDto>(inboundSms);
                        }
                    }
                }

                //if (IsCompletionResponse(inboundSms))
                //{
                //    _db.Delete<SmsDto>(inboundSms);
                //    inboundSms.DateTimeWhenProcessed = DateTime.Now;
                //    //
                //    ResponseProcessedConfirmation(inboundSms);
                //    _db.Add<SmsDto>(inboundSms);
                //}
                //IF inboundSms STILL UN PROCCESSED THEN HANDLE IT
                if (inboundSms.DateTimeWhenProcessed == null)
                {
                    _db.Delete <SmsDto>(inboundSms);
                    inboundSms.DateTimeWhenProcessed = DateTime.Now;
                    UnIdentifiedResponse(inboundSms);
                    _db.Add <SmsDto>(inboundSms);
                }
            }
        }