public ListingPageModel <TypeItem> Get(int position, int pageSize)
        {
            ListingPageModel <TypeItem> result         = new ListingPageModel <TypeItem>();
            List <TypeItem>             lstDeviceTypes = new List <TypeItem>();

            ClaimsPrincipal principal = Request.GetRequestContext().Principal as ClaimsPrincipal;
            bool            isAdmin   = principal.IsInRole("admins");

            List <DeviceType> deviceTypes = new List <DeviceType>();

            int totalRecords;

            deviceTypes = DeviceTypesRepository.GetAll(position, pageSize, out totalRecords);

            foreach (var deviceType in deviceTypes)
            {
                lstDeviceTypes.Add(new TypeItem
                {
                    Id   = deviceType.DeviceTypeId,
                    Name = deviceType.Name
                });
            }

            result.ListItems    = lstDeviceTypes;
            result.TotalRecords = totalRecords;

            return(result);
        }
Example #2
0
        public IActionResult ListingPage(ListingPageModel listingPageModel)
        {
            ListingModel currentListing = getCurrentListing(Request.Path);

            bool   validForm         = true;
            string calculatorResults = "";

            decimal homePrice        = -1;
            decimal downPayment      = -1;
            decimal mortgageDuration = -1;
            decimal interestRate     = -1;

            decimal mortgageAmount = 0;
            decimal monthlyPayment = 0;

            try
            {
                Decimal.TryParse(System.Web.HttpUtility.HtmlEncode(Request.Form["homePrice"]), out homePrice);
                Decimal.TryParse(System.Web.HttpUtility.HtmlEncode(Request.Form["downPayment"]), out downPayment);
                Decimal.TryParse(System.Web.HttpUtility.HtmlEncode(Request.Form["mortgageDuration"]), out mortgageDuration);
                Decimal.TryParse(System.Web.HttpUtility.HtmlEncode(Request.Form["interestRate"]), out interestRate);
            }
            catch (Exception e)
            {
                homePrice        = -1;
                downPayment      = -1;
                mortgageDuration = -1;
                interestRate     = -1;
            }


            if (homePrice < 0 || downPayment < 0 || mortgageDuration < 0 || interestRate < 0)
            {
                validForm = false;
            }

            if (homePrice == 0)
            {
                validForm = false;
            }

            if (mortgageDuration == 0)
            {
                validForm = false;
            }


            if (validForm)
            {
                mortgageAmount = homePrice - downPayment;
                if (mortgageAmount > 0)
                {
                    double mortgageDurationMonths = Convert.ToDouble(mortgageDuration * 12);
                    double principal = Convert.ToDouble(mortgageAmount);
                    double intRate   = (Convert.ToDouble(interestRate) * 0.01) / 12;

                    if (intRate > 0)
                    {
                        monthlyPayment = Convert.ToDecimal(principal * (intRate * Math.Pow(1 + intRate, mortgageDurationMonths)) / (Math.Pow(1 + intRate, mortgageDurationMonths) - 1));
                    }
                    else
                    {
                        monthlyPayment = Convert.ToDecimal(principal / mortgageDurationMonths);
                    }
                    monthlyPayment = Math.Round(monthlyPayment, 2);
                }
                else
                {
                    mortgageAmount = 0;
                    monthlyPayment = 0;
                }

                ViewBag.mortgageAmount = "<div class='form-response__mortgage-size'>Mortgage Size: $" + mortgageAmount + "</div>";
                ViewBag.monthlyPayment = "<div class='form-response__monthly-payment'>Monthly Payment: $" + monthlyPayment + "/month</div>";

                calculatorResults += "Showing your estimated mortgage results: ";
            }
            else
            {
                ViewBag.mortgageAmount = "";
                ViewBag.monthlyPayment = "";

                calculatorResults += "Please make sure all required fields are filled out and all filled out fields have positive numbers.";
            }

            ViewBag.homePrice        = "<div class='form-response__home-price'>Price: $" + homePrice + "</div>";
            ViewBag.downPayment      = "<div class='form-response__down-payment'>Down Payment: $" + downPayment + "</div>";
            ViewBag.mortgageDuration = "<div class='form-response__mortgage-duration'>Mortgage Duration: " + mortgageDuration + " years</div>";
            ViewBag.interestRate     = "<div class='form-response__interest-rate'>Interest Rate: " + interestRate + "%</div>";

            ArrayList theSessionVariables = new ArrayList();

            theSessionVariables.Add("homePriceUserInput");
            theSessionVariables.Add("downPaymentUserInput");
            theSessionVariables.Add("mortgageDurationUserInput");
            theSessionVariables.Add("interestRateUserInput");

            HttpContext.Session.SetString("homePriceUserInput", Convert.ToString(homePrice));
            HttpContext.Session.SetString("downPaymentUserInput", Convert.ToString(downPayment));
            HttpContext.Session.SetString("mortgageDurationUserInput", Convert.ToString(mortgageDuration));
            HttpContext.Session.SetString("interestRateUserInput", Convert.ToString(interestRate));

            ViewBag.homePriceUserInput        = HttpContext.Session.GetString("homePriceUserInput");
            ViewBag.downPaymentUserInput      = HttpContext.Session.GetString("downPaymentUserInput");
            ViewBag.mortgageDurationUserInput = HttpContext.Session.GetString("mortgageDurationUserInput");
            ViewBag.interestRateUserInput     = HttpContext.Session.GetString("interestRateUserInput");

            ViewData["calculatorResults"] = "<div class='form-response__calculator-results'>" + calculatorResults + "</div>";


            ViewData["theListings"] = SuperPortlandListings.Program.theListings;
            ViewData["projectDate"] = SuperPortlandListings.Program.projectDate;
            return(View(currentListing));
        }