Beispiel #1
0
        public async System.Threading.Tasks.Task <Response <PushNotificationModel> > SendPushNotifications(PushNotificationModel model)
        {
            int TotalRecords = 0;
            Response <PushNotificationModel> returnModel = new Response <PushNotificationModel>();

            if (string.IsNullOrEmpty(model.customer_id) && string.IsNullOrEmpty(model.provider_id) && !model.receiver_all)
            {
                returnModel.msg     = "Please select the receiver";
                returnModel.status  = (int)EnumClass.ResponseState.ResposityError;
                returnModel.success = false;
                return(returnModel);
            }

            if (string.IsNullOrEmpty(model.text))
            {
                returnModel.msg     = "Please enter the message";
                returnModel.status  = (int)EnumClass.ResponseState.ResposityError;
                returnModel.success = false;
                return(returnModel);
            }

            using (SqlConnection DB = new SqlConnection(SiteKey.ConnectionString))
            {
                List <string> Receivers  = new List <string>();
                List <string> Receivers1 = new List <string>();
                string        DeviceId   = string.Empty;



                if (model.receiver_all)
                {
                    //send notification to customer
                    Receivers = DB.QuerySql <string>(@"SELECT id FROM customer where is_deleted = 0 ").ToList();

                    if (Receivers != null)
                    {
                        foreach (var item in Receivers)
                        {
                            DeviceId = DB.QuerySql <string>("select device_id from device_data where user_id = @UserId and user_active = 1", new { UserId = item }).FirstOrDefault();
                            if (DeviceId != null)
                            {
                                await SMSNotification.PushNotificationAsync(DeviceId, "Kharban", model.subject + Environment.NewLine + model.text, "Home", 1);
                            }
                        }
                    }


                    //send notification to provider
                    Receivers1 = DB.QuerySql <string>(@"SELECT id FROM provider where is_deleted = 0 and is_online = 1 ").ToList();

                    if (Receivers1 != null)
                    {
                        foreach (var item in Receivers1)
                        {
                            DeviceId = DB.QuerySql <string>("select device_id from device_data where user_id = @UserId and user_active = 1", new { UserId = item }).FirstOrDefault();
                            if (DeviceId != null)
                            {
                                await SMSNotification.PushNotificationAsync(DeviceId, "Kharban", model.subject + Environment.NewLine + model.text, "Home", 1);
                            }
                        }
                    }
                }
                if (model.customer_id != string.Empty)
                {
                    DeviceId = DB.QuerySql <string>("select device_id from device_data where user_id = @UserId and user_active = 1", new { UserId = model.customer_id }).FirstOrDefault();
                    if (DeviceId != null)
                    {
                        await SMSNotification.PushNotificationAsync(DeviceId, "Kharban", model.subject + Environment.NewLine + model.text, "Home", 1);
                    }
                }

                if (model.provider_id != string.Empty)
                {
                    DeviceId = DB.QuerySql <string>("select device_id from device_data where user_id = @UserId and user_active = 1", new { UserId = model.provider_id }).FirstOrDefault();
                    if (DeviceId != null)
                    {
                        await SMSNotification.PushNotificationAsync(DeviceId, "Kharban", model.subject + Environment.NewLine + model.text, "Home", 1);
                    }
                }
            }


            returnModel.status  = (int)EnumClass.ResponseState.Success;
            returnModel.success = true;

            return(returnModel);
        }
Beispiel #2
0
        public Response<ProviderModel> ApproveRetailer(ProviderModel model)
        {
            string ReturnLink = string.Empty;
            var phone = string.Empty;
            Response<ProviderModel> returnModel = new Response<ProviderModel>();
            try
            {
                    
                using (SqlConnection DB = new SqlConnection(SiteKey.ConnectionString))
                {
                    DB.ExecuteSql(@"update provider set admin_approve = @admin_approve where id = @id ", new
                    {
                        id = model.id,
                        admin_approve = model.admin_approve,
                    });

                    phone =  DB.QuerySql<string>(@"Select country_code + contact_no as phone, admin_approve from provider where id= @id", new
                    {
                        id = model.id

                    }).FirstOrDefault();
                }
                returnModel.status = (int)EnumClass.ResponseState.Success;
                returnModel.msg = Resource_Kharban.UpdateSuccessfully;
                returnModel.success = true;

                if(!string.IsNullOrEmpty(phone))
                {

                    if (model.admin_approve == 1)
                    {
                        sendSMS("Kharban", $"{model.country_code}{model.contact_no}", "Your account is approved, You can login now");
                    }
                    else
                    {
                        sendSMS("Kharban", $"{model.country_code}{model.contact_no}", "Your account is rejected.");
                    }
                }
                string DeviceId = string.Empty;
                using (SqlConnection DB = new SqlConnection(SiteKey.ConnectionString))
                {
                    DeviceId = DB.QuerySql<string>("select device_id from device_data where user_id = @UserId and user_active = 1", new { UserId = model.id }).FirstOrDefault();
                    if (model.admin_approve == 1)
                    {
                        var notification = "Congratulations! Your account has been approved by the admin, you can now access the complete features of Kharban.";
                        SMSNotification.PushNotificationAsync(DeviceId, "Kharban", notification, "Home", 1);
                    }
                    else
                    {
                        var notification = "We are sorry, we can not approve your account at the moment, for any query please contact the admin.";
                        SMSNotification.PushNotificationAsync(DeviceId, "Kharban", notification, "Home", 1);
                    }
                }

            }
            catch (Exception ex)
            {
                returnModel.msg = ex.Message;
                returnModel.status = (int)EnumClass.ResponseState.ResposityError;
                LoggingRepository.SaveException(ex);
            }
            return returnModel;
        }