public OOfferMySpace InsertOfferMySpace(COfferMySpace objOffer)
        {
            DALExceptionManagment objExceptionlog = new DALExceptionManagment();
            OOfferMySpace         obj_Offer       = new OOfferMySpace();

            try
            {
                using (SqlConnection sqlconn_obj = new SqlConnection(SqlHelper.GetDBConnectionString()))
                {
                    using (SqlCommand sqlcmd_obj = new SqlCommand("CTAPP_PROC_INSERTOFFERMYSPACE", sqlconn_obj))
                    {
                        sqlcmd_obj.CommandType = CommandType.StoredProcedure;
                        sqlcmd_obj.Parameters.AddWithValue("@CustomerID", objOffer.CustomerID);
                        sqlcmd_obj.Parameters.AddWithValue("@Name", objOffer.Name);
                        sqlcmd_obj.Parameters.AddWithValue("@PhoneNumber", objOffer.PhoneNumber);
                        sqlcmd_obj.Parameters.AddWithValue("@Email", objOffer.Email);
                        sqlcmd_obj.Parameters.AddWithValue("@OtherDetails", objOffer.Other);
                        sqlconn_obj.Open();
                        SqlDataAdapter sqldap   = new SqlDataAdapter(sqlcmd_obj);
                        DataTable      resultdt = new DataTable();
                        sqldap.Fill(resultdt);
                        if (resultdt.Rows.Count > 0)
                        {
                            obj_Offer.OfferMySpaceID = Convert.ToInt32(resultdt.Rows[0]["OfferMySpaceID"]);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                objExceptionlog.InsertException(ex.Message, "DALOfferMySpace", "Proc: " + "CTAPP_PROC_INSERTOFFERMYSPACE", "InsertOfferMySpace");
                throw;
            }
            return(obj_Offer);
        }
        public OOfferMySpace InsertOfferMySpace(string accessToken, COfferMySpace objOfferMySpace)
        {
            OOfferMySpace obj_OfferMySpace = new OOfferMySpace();

            try
            {
                string baseUrl = Convert.ToString(App.Current.Properties["BaseURL"]);
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(baseUrl);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    // Add the Authorization header with the AccessToken.
                    client.DefaultRequestHeaders.Add("Authorization", "bearer  " + accessToken);
                    // create the URL string.
                    string url = "api/InstaConsumer/InsertOfferMySpace";
                    // make the request

                    var json    = JsonConvert.SerializeObject(objOfferMySpace);
                    var content = new StringContent(json, Encoding.UTF8, "application/json");
                    HttpResponseMessage response = client.PostAsync(url, content).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        string jsonString = response.Content.ReadAsStringAsync().Result;
                        if (jsonString != null)
                        {
                            APIResponse apiResult = JsonConvert.DeserializeObject <APIResponse>(jsonString);

                            if (apiResult.Result)
                            {
                                obj_OfferMySpace = JsonConvert.DeserializeObject <OOfferMySpace>(Convert.ToString(apiResult.Object));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(obj_OfferMySpace);
        }
Exemplo n.º 3
0
        private async void btn_SubmitClicked(object sender, EventArgs e)
        {
            btnSubmit.IsVisible = false;
            ShowLoading(true);

            try
            {
                IsOnline = VerifyInternet();

                if (IsOnline)
                {
                    if (App.Current.Properties.ContainsKey("CustomerID"))
                    {
                        if (Convert.ToInt32(App.Current.Properties["CustomerID"]) != 0)
                        {
                            if (txtName.Text == "" || txtName.Text == null)
                            {
                                btnSubmit.IsVisible = true;
                                ShowLoading(false);
                                DisplayAlert("", "Please enter your Name", "Ok");
                                return;
                            }

                            if (txtName.Text.Trim() == "")
                            {
                                btnSubmit.IsVisible = true;
                                ShowLoading(false);
                                DisplayAlert("", "Please enter your Name", "Ok");
                                return;
                            }

                            txtName.Text = txtName.Text.Trim();

                            if (txtName.Text.Length >= 3 && txtName.Text.Length <= 20)
                            {
                            }
                            else
                            {
                                btnSubmit.IsVisible = true;
                                ShowLoading(false);
                                DisplayAlert("", "Name must be atleast 3 characters and maximum 20 characters", "Ok");
                                return;
                            }

                            var regexName = new Regex("^[a-zA-Z ]*$");
                            if (!regexName.IsMatch(txtName.Text.Trim()))
                            {
                                btnSubmit.IsVisible = true;
                                ShowLoading(false);
                                DisplayAlert("", "Please enter only alphabets for Name", "Ok");
                                return;
                            }

                            if (txtPhoneNumber.Text == "" || txtPhoneNumber.Text == null)
                            {
                                btnSubmit.IsVisible = true;
                                ShowLoading(false);
                                DisplayAlert("", "Please enter your Phone Number", "Ok");
                                return;
                            }

                            if (txtEmail.Text == "" || txtEmail.Text == null)
                            {
                                btnSubmit.IsVisible = true;
                                ShowLoading(false);
                                DisplayAlert("", "Please enter your Email", "Ok");
                                return;
                            }

                            if (!RegexUtilities.IsEmailValid(txtEmail.Text))
                            {
                                btnSubmit.IsVisible = true;
                                ShowLoading(false);
                                DisplayAlert("", "Please enter valid Email", "Ok");
                                return;
                            }

                            if (txtOtherDetails.Text == "" || txtOtherDetails.Text == null)
                            {
                                btnSubmit.IsVisible = true;
                                ShowLoading(false);
                                DisplayAlert("", "Please enter Other Details", "Ok");
                                return;
                            }

                            if (txtOtherDetails.Text.Trim() == "")
                            {
                                btnSubmit.IsVisible = true;
                                ShowLoading(false);
                                DisplayAlert("", "Please enter Other Details", "Ok");
                                return;
                            }

                            txtOtherDetails.Text = txtOtherDetails.Text.Trim();

                            if (txtOtherDetails.Text.Length >= 10 && txtOtherDetails.Text.Length <= 200)
                            {
                            }
                            else
                            {
                                btnSubmit.IsVisible = true;
                                ShowLoading(false);
                                DisplayAlert("", "Other Details must be atleast 10 characters and maximum 200 characters", "Ok");
                                return;
                            }

                            COfferMySpace objOfferMySpace = new COfferMySpace();
                            objOfferMySpace.CustomerID  = Convert.ToInt32(App.Current.Properties["CustomerID"]);
                            objOfferMySpace.Name        = txtName.Text.Trim();
                            objOfferMySpace.Email       = txtEmail.Text.Trim();
                            objOfferMySpace.PhoneNumber = txtPhoneNumber.Text.Trim();
                            objOfferMySpace.Other       = txtOtherDetails.Text.Trim();

                            if (App.Current.Properties.ContainsKey("apitoken"))
                            {
                                var json    = JsonConvert.SerializeObject(objOfferMySpace);
                                var content = new StringContent(json, Encoding.UTF8, "application/json");

                                OOfferMySpace resultObj = new OOfferMySpace();

                                await Task.Run(() =>
                                {
                                    ShowLoading(true);
                                    resultObj = dal_Offer.InsertOfferMySpace(Convert.ToString(App.Current.Properties["apitoken"]), objOfferMySpace);
                                });

                                if (resultObj.OfferMySpaceID != 0)
                                {
                                    /*
                                     * await Task.Run(() =>
                                     * {
                                     *     SendEmail();
                                     * });
                                     */
                                    int CustomerID = 0;
                                    if (App.Current.Properties.ContainsKey("CustomerID"))
                                    {
                                        CustomerID = Convert.ToInt32(App.Current.Properties["CustomerID"]);
                                    }

                                    ShowLoading(false);
                                    await DisplayAlert("", "Your Request has been accepted. Our team will get back to you soon!", "Ok");

                                    btnSubmit.IsVisible = true;
                                    await Navigation.PushAsync(new Home(null, CustomerID));
                                }
                                else
                                {
                                    btnSubmit.IsVisible = true;
                                    ShowLoading(false);
                                    DisplayAlert("Failed - InsertOfferMySpace", "Insert Failed", "Ok");
                                }
                            }
                            else
                            {
                                btnSubmit.IsVisible = true;
                                ShowLoading(false);
                            }
                        }
                        else
                        {
                            btnSubmit.IsVisible = true;
                            ShowLoading(false);
                            DisplayAlert("", "Profile not found!", "Ok");
                        }
                    }
                    else
                    {
                        btnSubmit.IsVisible = true;
                        ShowLoading(false);
                        DisplayAlert("", "Customer Key does not exists", "Ok");
                    }
                }
                else
                {
                    await DisplayAlert("", "Please check your network connectivity", "Ok");

                    return;
                }
            }
            catch (Exception ex)
            {
                btnSubmit.IsVisible = true;
                ShowLoading(false);
            }
        }