public void TestCheckIfStringIsIntegerAndPositive()
 {
     Assert.IsTrue(ServicesHelper.CheckIfInteger("3"));
 }
 public void TestIfTextIsNotEmpty()
 {
     Assert.AreEqual("coucou", ServicesHelper.CheckTextBoxText("coucou"));
 }
 public void TestCheckIfStringIsDoubleAndPositiveWhenStringIsEmpty()
 {
     Assert.IsFalse(ServicesHelper.CheckIfDouble(String.Empty));
 }
 public void TestCheckIfStringIsIntegerAndPositiveWhenStringIsEmpty()
 {
     Assert.IsFalse(ServicesHelper.CheckIfInteger(String.Empty));
 }
 public void TestConvertStringToNullableDoubleWhenStringIsEmptyAndStringIsAPercentage()
 {
     Assert.AreEqual(null, ServicesHelper.ConvertStringToNullableDouble(String.Empty, true));
 }
 public void TestConvertStringToNullableInt32()
 {
     Assert.AreEqual(3, ServicesHelper.ConvertStringToNullableInt32("3").Value);
 }
	void Start()
	{
		Singleton = this;
	}
 public void TestConvertStringToDoubleWhenStringIsNullAndStringIsPercentage()
 {
     Assert.AreEqual(0, ServicesHelper.ConvertStringToDouble(null, true));
 }
Beispiel #9
0
        public async Task <HttpResponseMessage> Image(string channelId, string conversationId, string userId, string userNonce)
        {
            // Save the request url
            RequestHelper.RequestUri = Request.RequestUri;

            ChartAttachment chartAttachment = null;

            try
            {
                var conversationData = await BotStateHelper.GetConversationDataAsync(channelId, conversationId);

                chartAttachment = conversationData.GetProperty <ChartAttachment>(userNonce);

                if (chartAttachment == null)
                {
                    throw new ArgumentException("User nounce not found");
                }

                // Get access token
                BotAuth.Models.AuthResult authResult = null;
                try
                {
                    var userData = await BotStateHelper.GetUserDataAsync(channelId, userId);

                    authResult = userData.GetProperty <BotAuth.Models.AuthResult>($"MSALAuthProvider{BotAuth.ContextConstants.AuthResultKey}");
                }
                catch
                {
                }

                if (authResult != null)
                {
                    ServicesHelper.AccessToken = authResult.AccessToken;

                    var headers = ServicesHelper.GetWorkbookSessionHeader(
                        ExcelHelper.GetSessionIdForRead(conversationData, chartAttachment.WorkbookId));

                    // Get the chart image
                    #region Graph client bug workaround
                    // Workaround for following issue:
                    // https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/107

                    // Proper call should be:
                    // var imageAsString = await ServicesHelper.GraphClient.Me.Drive.Items[chartAttachment.WorkbookId]
                    //     .Workbook.Worksheets[chartAttachment.WorksheetId]
                    //     .Charts[chartAttachment.ChartId].Image(0, 0, "fit").Request(headers).GetAsync();

                    // Get the request URL just to the chart because the image
                    // request builder is broken
                    string chartRequestUrl = ServicesHelper.GraphClient.Me.Drive.Items[chartAttachment.WorkbookId]
                                             .Workbook.Worksheets[chartAttachment.WorksheetId]
                                             .Charts[chartAttachment.ChartId].Request().RequestUrl;

                    // Append the proper image request segment
                    string chartImageRequestUrl = $"{chartRequestUrl}/image(width=0,height=0,fittingMode='fit')";

                    // Create an HTTP request message
                    var imageRequest = new HttpRequestMessage(HttpMethod.Get, chartImageRequestUrl);

                    // Add session header
                    imageRequest.Headers.Add(headers[0].Name, headers[0].Value);

                    // Add auth
                    await ServicesHelper.GraphClient.AuthenticationProvider.AuthenticateRequestAsync(imageRequest);

                    // Send request
                    var imageResponse = await ServicesHelper.GraphClient.HttpProvider.SendAsync(imageRequest);

                    if (!imageResponse.IsSuccessStatusCode)
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotFound));
                    }

                    // Parse the response for the base 64 image string
                    var imageObject   = JObject.Parse(await imageResponse.Content.ReadAsStringAsync());
                    var imageAsString = imageObject.GetValue("value").ToString();
                    #endregion

                    // Convert the image from a string to an image
                    byte[] byteBuffer = Convert.FromBase64String(imageAsString);

                    var memoryStream = new MemoryStream(byteBuffer);
                    memoryStream.Position = 0;

                    // Send the image back in the response
                    var response = Request.CreateResponse(HttpStatusCode.OK);
                    response.Headers.AcceptRanges.Add("bytes");
                    response.Content = new StreamContent(memoryStream);
                    response.Content.Headers.ContentDisposition          = new ContentDispositionHeaderValue("render");
                    response.Content.Headers.ContentDisposition.FileName = "chart.png";
                    response.Content.Headers.ContentType   = new MediaTypeHeaderValue("image/png");
                    response.Content.Headers.ContentLength = memoryStream.Length;
                    response.Headers.CacheControl          = new CacheControlHeaderValue()
                    {
                        NoCache = true, NoStore = true
                    };
                    return(response);
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.Forbidden));
                }
            }
            catch
            {
                // The user nonce was not found in user state
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
        }
