예제 #1
0
        public async Task <cStatus> Postsubcriberswithnotifiy([FromBody] ctblSubscriber ctblSubscriber)
        {
            cStatus status = new cStatus();

            string retvalue, deviceID, receiverName;

            try
            {
                string constr = ConfigurationManager.ConnectionStrings["MyAbDbContext"].ConnectionString;

                using (SqlConnection con = new SqlConnection(constr))
                {
                    SqlCommand cmd = new SqlCommand("sp_addupdate_subscriber", con);
                    cmd.CommandType = CommandType.StoredProcedure;


                    SqlParameter paramReceiverID = new SqlParameter();
                    paramReceiverID.ParameterName = "@ReceiverID";
                    paramReceiverID.Value         = ctblSubscriber.ReceiverID;
                    cmd.Parameters.Add(paramReceiverID);

                    SqlParameter paramReceiverUserType = new SqlParameter();
                    paramReceiverUserType.ParameterName = "@ReceiverUserType";
                    paramReceiverUserType.Value         = ctblSubscriber.ReceiverUserType;
                    cmd.Parameters.Add(paramReceiverUserType);

                    SqlParameter paramSenderID = new SqlParameter();
                    paramSenderID.ParameterName = "@SenderID";
                    cmd.Parameters.Add(paramSenderID);


                    SqlParameter paramsubscribeonoff = new SqlParameter();
                    paramsubscribeonoff.ParameterName = "@subscribeonoff";
                    cmd.Parameters.Add(paramsubscribeonoff);

                    cmd.Parameters.Add("@LastInsertedID", SqlDbType.Int);
                    cmd.Parameters["@LastInsertedID"].Direction = ParameterDirection.Output;

                    cmd.Parameters.Add("@deviceID", SqlDbType.NVarChar, 300);
                    cmd.Parameters["@deviceID"].Direction = ParameterDirection.Output;


                    cmd.Parameters.Add("@receivername", SqlDbType.NVarChar, 50);
                    cmd.Parameters["@receivername"].Direction = ParameterDirection.Output;

                    con.Open();
                    SendNotificationController s = new SendNotificationController();
                    cStatus st = new cStatus();
                    for (int i = 0; i < ctblSubscriber.Senders.Count; i++)
                    {
                        paramSenderID.Value       = ctblSubscriber.Senders[i].SenderID;
                        paramsubscribeonoff.Value = ctblSubscriber.Senders[i].subscribeonoff;
                        cmd.ExecuteNonQuery();
                        deviceID     = cmd.Parameters["@deviceID"].Value.ToString();
                        receiverName = cmd.Parameters["@receivername"].Value.ToString();

                        /* if (ctblSubscriber.Senders[i].subscribeonoff.Contains("ON"))
                         * {
                         * st=await   s.SubscriberNotificationAsync(deviceID, receiverName, " following you @ Thandora");
                         * }
                         * else
                         * {
                         * st=await  s.SubscriberNotificationAsync(deviceID, receiverName, " leaving you @ Thandora");
                         * }
                         * status.DesctoDev = st.DesctoDev;
                         */
                        // status.returnID = int.Parse(retvalue);
                    }
                    con.Close();

                    retvalue        = cmd.Parameters["@LastInsertedID"].Value.ToString();
                    status.returnID = int.Parse(retvalue);
                    if (status.returnID > 0)
                    {
                        status.StatusID  = 0;
                        status.StatusMsg = "Updated successfully";
                        status.DesctoDev = "Updated successfully, Need to call FCM subscribe method";
                    }
                    else if (status.returnID == -1)
                    {
                        status.StatusID  = 1;
                        status.StatusMsg = "Updation failed";
                        status.DesctoDev = "Updation failed, Invalid user ";
                    }
                    else if (status.returnID == -2)
                    {
                        status.StatusID  = 1;
                        status.StatusMsg = "Updation failed";
                        status.DesctoDev = "Updation failed, Invalid user ";
                    }

                    // cmd.Dispose();
                }
            }
            catch (Exception ex)
            {
                retvalue         = ex.Message.ToString();
                status.StatusID  = 1;
                status.StatusMsg = retvalue;
                status.DesctoDev = "Updation failed, Please check your internet";
            }

            return(status);

            /* if (!ModelState.IsValid)
             * {
             *   return BadRequest(ModelState);
             * }
             *
             * db.ctblSubscribers.Add(ctblSubscriber);
             * db.SaveChanges();
             *
             * return CreatedAtRoute("DefaultApi", new { id = ctblSubscriber.SubscribeID }, ctblSubscriber);*/
        }
        public async Task <List <cServiceProvider> > ServicesbySearchv1_3(int userid, string userType, string SEARCH)
        {
            List <cServiceProvider> spCollctionlist  = new List <cServiceProvider>();
            List <cPartialSender>   ServiceProviders = new List <cPartialSender>();
            //List<cPartialSender> SendersList = new List<cPartialSender>();

            string retvalue = "1", userPostcode = "";

            try
            {
                string constr = ConfigurationManager.ConnectionStrings["MyAbDbContext"].ConnectionString;

                using (SqlConnection con = new SqlConnection(constr))
                {
                    SqlCommand cmd = new SqlCommand("sp_listServiceProviderforSearch", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlDataReader reader;

                    SqlParameter paramsearch = new SqlParameter();
                    paramsearch.ParameterName = "@search";
                    paramsearch.Value         = SEARCH;
                    cmd.Parameters.Add(paramsearch);

                    SqlParameter paramuserid = new SqlParameter();
                    paramuserid.ParameterName = "@userID";
                    paramuserid.Value         = userid;
                    cmd.Parameters.Add(paramuserid);

                    SqlParameter paramuserType = new SqlParameter();
                    paramuserType.ParameterName = "@userType";
                    paramuserType.Value         = userType;
                    cmd.Parameters.Add(paramuserType);



                    /*   cmd.Parameters.Add("@Result", SqlDbType.Int);
                     * cmd.Parameters["@Result"].Direction = ParameterDirection.Output;*/

                    con.Open();
                    reader = cmd.ExecuteReader();

                    //retvalue = cmd.Parameters["@Result"].Value.ToString();

                    while (reader.Read())
                    {
                        cPartialSender c = new cPartialSender();
                        c.SenderID          = (int)reader["SenderID"];
                        c.SenderName        = reader["SenderName"].ToString().Trim();
                        c.SenderContactNo_1 = reader["SenderContactNo_1"].ToString().Trim();
                        c.SenderContactNo_2 = reader["SenderContactNo_2"].ToString().Trim();

                        c.ContactHide  = (Int16)reader["ContactHide"];
                        c.cServiceType = reader["cServiceType"].ToString().Trim();
                        c.ServiceDesc  = reader["ServiceDesc"].ToString().Trim();
                        c.postcode     = reader["POSTCODE"].ToString().Trim();

                        if (reader["logopath"] != null)
                        {
                            if (reader["logopath"].ToString().Length > 0)
                            {
                                c.logopath = reader["logopath"].ToString().Trim();
                            }
                        }

                        c.subscribeonoff      = reader["subscribeonoff"].ToString().Trim();
                        c.ReviewReceived      = (int)reader["ReviewReceived"];
                        c.msgCommentsReceived = (int)reader["msgCommentsReceived"];
                        c.msgLikeReceived     = (int)reader["msgLikeReceived"];
                        c.msgTotpublished     = (int)reader["msgTotpublished"];
                        c.msgReadBy           = (int)reader["msgReadBy"];
                        c.isFCMActive         = reader["isFCMActive"].ToString().Trim();
                        ServiceProviders.Add(c);
                        //}
                        // }

                        // } while (reader.Read() && sp.cServiceCategory.Equals(reader["cServiceType"].ToString().Trim()));
                    }
                }
            }
            catch (Exception ex)
            {
                retvalue = ex.Message.ToString();
            }
            //return Ok(retvalue);*/
            try
            {
                string constr = ConfigurationManager.ConnectionStrings["MyAbDbContext"].ConnectionString;

                using (SqlConnection con = new SqlConnection(constr))
                {
                    SqlCommand cmd = new SqlCommand("sp_getPostcode", con);
                    cmd.CommandType = CommandType.StoredProcedure;


                    SqlParameter paramuserType = new SqlParameter();
                    paramuserType.ParameterName = "@userType";
                    paramuserType.Value         = userType;
                    cmd.Parameters.Add(paramuserType);

                    SqlParameter paramuserid = new SqlParameter();
                    paramuserid.ParameterName = "@userID";
                    paramuserid.Value         = userid;
                    cmd.Parameters.Add(paramuserid);

                    cmd.Parameters.Add("@postcode", SqlDbType.NVarChar, 6);
                    cmd.Parameters["@postcode"].Direction = ParameterDirection.Output;

                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                    userPostcode = cmd.Parameters["@postcode"].Value.ToString();
                }
            }
            catch (Exception e)
            { }
            SendNotificationController s        = new SendNotificationController();
            cPostCodeDistance          distance = new cPostCodeDistance();

            foreach (cPartialSender snd in ServiceProviders)
            {
                if (!userPostcode.Equals(snd.postcode))
                {
                    distance = await s.GetCalculatedistanceAsync(userPostcode, snd.postcode);

                    if (distance.rows[0].elements[0].status.Contains("OK"))
                    {
                        snd.postcode       = distance.rows[0].elements[0].distance.text;             ////the value in KMS. eg 2,435 KM
                        snd.ReviewReceived = int.Parse(distance.rows[0].elements[0].distance.value); /// the value in meters. eg 2435675
                    }
                }
                else
                {
                    snd.postcode       = "LOCAL";
                    snd.ReviewReceived = 0;
                }
            }


            for (int i = 0; i < ServiceProviders.Count; i++)
            {
                for (int j = 0; j < ServiceProviders.Count; j++)
                {
                    cPartialSender swp = new cPartialSender();
                    if (ServiceProviders[i].ReviewReceived < ServiceProviders[j].ReviewReceived)
                    {
                        swp = ServiceProviders[j];
                        ServiceProviders[j] = ServiceProviders[i];
                        ServiceProviders[i] = swp;
                    }
                }
            }
            cServiceProvider spprov             = new cServiceProvider();

            spprov.providers        = ServiceProviders;
            spprov.cCount           = ServiceProviders.Count;
            spprov.cServiceCategory = "Results Found";
            spprov.cSvcDesc         = SEARCH;
            spCollctionlist.Add(spprov);
            //return ServiceProviders;
            CreateEnquiries(userid, userType, spCollctionlist);
            return(spCollctionlist);
        }
예제 #3
0
        public async Task <IHttpActionResult> PostctblSender([FromBody] ctblSender ctblSender)
        {
            cStatus status = new cStatus();
            string  retvalue;

            try
            {
                string constr = ConfigurationManager.ConnectionStrings["MyAbDbContext"].ConnectionString;

                using (SqlConnection con = new SqlConnection(constr))
                {
                    SqlCommand cmd = new SqlCommand("sp_new_sender", con);
                    cmd.CommandType = CommandType.StoredProcedure;

                    SqlParameter paramSendName = new SqlParameter();
                    paramSendName.ParameterName = "@SenderName";
                    paramSendName.Value         = ctblSender.SenderName;
                    cmd.Parameters.Add(paramSendName);

                    SqlParameter paramSenderPhone = new SqlParameter();
                    paramSenderPhone.ParameterName = "@SenderPhone";
                    paramSenderPhone.Value         = ctblSender.SenderPhone;
                    cmd.Parameters.Add(paramSenderPhone);

                    if (ctblSender.deviceTokenID == null)
                    {
                        ctblSender.deviceTokenID = "Assigned by API";

                        /* status.StatusID = 1;
                         * status.DesctoDev = "FCM Device id null ";
                         * status.StatusMsg = " FCM Device id null ";
                         * return Ok(status);*/
                    }

                    SqlParameter paramdeviceTokenID = new SqlParameter();
                    paramdeviceTokenID.ParameterName = "@IME";
                    paramdeviceTokenID.Value         = ctblSender.deviceTokenID;
                    cmd.Parameters.Add(paramdeviceTokenID);


                    SqlParameter paramRecSIMNO = new SqlParameter();
                    paramRecSIMNO.ParameterName = "@SIMNO";
                    paramRecSIMNO.Value         = ctblSender.SIMNO;
                    cmd.Parameters.Add(paramRecSIMNO);

                    SqlParameter paramSenderContactNo_1 = new SqlParameter();
                    paramSenderContactNo_1.ParameterName = "@SenderContactNo_1";
                    paramSenderContactNo_1.Value         = ctblSender.SenderContactNo_1;
                    cmd.Parameters.Add(paramSenderContactNo_1);

                    /* SqlParameter paramSenderContactNo_2 = new SqlParameter();
                     * paramSenderContactNo_2.ParameterName = "@SenderContactNo_2";
                     * paramSenderContactNo_2.Value = ctblSender.SenderContactNo_2;
                     * cmd.Parameters.Add(paramSenderContactNo_2);
                     */

                    SqlParameter paramContactHide = new SqlParameter();
                    paramContactHide.ParameterName = "@ContactHide";
                    paramContactHide.Value         = ctblSender.ContactHide;
                    cmd.Parameters.Add(paramContactHide);

                    SqlParameter paramcServiceType = new SqlParameter();
                    paramcServiceType.ParameterName = "@cServiceType";
                    paramcServiceType.Value         = ctblSender.cServiceType;
                    cmd.Parameters.Add(paramcServiceType);

                    SqlParameter paramServiceDesc = new SqlParameter();
                    paramServiceDesc.ParameterName = "@ServiceDesc";
                    if (ctblSender.ServiceDesc == null)
                    {
                        ctblSender.ServiceDesc = " ";
                    }
                    paramServiceDesc.Value = ctblSender.ServiceDesc;
                    cmd.Parameters.Add(paramServiceDesc);

                    SqlParameter paramPOSTCODE = new SqlParameter();
                    paramPOSTCODE.ParameterName = "@POSTCODE";
                    paramPOSTCODE.Value         = ctblSender.POSTCODE;
                    cmd.Parameters.Add(paramPOSTCODE);

                    SqlParameter paramAddress = new SqlParameter();
                    paramAddress.ParameterName = "@Address";
                    if (ctblSender.Address == null)
                    {
                        ctblSender.Address = " ";
                    }
                    paramAddress.Value = ctblSender.Address;
                    cmd.Parameters.Add(paramAddress);

                    SqlParameter paramlogopath = new SqlParameter();
                    paramlogopath.ParameterName = "@logopath";
                    paramlogopath.Value         = ctblSender.logopath;
                    cmd.Parameters.Add(paramlogopath);

                    cmd.Parameters.Add("@LastInsertedID", SqlDbType.Int);
                    cmd.Parameters["@LastInsertedID"].Direction = ParameterDirection.Output;

                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                    //retvalue = cmd.Parameters["@LastInsertedID"].Value.ToString();
                    retvalue        = cmd.Parameters["@LastInsertedID"].Value.ToString();
                    status.returnID = int.Parse(retvalue);
                    if (status.returnID == -5)
                    {
                        status.StatusID  = 1;
                        status.DesctoDev = " Name Restricted ";
                        status.StatusMsg = " Name Restricted ";
                    }

                    if (status.returnID == -4)
                    {
                        status.StatusID  = 1;
                        status.DesctoDev = "Restricted word in Name ";
                        status.StatusMsg = " Restricted word in Name ";
                    }
                    if (status.returnID == -3)
                    {
                        status.StatusID  = 1;
                        status.DesctoDev = "Restricted word in Description ";
                        status.StatusMsg = " Restricted word in Description ";
                    }
                    if (status.returnID == -2)
                    {
                        status.StatusID  = 1;
                        status.DesctoDev = "-2 is the error code for invalid POSTAL code. ";
                        status.StatusMsg = " Invalid POSTAL Code. ";
                    }
                    if (status.returnID >= 100000)
                    {
                        // Whenever a new TELLER is added, a new TOPIC will be created in FCM on the TELLER ID. So that the notification
                        //will be published on the TELLER topic name, it will reach automatically all the subcribers of the TELLER.
                        //Every LISTENER & TELLER should be subscribed to the below TOPIC mandatory according to their POSTCODE
                        //FirebaseMessaging.getInstance().subscribeToTopic("POSTCODE);
                        //FirebaseMessaging.getInstance().subscribeToTopic("POSTCODE);


                        //Whenever a receiver subcribing a TELLER from Services menu that time the below line should be exeucted from the client.
                        //FirebaseMessaging.getInstance().subscribeToTopic("SenderID");

                        //DeviceGroupController dgc = new DeviceGroupController();
                        //Task<string> s=  dgc.CreateTopicGroup(ctblSender.deviceTokenID, status.returnID.ToString());

                        status.StatusID = 0;
                        //status.DesctoDev = s.ToString();


                        status.StatusMsg = " User Successfully Created/Updated ";
                        status.userType  = "S";
                        SendNotificationController s = new SendNotificationController();

                        string        msg;
                        FCMController fcm = new FCMController();
                        cStatus       st  = new cStatus();
                        if (ctblSender.cServiceType != "Personal Use" && ctblSender.cServiceType != "Home Maker")
                        {
                            st = await s.NewTellerNotificationAsync(ctblSender.POSTCODE, ctblSender.SenderName, ctblSender.cServiceType, status.returnID);

                            msg = "@POSTCODE:" + ctblSender.POSTCODE + "@SenderName:" + ctblSender.SenderName + "New user joined @ServiceType:" + ctblSender.cServiceType;

                            if (st.DesctoDev.Contains("message_id"))
                            {
                                status.StatusMsg = "Broadcast success";
                                await fcm.PostFCMResponse(st.DesctoDev, msg, "Y");
                            }
                            else
                            {
                                status.StatusMsg = "Broadcast failed";
                                await fcm.PostFCMResponse(st.DesctoDev, msg, "N");
                            }
                        }
                        ctblEnquiry enq = new ctblEnquiry();
                        string      str;
                        enq.EnquiryID      = 0;
                        str                = @"Welcome to Thandora a Business/Social media app to promote your business and services.

All business users requested to update your Address, Profile picture, business descriptions clearly with commonly searched key words specific to your business.

Any search/enquiry on Thandora related to your business area or business name, would be notified to you through SMS and Thandora notification.

If you are NOT posting for 30 calendar days, your name and services will be made dormant and made unavailable to public. 

You can invite your friends/neighbors/business partners/workers/staffs/contractors/owners to promote their business and services.

WEB: http://www.thandora.co

FB: https://www.facebook.com/search/top/?q=thandora%20-%20a%20business%20app

Regards
Thandora Admin";
                        enq.EnquiryMessage = str;
                        enq.FromUserID     = 100089;
                        enq.FromUserType   = "S";
                        enq.ToUserID       = status.returnID;
                        enq.ToUserType     = "S";
                        enq.AnswerID       = 0;
                        MessageController mc = new MessageController();
                        mc.PostEnquiry(enq);

                        AuthorizationController ac = new AuthorizationController();
                        ac.RefreshUsers();
                    }
                }
            }
            catch (Exception ex)
            {
                retvalue         = ex.Message.ToString();
                status.StatusID  = 1;
                status.StatusMsg = retvalue;
            }

            return(Ok(status));
        }