예제 #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);

                            }


                        }
                    }
                }

                
            }
           
        }
예제 #2
0
        //internal bool AcceptStudent(StudentTeacherMap objReq)
        //{
        //   // var isTutor = Convert.ToBoolean(objReq.userId);
        //    using (var db = new WizzDataContext())
        //    {
        //        if (objReq.isAccept.ToLower() == "true")
        //        {
        //            tblRequest reqStudent = new tblRequest();
        //            var studentList = db.tblRequestStudents.Where(x => x.isAccepted != true && x.isDelete == false && x.uniqueRequestId == objReq.uniqueRequestId && x.fkUserId == Convert.ToInt32(objReq.tutorId)).ToList();

        //            studentList.ForEach(a => { a.isAccepted = true; a.updatedDate = DateTime.UtcNow; });
        //            db.SubmitChanges();//update student request
                
        //            var totalList = db.tblRequests.Where(x => x.isAccepted != true &&  x.uniqueRequestId == objReq.uniqueRequestId && x.fkStudentId==Convert.ToInt32(objReq.studentId)).ToList();
        //            var deleteList = totalList.Where(x => x.fkTutorId != Convert.ToInt32(objReq.tutorId)).ToList();
                   

        //            //delete all tutors who recived the notiifcation except the tutor who is accepeting the notification
        //            reqStudent = totalList.Where(x => x.fkTutorId == Convert.ToInt32(objReq.tutorId)).FirstOrDefault();
        //            db.tblRequests.DeleteAllOnSubmit(deleteList);
        //            db.SubmitChanges();

        //            //accept the request
        //            if (reqStudent == null)//if request is not exist
        //                return false;
        //            reqStudent.isAccepted = true;
        //            reqStudent.updatedDate = DateTime.UtcNow;
        //            var userData = db.tblUsers.Where(x => x.pkUserId == Convert.ToInt32(objReq.studentId)&& x.isTeacher==false).FirstOrDefault();
        //            var teacherData = db.tblUsers.Where(x => x.pkUserId == Convert.ToInt32(objReq.tutorId)).FirstOrDefault();
        //            if (userData!=null &&!string.IsNullOrEmpty(userData.deviceToken))
        //            {
                        
        //             //   objPush.type = Convert.ToInt16(PushType.acceptRequest).ToString();

        //                PushData push = new PushData()
        //                {
        //                    registration_ids = userData.deviceToken,
        //                    //push.data = CommonMethod.ObjectToJson(objPush);
        //                    message = PushMessages.FormatMessage(PushMessages.acceptRequest, teacherData.userName),
        //                    type = Convert.ToInt16(PushType.acceptRequest).ToString(),
        //                    badge = Convert.ToString(userData.badge)
        //                };
        //                if (userData.deviceType == Convert.ToInt16(DeviceType.ios))//ios
        //                {
        //                    SendPush objIOS = new SendPush();
        //                    objIOS.ConnectToAPNS(push);
        //                }
        //                else if (userData.deviceType == Convert.ToInt16(DeviceType.android))//android
        //                {
        //                    Android objAndroid = new Android();
        //                    objAndroid.send(push);

        //                }
        //            }

        //            // update tblrequest by isAccept=1 and delete rest of request

        //        }
        //        else
        //        {

        //            var objRequestData = db.tblRequests.Where(x => x.isAccepted == false && x.fkTutorId ==Convert.ToInt32(objReq.tutorId) && x.uniqueRequestId==objReq.uniqueRequestId).FirstOrDefault();
        //            if (objRequestData != null)
        //            {
        //                db.tblRequests.DeleteOnSubmit(objRequestData);
        //                db.SubmitChanges();
        //            }
        //            else {

        //                return false;
        //            }
                
        //        }
              
        //        db.SubmitChanges();
        //        return true;
                
        //    }
        //}

        #endregion
        internal bool SendPushForIos(IosPushModel push)
        {
            
            tblUser receiverData = new tblUser();
            using (var db = new WizzDataContext())
            {
                receiverData = db.tblUsers.Where(c => c.pkUserId == Convert.ToInt32(push.receiverId)).FirstOrDefault();
                var sendor = db.tblUsers.Where(c => c.pkUserId == Convert.ToInt32(push.senderId)).FirstOrDefault();
                // objPush.deviceToken = receiverData.deviceToken;

                PushData objPush = new PushData()
                {
                    message = sendor.userName + ": " + push.Message,
                    type = Convert.ToInt16(PushType.chatPush).ToString(),
                    messageType=push.Type,
                    userId=push.senderId,
                    subject=push.subjectName,
                    registration_ids = receiverData.deviceToken,
                    badge = Convert.ToString(receiverData.badge),
                    uniqueRequestid=push.requestId
                };



                // push.type = PushType.newRequest.ToString();

                // push.data = CommonMethod.ObjectToJson(objPush);
                //  push.Type =push.Type;
                //     push.messageId = push.messageId;
                //   push.Message = push.Message;
                //    push.senderName=push

                if (receiverData.deviceType == 1)//ios
                {
                    SendPush objIOS = new SendPush();
                    objIOS.ConnectToAPNS(objPush);
                }
                else if (receiverData.deviceType == 2)//android
                {
                    PushForIos objAndroid = new PushForIos();
                    objAndroid.SendPushForIos(push);

                }
            }
            return true;
            ///throw new NotImplementedException();
        }
예제 #3
0
        //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);
                            
                        }
                    }
                }
            }
        }
예제 #4
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;
        }