Beispiel #10
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddBlazorMobileNativeServices <InteropBlazorApp.Startup>();

            ServicesHelper.ConfigureCommonServices(services);
        }
Beispiel #11
0
 private void comboBoxHomeType_SelectionChangeCommitted(object sender, EventArgs e)
 {
     _homeType = ServicesHelper.CheckTextBoxText(comboBoxHomeType.SelectedItem.ToString());
 }
Beispiel #12
0
 private void textBoxPersonalPhone_TextChanged(object sender, EventArgs e)
 {
     _personalPhone = ServicesHelper.CheckTextBoxText(textBoxPersonalPhone.Text);
 }
Beispiel #13
0
 private void textBoxComments_TextChanged(object sender, System.EventArgs e)
 {
     _comments = ServicesHelper.CheckTextBoxText(tbAddress.Text);
 }
Beispiel #14
0
 private void textBoxCity_TextChanged(object sender, System.EventArgs e)
 {
     _city = ServicesHelper.CheckTextBoxText(textBoxCity.Text);
     ChooseDisrictProvinceByCity();
 }
Beispiel #15
0
 private void textBoxMail_TextChanged(object sender, EventArgs e)
 {
     _user.Mail = ServicesHelper.CheckTextBoxText(txbMail.Text);
 }
 private void textBoxBirthPlace_TextChanged(object sender, EventArgs e)
 {
     _tempPerson.BirthPlace = ServicesHelper.CheckTextBoxText(textBoxBirthPlace.Text);
 }
Beispiel #17
0
 private void txbPhone_TextChanged(object sender, EventArgs e)
 {
     _user.Phone = ServicesHelper.CheckTextBoxText(txbPhone.Text);
 }
 public void TestConvertStringToNullableDoubleWhenStringIsEmpty()
 {
     Assert.AreEqual(null, ServicesHelper.ConvertStringToNullableDouble(String.Empty, false));
 }
Beispiel #19
0
 private void textBoxPassword_TextChanged(object sender, EventArgs e)
 {
     _user.Password = ServicesHelper.CheckTextBoxText(txbPassword.Text);
 }
 public void TestConvertStringToNullableInt32WhenStringIsEmpty()
 {
     Assert.AreEqual(null, ServicesHelper.ConvertStringToNullableInt32(String.Empty));
 }
Beispiel #21
0
 private void textBoxLastname_TextChanged(object sender, EventArgs e)
 {
     _user.LastName = ServicesHelper.CheckTextBoxText(txbLastname.Text);
 }
 public void TestCheckIfStringIsDoubleAndPositiveWhenStringIsNull()
 {
     Assert.IsFalse(ServicesHelper.CheckIfDouble(null));
 }
