コード例 #1
0
        public void ProcessSitterResonseToJobPosting(TxtMsgInbound msgInbound, TxtMsgAwaitingResponse awaiting, AppUser user)
        {
            string feedback = null;
            bool stillAwaiting = true;
            Job job = _jobRepo.GetById(awaiting.JobId);

            if (job == null)
            {
                string msgError = "Unable to find job with id " + awaiting.JobId;
                _log.Error(msgInbound.MobilePhone, msgError, null);
                _txtMsgInboundDal.UpdateState(msgInbound.Id, TxtMsgProcessState.Error, msgError);
                _txtMsgAwaitingResponseDal.DeleteAwaiting(awaiting.Id);
                return;
            }
            var response = new SitterJobInviteResponseSM
            {
                JobId = job.Id,
                SitterId = awaiting.WaitingForUserId,
                Message = msgInbound.Message
            };

            MessageAffirmativeType aff = MessageUtility.ParseAffirmativeType(msgInbound);

            if (aff == MessageAffirmativeType.yes)
            {
                response.Response = SitterResponse.Accept;
                feedback = MessageTemplates.FormatSitterAcceptJob();
                stillAwaiting = false;
            }
            else if (aff == MessageAffirmativeType.no)
            {
                response.Response = SitterResponse.Decline;
                feedback = MessageTemplates.FormatSitterDeclineJob("parent"); //TODO
                stillAwaiting = false;
            }
            else
            {
                response.Response = SitterResponse.Unrecognized;
                feedback = MessageTemplates.FormatSitterInvalidResponseToJobOrSignup(true);
                stillAwaiting = true;
            }
            _jobRepo.ProcessSitterResponse(response, job);


            _txtMsgInboundDal.UpdateState(msgInbound.Id, TxtMsgProcessState.Processed);

            if (feedback != null)
            {
                _omm.SendFeedbackToInboundMessage(msgInbound, feedback, user.Id);
            }

            if (!stillAwaiting)
            {
                _txtMsgAwaitingResponseDal.DeleteAwaiting(awaiting.Id);
            }

            if (aff == MessageAffirmativeType.yes && job != null)
            {
                try
                {
                    // STEP - Send confirm to parent, and closed notice to other sitters
                    _omm.SendNoticeOfSitterAccept(job);
                }
                catch (Exception ex)
                {
                    _log.Error(job.ParentId.ToString(), "error while SendParentNoticeOfSitterAccept(). msgInbound.Id:" + msgInbound.Id, ex);
                    throw;
                }
            }
        }
コード例 #2
0
        public bool ProcessSitterResponse(SitterJobInviteResponseSM response, Job jobIn)
        {
            Job job = jobIn ?? _jobDal.GetById(response.JobId);
            JobInvite invite = job.JobInvites.FirstOrDefault(m => m.SitterId == response.SitterId);
            if (invite == null)
            {
                throw new AppException(string.Format("Unable to find invite on job {0} for sitterId {1}", job.Id, response.SitterId));
            }
            invite.LatestResponseDate = TimeUtil.GetCurrentUtcTime();
            invite.LatestResponseMessage = response.Message;

            if (response.Response == SitterResponse.Accept)
            {
                job.State = JobState.Accepted;
                job.AcceptedSitterId = response.SitterId;

                // STEP - Send Text to parent and other sitters of job closed.
                try
                {
                    // STEP - Send confirm to parent, and closed notice to other sitters
                    _omm.SendNoticeOfSitterAccept(job);
                }
                catch (Exception ex)
                {
                    _log.Error(job.ParentId.ToString(), "error while SendParentNoticeOfSitterAccept()." , ex);
                    throw;
                }

            }
            else if (response.Response == SitterResponse.Decline)
            {
                invite.State = InvitationState.Declined;
                bool allSittersDeclined = job.JobInvites.All(m => m.State == InvitationState.Declined);
                job.State = JobState.Closed;
                job.CloseReason = CloseReason.AllSittersDeclined;
                _omm.SendParentNoticeOfSitterDecline(job, response.SitterId, allSittersDeclined);
            }
            else
            {
                invite.State = InvitationState.InvalidResponse;
            }
            _jobDal.Update(job);

            return true;
        }