Пример #1
0
        public async void sendMail(string text)
        {
            IsBusy = true;
            var apiKey = Constants.sendgridApiKey;
            var client = new SendGridClient(apiKey);

            var msg = new SendGridMessage()
            {
                From             = new EmailAddress("*****@*****.**", "EnquiryMessenger"),
                Subject          = product != null ? "Enquiry about " + product.FullName : "Email from customer",
                PlainTextContent = "Write enquiry...!",
                HtmlContent      = "<p>" + text + "</p>"
            };

            msg.AddTo(new EmailAddress("*****@*****.**", "Hristo"));
            try {
                var response = await client.SendEmailAsync(msg);

                view.notify("response", response);
            }
            catch (HttpRequestException e)
            {
                view.notify("Error", "Error occured while sending enquiry. Check internet connection.");
            }
            catch (Exception ex)
            {
                view.notify("Error", "Unexpected error:" + Environment.NewLine + ex.Message);
            }
            finally
            {
                IsBusy = false;
            }
        }
Пример #2
0
        //Requests the products from the product manager.
        public async void requestProducts()
        {
            //Check if there is internet connection
            if (Connectivity.NetworkAccess == NetworkAccess.Internet)
            {
                NoInternetConnection = false;
                IsLoading            = true;
                string productListString = await manager.requestProductsAsync();

                IsLoading = false;

                if (productListString.Contains("Error:"))
                {
                    notifyView.notify("Error", productListString.Substring(6));
                    return;
                }

                //Set the sorted ProductList variable to a sorted product list so that the favorites come on top.
                ProductList = SortProductList(JsonConvert.DeserializeObject <ProductList>(productListString));
            }
            else
            {
                NoInternetConnection = true;
            }
        }
Пример #3
0
 private void FavoritesCommandCalled()
 {
     //Check if product is in favorites...
     if (Settings.ProductIsFavorite(product))
     {
         Settings.RemoveProductFromFavorites(product); //Remove it if it is
         FavoriteLabelText = markLabel;
         view.notify("unfavorited");
     }
     else
     {
         Settings.AddToFavorites(product); //Add it if it isnt
         FavoriteLabelText = removeLabel;
         view.notify("favorited");
     }
 }
        private async void GetEmployeeID()
        {
            if (!HasInternetConnection())
            {
                NoInternetAlert();
                return;
            }

            int newID = await manager.GetEmpID(employeeName);

            if (empID != -1)//This will be executed if there are still pending requests after the Employee id has already been set...
            {
                if (IDtimer != null)
                {
                    IDtimer.Dispose();
                }
                return;
            }
            //Check if the requested ID does not contain an error response.
            if (newID == -200 || newID == -12)
            {
                view.notify("id error");

                Task.Factory.StartNew(() =>
                {
                    if (IDtimer != null) //Destroy the timer if it already exists.
                    {
                        IDtimer.Dispose();
                    }
                    //Make the system check for new messages every 3 seconds.
                    var startTimeSpan  = TimeSpan.Zero;
                    var periodTimeSpan = TimeSpan.FromSeconds(3);
                    IDtimer            = new Timer((e) =>
                    {
                        GetEmployeeID();
                    }, null, startTimeSpan, periodTimeSpan);
                });
            }
            else
            {
                //The request for employee ID was successful.
                empID = newID;
                if (IDtimer != null)
                {
                    IDtimer.Dispose();
                }
                PageTitle = internetAcessTitle;
                StartUpdatingChatList();
            }
        }
Пример #5
0
 //Stops the update requests and alerts the user for no internet services enabled
 private void NoInternetAlert()
 {
     StopUpdateRequests();
     BackgroundColor = noInternetColor;
     view.notify("no internet");
 }
Пример #6
0
        private async void setSession(int sessionID)
        {
            if (Connectivity.NetworkAccess != NetworkAccess.Internet)
            {
                NoInternetAlert();
                return;
            }
            string chatString = await manager.GetSessionInfo(sessionID);

            if (chatString.Contains("Error"))
            {
                if (chatString.Contains("Error"))
                {
                    view.notify("session error", chatString.Substring(6));
                    setSession(sessionID);
                    return;
                }
            }
            this.chat     = JsonConvert.DeserializeObject <Session>(chatString);
            lastMessageID = chat.GetLatestCustomerMessageID();
            if (chat.MessageList != null)
            {
                foreach (Message m in chat.MessageList)
                {
                    //Add all previous messages to the chat page.
                    Messages.Add(new TextChatViewModel()
                    {
                        Text = m.Text, Direction = m.IsEmployee ? TextChatViewModel.ChatDirection.Outgoing : TextChatViewModel.ChatDirection.Incoming
                    });
                }

                view.notify("new messages");
            }
            StartUpdateRequests();
        }