Beispiel #23
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool isError = false;

            try
            {
                if (_notEnoughMoney)
                {
                    if (!MessageBox.Show(MultiLanguageStrings.GetString(Ressource.VillageForm, "MoneyNotEnoughForAll.Text"), "!",
                                         MessageBoxButtons.YesNo).Equals(DialogResult.Yes))
                    {
                        return;
                    }
                }
                foreach (ListViewItem item in lvMembers.Items)
                {
                    if (!item.Checked || item == _itemTotal)
                    {
                        continue;
                    }
                    var      loan = item.Tag as Loan;
                    DateTime date = Convert.ToDateTime(item.SubItems[IdxDDate].Text);

                    VillageMember activeMember = null;

                    int index = 0;
                    foreach (VillageMember member in _village.NonDisbursedMembers)
                    {
                        int tIndex = member.ActiveLoans.IndexOf(loan);
                        if (tIndex > -1)
                        {
                            activeMember = member;
                            index        = tIndex;
                        }
                    }

                    if (loan != null)
                    {
                        loan.CompulsorySavings = ServicesProvider.GetInstance().GetSavingServices().GetSavingForLoan(loan.Id, true);
                        if (loan.Product.UseCompulsorySavings)
                        {
                            if (loan.CompulsorySavings == null)
                            {
                                string text = string.Format("The loan with the code {0} requires a compulsory savings account to be disbursed!", loan.Code);
                                MessageBox.Show(text, @"No compulsory savings", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return;
                            }
                            decimal totalAmountPercentage = 0;
                            decimal savingsBalance        = loan.CompulsorySavings.GetBalance().Value;

                            foreach (Loan assosiatedLoan in loan.CompulsorySavings.Loans)
                            {
                                if (assosiatedLoan.ContractStatus != OContractStatus.Closed &&
                                    assosiatedLoan.ContractStatus != OContractStatus.Abandoned &&
                                    assosiatedLoan.ContractStatus != OContractStatus.Postponed &&
                                    assosiatedLoan.CompulsorySavingsPercentage != null)
                                {
                                    totalAmountPercentage += (assosiatedLoan.Amount.Value * ((decimal)assosiatedLoan.CompulsorySavingsPercentage / 100));
                                }
                            }

                            if (totalAmountPercentage > savingsBalance)
                            {
                                MessageBox.Show(String.Format(
                                                    "The balance on savings account {2} of {0} is not enough to cover total loans amount percentage of {1}.\nClient name: {3}",
                                                    ServicesHelper.ConvertDecimalToString(savingsBalance),
                                                    ServicesHelper.ConvertDecimalToString(totalAmountPercentage),
                                                    loan.CompulsorySavings.Code,
                                                    item.SubItems[0].Text),
                                                @"Insufficient savings balance", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return;
                            }
                        }
                    }

                    date = DateTime.Parse(item.SubItems[2].Text);

                    loan.StartDate = date;
                    if (loan.AlignDisbursementDate.Date != DateTime.Parse(item.SubItems[3].Text).Date)
                    {
                        loan.FirstInstallmentDate  = DateTime.Parse(item.SubItems[3].Text).Date;
                        loan.AlignDisbursementDate = loan.CalculateAlignDisbursementDate(DateTime.Parse(item.SubItems[3].Text).Date);
                        if (!loan.ScheduleChangedManually)
                        {
                            loan.InstallmentList = ServicesProvider.GetInstance().GetContractServices().SimulateScheduleCreation(loan);
                            loan.CalculateStartDates();
                        }
                    }

                    if (item.SubItems[IdxPaymentMethod].Tag != null && item.SubItems[IdxPaymentMethod].Tag.ToString() == OPaymentMethods.Savings.ToString())
                    {
                        if (loan.Product.UseCompulsorySavings && loan.CompulsorySavings != null)
                        {
                            if (loan.CompulsorySavings.Status == OSavingsStatus.Active)
                            {
                                ServicesProvider.GetInstance().GetSavingServices().LoanDisbursement(loan.CompulsorySavings, loan,
                                                                                                    loan.AlignDisbursementDate, "Disbursement of the loan: " + loan.Code, User.CurrentUser, false);
                            }
                            else
                            {
                                throw new OpenCbsSavingException(OpenCbsSavingExceptionEnum.CompulsorySavingsContractIsNotActive);
                            }
                        }
                        else
                        {
                            string text = string.Format(@"The loan of client '{0}' requires a compulsory savings account!", ((VillageMember)item.Tag).Tiers.Name);
                            MessageBox.Show(text, @"No compulsory savings", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }

                    PaymentMethod method =
                        ServicesProvider.GetInstance().GetPaymentMethodServices().GetPaymentMethodByName(item.SubItems[IdxPaymentMethod].Text);
                    activeMember.ActiveLoans[index] = ServicesProvider.GetInstance().GetContractServices().Disburse(loan, date, true, false, method);
                }
            }
            catch (Exception ex)
            {
                isError = true;
                new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
            }

            if (!isError)
            {
                Close();
            }
        }
 public void TestCheckIfStringIsIntegerAndPositiveWhenStringIsNull()
 {
     Assert.IsFalse(ServicesHelper.CheckIfInteger(null));
 }
Beispiel #25
0
 private void FillList()
 {
     listMain.Items.Clear();
     ServicesHelper.GetAllOpenDentServices().ForEach(x => listMain.Items.Add(x.ServiceName));
 }
 public void TestCheckIfStringIsIntegerAndPositiveWhenResultIsNegative()
 {
     Assert.IsFalse(ServicesHelper.CheckIfInteger("-3"));
 }
        private void ShowLoanInListView(VillageMember member, Loan loan)
        {
            Person person = (Person)member.Tiers;
            ApplicationSettings dataParam = ApplicationSettings.GetInstance(string.Empty);
            int          decimalPlaces    = dataParam.InterestRateDecimalPlaces;
            ListViewItem item             = new ListViewItem(person.Name)
            {
                Tag = loan
            };

            if (loan == null || _village.EstablishmentDate == null)
            {
                return;
            }
            if (_village.Id == loan.NsgID)
            {
                item.SubItems.Add(loan.ProductName);
                item.SubItems.Add(loan.Code);
                item.SubItems.Add(MultiLanguageStrings.GetString(Ressource.ClientForm, loan.ContractStatus + ".Text"));
                item.SubItems.Add(loan.Amount.GetFormatedValue(loan.UseCents));
                item.SubItems.Add(
                    loan.CalculateActualOlb().GetFormatedValue(loan.UseCents));
                item.SubItems.Add(loan.Product.Currency.Name);
                item.SubItems.Add(Math.Round(loan.InterestRate * 100m, decimalPlaces).ToString());
                item.SubItems.Add(loan.InstallmentType.Name);
                item.SubItems.Add(loan.NbOfInstallments.ToString());

                if (loan.ContractStatus == OContractStatus.Active && loan.Disbursed == true)
                {
                    item.SubItems.Add(loan.AlignDisbursementDate.ToShortDateString());
                }
                else
                {
                    item.SubItems.Add("-");
                }

                if (loan.GetLastNonDeletedEvent() != null)
                {
                    item.SubItems.Add(loan.GetLastNonDeletedEvent().Date.ToShortDateString());
                }

                else
                {
                    item.SubItems.Add("-");
                }

                if (loan.NextInstallment != null)
                {
                    item.SubItems.Add(loan.NextInstallment.ExpectedDate.ToShortDateString());
                    item.SubItems.Add(
                        ServicesHelper.ConvertDecimalToString(loan.NextInstallment.Amount.Value));
                }
                else
                {
                    item.SubItems.Add("-");
                    item.SubItems.Add("-");
                }
                item.SubItems.Add(loan.CloseDate.ToShortDateString());
                if (member.LeftDate != null)
                {
                    item.BackColor = Color.Red;
                }
                listViewLoans.Items.Add(item);
            }
        }
 public void TestIfTextIsNotEmptyWhenTextIsEmpty()
 {
     Assert.IsNull(ServicesHelper.CheckTextBoxText(String.Empty));
 }
 private void textBoxFatherName_TextChanged(object sender, EventArgs e)
 {
     _tempPerson.FatherName = ServicesHelper.CheckTextBoxText(textBoxFatherName.Text);
 }
 public void TestIfMinLowerThanMaxWhenMaxLowerThanMin()
 {
     Assert.IsFalse(ServicesHelper.CheckIfMinLowerThanMax(9, 2));
 }
Beispiel #31
0
 void Start()
 {
     Singleton = this;
 }