Пример #1
0
        internal static void AddUser(string username, string password)
        {
            Argon2Config config = new Argon2Config
            {
                Type       = Argon2Type.DataIndependentAddressing,
                Version    = Argon2Version.Nineteen,
                TimeCost   = 3,
                MemoryCost = 32768,
                Lanes      = 4,
                Threads    = Environment.ProcessorCount,
                Password   = Encoding.ASCII.GetBytes(password),
                Salt       = Convert.FromBase64String(Properties.Settings.Default.Salt), // >= 8 bytes if not null
                HashLength = 20                                                          // >= 4
            };
            Argon2 argon2 = new Argon2(config);
            string passwordHash;

            using (SecureArray <byte> hashA = argon2.Hash())
            {
                passwordHash = config.EncodeString(hashA.Buffer);
            }
            var userCreated = new user()
            {
                username     = username,
                passwordHash = passwordHash,
                isAdmin      = false,
                isEnabled    = false
            };

            context.users.Add(userCreated);
            context.SaveChanges();
        }
Пример #2
0
        /// <summary>
        /// Updated Scoped Property
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SavePropertyBtn_Click(object sender, RoutedEventArgs e)
        {
            var validator = Validate();

            if (validator)
            {
                MessageBoxResult result = MessageBox.Show("Are you sure you want to update this property?",
                                                          "Update Property", MessageBoxButton.YesNo);

                if (result == MessageBoxResult.Yes)
                {
                    property property = (from p in context.properties
                                         where p.property_id == property_id
                                         select p).Single();

                    property.address         = formAddress.Text;
                    property.city            = formCity.Text;
                    property.province        = formProvince.Text;
                    property.country         = formCountry.Text;
                    property.postal_code     = formPostal.Text;
                    property.number_of_units = int.Parse(formNumberOfUnits.Text);
                    property.rentable_area   = int.Parse(formRentableArea.Text);
                    property.available_space = int.Parse(formAvailableSpace.Text);

                    context.SaveChanges();

                    LoadPropertyList();
                }
                else if (result == MessageBoxResult.No)
                {
                    Hide();
                }
            }
        }
        /// <summary>
        /// Fetch selected row from Database, update Grid and DB
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UpdateBtn_Click(object sender, RoutedEventArgs e)
        {
            var validator = Validate();

            if (validator)
            {
                expense editExp = (from ex in context.expenses
                                   where ex.expense_id == this.expense.expense_id
                                   select ex).Single();

                editExp.expense_name    = formExpenseName.Text;
                editExp.expense_cost    = Double.Parse(formExpenseCost.Text);
                editExp.contractor_name = formContractorName.Text;
                editExp.expense_desc    = formExpenseDescription.Text;
                editExp.expense_type    = expTypeOp.IsChecked == true
                    ? expTypeOp.Content.ToString()
                    : expTypeAdm.Content.ToString();

                context.SaveChanges();
                MainWindow.ExpenseDataGrid.ItemsSource = context.expenses.ToList();

                MessageBoxButton mbBtn   = MessageBoxButton.OK;
                string           header  = "Update Expense";
                string           message = $"Expense id:{editExp.expense_id} has been altered.";
                MessageBoxImage  icon    = MessageBoxImage.Information;
                MessageBoxResult result  = MessageBox.Show(message, header, mbBtn, icon);

                Close();
            }
        }
