Esempio n. 1
0
        ///this method will called once in a day
        internal void ChorneJob()
        {
         
            using (var db = new WizzDataContext())
            {
                var tutorList = db.usp_GetPendingRequest().ToList();

                if(tutorList!=null&&tutorList.Count>0)
                {
                    foreach(var item in tutorList )
                    {
                        if(!string.IsNullOrEmpty(item.devicetoken))
                        {
                            PushData push = new PushData();
                            push.registration_ids = item.devicetoken;
                            push.badge = Convert.ToString(item.badge);
                            push.message = PushMessages.cron;
                            if(item.devicetype==Convert.ToInt16(DeviceType.ios))
                            {
                               SendPush objIOS = new SendPush();
                                objIOS.ConnectToAPNS(push);
                              
                            }
                            else if (item.devicetype == Convert.ToInt16(DeviceType.android))//android
                            {
                                Android objAndroid = new Android();
                                objAndroid.send(push);

                            }


                        }
                    }
                }

                
            }
           
        }
        //internal int SaveTutorSubjects(TutorSubjects objReq)
        //{

        //    tblTutorSubject objSubjectData = new tblTutorSubject();
        //    using (var db = new WizzDataContext())
        //    {
        //        objSubjectData = db.tblTutorSubjects.Where(x => x.fkTutorId == Convert.ToInt64(objReq.tutorId)).FirstOrDefault();
        //        if (objSubjectData == null)
        //        {
        //            //objSubjectData = new TutorSubjects();
        //            //objSubjectData.isApproved = true;
        //            //objSubjectData.isActive = true;
        //            //objSubjectData.fkUserId = Convert.ToInt64(objReq.userId);
        //            //objSubjectData.latitude = Convert.ToDecimal(objReq.latitude);
        //            //objSubjectData.longitude = Convert.ToDecimal(objReq.longitude);
        //            //objSubjectData.subjects = objReq.majors;
        //            //objSubjectData.TimeStamp = Convert.ToDateTime(objReq.timeStamp).Ticks;
        //            //objSubjectData.updatedDate = DateTime.UtcNow;
        //            //objSubjectData.createdDate = DateTime.UtcNow;
        //            //objSubjectData.passingYear = objReq.passingYear;
        //            //objSubjectData.referralcode = objReq.referalCode == null ? "" : objReq.referalCode;
        //            ////    profileData.fkClassId = String.Join(",", objReq.classes);
        //            //objSubjectData.fkCollegeId = Convert.ToInt32(objReq.collegeId);
        //            //db.tblTutorProfiles.InsertOnSubmit(objSubjectData);

        //        }
        //        else
        //        {
        //            //objSubjectData.isApproved = true;
        //            //objSubjectData.isActive = true;
        //            //objSubjectData.fkUserId = Convert.ToInt64(objReq.userId);
        //            //objSubjectData.latitude = Convert.ToDecimal(objReq.latitude);
        //            //objSubjectData.longitude = Convert.ToDecimal(objReq.longitude);
        //            //objSubjectData.subjects = objReq.majors;
        //            //objSubjectData.TimeStamp = Convert.ToDateTime(objReq.timeStamp).Ticks;
        //            //objSubjectData.updatedDate = DateTime.UtcNow;
        //            //objSubjectData.createdDate = DateTime.UtcNow;
        //            ////  profileData.fkClassId = String.Join(",", objReq.classes);
        //            //objSubjectData.fkCollegeId = Convert.ToInt32(objReq.collegeId);
        //        }
        //        db.SubmitChanges();
        //        return 1;
        //    }

        //}


        //save matched tutos in db and send notifications 
        void SendRequest(StudentRequestModel objReq,List<usp_GetTutorsResult> tutors,string requestId)
        {
            var studentId =Convert.ToInt64(objReq.userId);
            using(var db=new WizzDataContext())
            {
                foreach (var tutor in tutors.ToList())
                {
                    var request = new tblRequest();
                    request.createdDate = DateTime.UtcNow;
                    request.updatedDate = DateTime.UtcNow;
                    request.isAccepted = false;
                    request.isDeleted = false;
                    request.fkStudentId = studentId;
                    request.fkTutorId = tutor.fkUserId;
                    request.uniqueRequestId = requestId;
                    request.timeStamp = DateTime.UtcNow.Ticks;
                    db.tblRequests.InsertOnSubmit(request);
                    db.SubmitChanges();
                    //sendpush

                    if(!string.IsNullOrEmpty(tutor.deviceToken))
                    {
                        PushData push=new PushData()
                        {
                        
                        registration_ids = tutor.deviceToken,
                        message = PushMessages.newRequest,
                        type = Convert.ToInt16(PushType.newRequest).ToString(),
                        badge = Convert.ToString(tutor.badge)
                    };
                       // push.data = CommonMethod.ObjectToJson(objPush);

                        if (tutor.deviceType == Convert.ToInt16(DeviceType.ios))//ios
                        { 
                            SendPush objIOS=new SendPush();
                            objIOS.ConnectToAPNS(push);
                        }
                        else if (tutor.deviceType == Convert.ToInt16(DeviceType.android))//android
                        {
                            Android objAndroid = new Android();
                            objAndroid.send(push);
                            
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        private void SendSessionEndPushes(string sessionAmt, string uniqueRequestid, WizzDataContext db, long studentId, long sessionId, long tutorId)
        {


            var sessionStudents = db.tblInviteFriends.Where(x => x.uniqueRequestId == uniqueRequestid).ToList();
            if (sessionStudents != null)
            {
                if (sessionStudents.Count == 0)
                {
                    var studentData = db.tblUsers.Where(x => x.pkUserId == studentId).FirstOrDefault();//missed is tutor intentionally
                    if (!string.IsNullOrEmpty(studentData.deviceToken))
                    {

                        PushData push = new PushData()
                        {
                            registration_ids = studentData.deviceToken,
                            uniqueRequestid = uniqueRequestid.ToString(),
                            sessionId = sessionId.ToString(),
                            tutorId = tutorId.ToString(),
                            amount = Convert.ToString(sessionAmt),
                            //   userId = Convert.ToString(sessionData.fkTutorId),
                            message = PushMessages.sessionEnd,
                            type = Convert.ToInt16(PushType.sessionEnd).ToString(),
                            badge = Convert.ToString(studentData.badge)
                        };
                        // push.data = CommonMethod.ObjectToJson(objPush);
                        if (studentData.deviceType == Convert.ToInt16(DeviceType.ios))//ios
                        {
                            SendPush objIOS = new SendPush();
                            objIOS.ConnectToAPNS(push);
                        }
                        else if (studentData.deviceType == Convert.ToInt16(DeviceType.android))//android
                        {
                            Android objAndroid = new Android();
                            objAndroid.send(push);
                        }

                    }
                }
                else
                {
                    #region multiple pushes
                    foreach (var n in sessionStudents)
                    {
                        if (n.fkFriendId == 0)
                            continue;

                        var studentData = db.tblUsers.Where(x => x.pkUserId == n.fkFriendId).FirstOrDefault();//missed is tutor intentionally
                        if (!string.IsNullOrEmpty(studentData.deviceToken))
                        {

                            PushData push = new PushData()
                            {
                                registration_ids = studentData.deviceToken,
                                uniqueRequestid = uniqueRequestid.ToString(),
                                amount = Convert.ToString(sessionAmt),
                                //   userId = Convert.ToString(sessionData.fkTutorId),
                                message = PushMessages.sessionEnd,
                                type = Convert.ToInt16(PushType.sessionEnd).ToString(),
                                badge = Convert.ToString(studentData.badge),
                                sessionId = sessionId.ToString()
                            };
                            // push.data = CommonMethod.ObjectToJson(objPush);
                            if (studentData.deviceType == Convert.ToInt16(DeviceType.ios))//ios
                            {
                                SendPush objIOS = new SendPush();
                                objIOS.ConnectToAPNS(push);
                            }
                            else if (studentData.deviceType == Convert.ToInt16(DeviceType.android))//android
                            {
                                Android objAndroid = new Android();
                                objAndroid.send(push);
                            }

                        }
                    }
                    #endregion
                }

            }




        }
        public Response<string> SendPush(push objReq)
        {
            Response<string> response = new Response<string>();
            List<string> objResp = new List<string>();
            try
            {


                if (CheckRequestIsvalidornot(this.Request))
                {
                    if (!string.IsNullOrEmpty(objReq.deviceToken))
                    {
                        PushMessage objPush = new PushMessage();
                        objPush.message = PushMessages.newRequest;
                        // objPush.type = PushType.newRequest.ToString();

                        PushData push = new PushData();
                        push.message = "Testing";
                        push.registration_ids = objReq.deviceToken;
                        // push.data = CommonMethod.ObjectToJson(objPush);
                        push.type = Convert.ToInt16(PushType.acceptRequest).ToString();
                        if (objReq.deviceType == "1")//ios
                        {
                            SendPush objIOS = new SendPush();
                            objIOS.ConnectToAPNS(push);
                        }
                        else if (objReq.deviceType == "2")//android
                        {
                            Android objAndroid = new Android();
                            objAndroid.send(push);

                        }
                    }
                    else
                        response.Create(false, ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage, Messages.AppVersion, objResp);
                }
                else
                    response.Create(false, Messages.FormatMessage(Messages.InvalidReq), Messages.AppVersion, objResp);

            }
            catch (Exception ex)
            {
                object session = new JavaScriptSerializer().Serialize(objReq);
                LogManager.Error("Error occured while Processing Webservice request :{0}", ex, session, ex.Message);
                response.Create(false, Messages.FormatMessage(Messages.ErrorOccure), Messages.AppVersion, objResp);
            }
            finally
            {
            }
            return response;
        }