Пример #4
0
        /// <summary>
        /// Saves the tenant to the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveBtn_Click(object sender, RoutedEventArgs e)
        {
            var validator = Validate();

            if (validator)
            {
                property property = (from p in context.properties
                                     where p.property_id == propertyId
                                     select p).FirstOrDefault();

                var annualRent = (double.Parse(formRent.Text)) * (double.Parse(formSquareFeet.Text));

                var unitSize       = int.Parse(formSquareFeet.Text);
                var availableSpace = property.available_space;
                var leaseStart     = DateTime.Parse(formStart.Text);
                var leaseEnd       = DateTime.Parse(formEnd.Text);
                var monthsLeft     = (leaseEnd.Month + leaseEnd.Year * 12) - (leaseStart.Month + leaseStart.Year * 12);

                if (unitSize <= availableSpace)
                {
                    //Map Text box fields to new tenant object
                    tenant tenant = new tenant
                    {
                        tenant_name        = formTenantName.Text,
                        unit_number        = int.Parse(formUnitNumber.Text),
                        unit_size_sqft     = double.Parse(formSquareFeet.Text),
                        rent_per_sf        = double.Parse(formRent.Text),
                        annual_rent        = annualRent,
                        monthly_rent       = annualRent / 12,
                        lease_start        = leaseStart,
                        lease_end          = leaseEnd,
                        months_left        = monthsLeft,
                        tenant_property_id = propertyId
                    };
                    property.available_space = availableSpace - unitSize;
                    _tenantAccess.AddNewTenant(tenant, propertyId);
                    context.SaveChanges();
                    Close();

                    MessageBoxButton mbBtn   = MessageBoxButton.OK;
                    string           header  = "Add Expense";
                    string           message = $"Tenant: {tenant.tenant_name} has been added.";
                    MessageBoxImage  icon    = MessageBoxImage.Information;
                    MessageBoxResult result  = MessageBox.Show(message, header, mbBtn, icon);
                    Clear();
                }
            }
        }
        /// <summary>
        /// This will update the details in database based on user inputs
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UpdateTenantBtn_Click(object sender, RoutedEventArgs e)
        {
            var validator = Validate();

            if (validator)
            {
                property property = (from p in context.properties
                                     where p.property_id == tenant.tenant_property_id
                                     select p).FirstOrDefault();

                var annualRent = (double.Parse(formRent.Text)) * (double.Parse(formSquareFeet.Text));

                var unitSize       = int.Parse(formSquareFeet.Text);
                var availableSpace = property.available_space;
                var leaseStart     = DateTime.Parse(formStart.Text);
                var leaseEnd       = DateTime.Parse(formEnd.Text);
                var monthsLeft     = (leaseEnd.Month + leaseEnd.Year * 12) - (leaseStart.Month + leaseStart.Year * 12);

                if (unitSize <= availableSpace)
                {
                    tenant editTenant = (from t in context.tenants
                                         where t.tenant_id == tenant.tenant_id
                                         select t).Single();

                    editTenant.tenant_name    = formTenantName.Text;
                    editTenant.unit_number    = int.Parse(formUnitNumber.Text);
                    editTenant.unit_size_sqft = unitSize;
                    editTenant.rent_per_sf    = double.Parse(formRent.Text);
                    editTenant.annual_rent    = annualRent;
                    editTenant.monthly_rent   = tenant.annual_rent / 12;
                    editTenant.lease_start    = leaseStart;
                    editTenant.lease_end      = leaseEnd;
                    editTenant.months_left    = monthsLeft;
                    property.available_space  = availableSpace - unitSize;
                    context.SaveChanges();

                    MainWindow.TenantDataGrid.ItemsSource = context.tenants.ToList();

                    MessageBoxButton mbBtn   = MessageBoxButton.OK;
                    string           header  = "Update Tenant";
                    string           message = $"Tenant name:{editTenant.tenant_name} has been altered.";
                    MessageBoxImage  icon    = MessageBoxImage.Information;
                    MessageBoxResult result  = MessageBox.Show(message, header, mbBtn, icon);
                    Close();
                }
            }
        }
Пример #6
0
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            Update_Click(sender, e);
            if (validator)
            {
                MessageBoxResult result = MessageBox.Show("Are you sure you want to save this property?",
                                                          "Update Property", MessageBoxButton.YesNo);

                if (result == MessageBoxResult.Yes)
                {
                    analysis analysis = (from a in context.analyses
                                         where a.analysis_id == analysis_id
                                         select a).First();

                    analysis.land_acquisition_price         = varlandAcquisitionCost;
                    analysis.acquisition_leasing_fee        = varAcquisitionFee;
                    analysis.acquisition_leasing_percentage = varAcquisitionLeasing;
                    analysis.syndication_fee                    = varSyndicationFee;
                    analysis.syndication_percentage             = varSyndication;
                    analysis.land_transfer_tax                  = varLandTransferTax;
                    analysis.land_transfer_percentage           = varLandTransfer;
                    analysis.legal_purchase_lease_fee           = varLegalPurchaseLease;
                    analysis.contingency_tenant_improvement_fee = varContigency;
                    analysis.environmental_fee                  = varEnvironmental;
                    analysis.construction_fee                   = varConstruction;
                    analysis.mortgage_fee                              = varMortgage;
                    analysis.bcr_fee                                   = varBCR;
                    analysis.appraisal_fee                             = varAppraisal;
                    analysis.total_closing_fees                        = varClosingFee;
                    analysis.total_acquisition_cost                    = varAcquisitionCost;
                    analysis.mortgage_ltv_cost                         = varMortgageLTVCost;
                    analysis.mortgage_ltv_percentage                   = varMortgageLTV;
                    analysis.twenty_five_year_interest_rate            = varInterest25;
                    analysis.twenty_five_year_interest_rate_percentage = varInterestRatePer;
                    analysis.annual_debt_service_twenty_five_years     = varAnnualDebt;

                    context.SaveChanges();


                    LoadPropertyList();
                }
                else if (result == MessageBoxResult.No)
                {
                    Hide();
                }
            }
        }