public async Task <IActionResult> Create([Bind("IdCustomerRegion,CustomerRegionName,IdCustomerCountry")] CustomerCountryRegionVM customerCountryRegionVM)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    CustomerRegions region = new CustomerRegions();
                    region.CustomerRegionName = customerCountryRegionVM.CustomerRegionName;
                    region.IdCustomerCountry  = customerCountryRegionVM.IdCustomerCountry;

                    _context.Add(region);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            ViewData["IdCustomerCountry"] = new SelectList(_context.CustomerCountries, "IdCustomerCountry", "IdCustomerCountry");

            return(View(customerCountryRegionVM));
        }
        public async Task <IActionResult> Edit(int id, [Bind("IdCustomerRegion,CustomerRegionName,IdCustomerCountry")] CustomerRegions customerRegions)
        {
            if (id != customerRegions.IdCustomerRegion)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var region = _context.CustomerRegions.FirstOrDefault(c => c.IdCustomerRegion == customerRegions.IdCustomerRegion);
                    region.CustomerRegionName = customerRegions.CustomerRegionName;
                    _context.Update(region);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerRegionsExists(customerRegions.IdCustomerRegion))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            ViewData["IdCustomerCountry"] = new SelectList(_context.CustomerCountries, "IdCustomerCountry", "IdCustomerCountry");

            return(View(customerRegions));
        }
Ejemplo n.º 3
0
        }         // constructor

        public List <LoanStatsReportEntry> Generate()
        {
            var oResult = new List <LoanStatsReportEntry>();

            foreach (KeyValuePair <int, List <LoanStatsDataEntry> > pair in Data)
            {
                int nCustomerID = pair.Key;

                foreach (LoanStatsDataEntry lse in pair.Value)
                {
                    var lre = new LoanStatsReportEntry();
                    oResult.Add(lre);

                    lre.IsFirstLoan = lse.IsLoanIssued ? ((lse.IsFirstLoan ? "" : "not ") + "first") : "";

                    lre.ClientLoanOrderNo   = lse.LoanSeqNo;
                    lre.TypeOfLoan          = lse.ApprovedType;
                    lre.CustomerSelection   = lse.IsLoanTypeSelectionAllowed ? 1 : 0;
                    lre.DiscountPlan        = lse.DiscountPlanName;
                    lre.Offline             = lse.IsOffline ? "offline" : "online";
                    lre.LoanID              = lse.IsLoanIssued ? lse.LoanID : (int?)null;
                    lre.ClientID            = lse.CustomerID;
                    lre.ClientName          = lse.CustomerName;
                    lre.DateFirstApproved   = lse.FirstDecisionDate;
                    lre.DateLastApproved    = lse.LastDecisionDate.Date;
                    lre.NewOrOldClient      = lse.IsNewClient ? "new" : "old";
                    lre.LoanOffered         = lse.ApprovedSum;
                    lre.InterestRate        = lse.ApprovedRate;
                    lre.LoanIssued          = lse.IsLoanIssued ? lse.LoanAmount : (decimal?)null;
                    lre.IsLoanIssued        = lse.IsLoanIssued ? "yes" : "no";
                    lre.LoanIssueDate       = lse.IsLoanIssued ? lse.IssueDate : (DateTime?)null;
                    lre.LoanDuration        = lse.IsLoanIssued ? lse.LoanTerm : (int?)null;
                    lre.CreditScore         = lse.CreditScore;
                    lre.TotalAnnualTurnover = lse.AnnualTurnover;
                    lre.Medal = ((object)lse.Medal).ToString().ToLower();

                    SortedDictionary <int, int> oMarketplaceCount = CustomerMarketplaces.ContainsKey(lse.CustomerID)
                                                ? CustomerMarketplaces[lse.CustomerID].Count(lse.FirstDecisionDate)
                                                : LoanStatsMarketplaces.Count();

                    foreach (KeyValuePair <int, int> mpc in oMarketplaceCount)
                    {
                        lre.MarketplaceCount[mpc.Key] = mpc.Value;
                    }

                    lre.PaypalTotal = CustomerPaypalTotals.ContainsKey(lse.CustomerID)
                                                ? CustomerPaypalTotals[lse.CustomerID].Calculate(lse.FirstDecisionDate)
                                                : 0;

                    lre.Gender      = lse.Gender.ToString().ToLower();
                    lre.YearOfBirth = lse.BirthDate.Year;

                    switch (lse.MaritalStatus)
                    {
                    case MaritalStatus.Married:
                        lre.FamilyStatus = 1;
                        break;

                    case MaritalStatus.Single:
                        lre.FamilyStatus = 0;
                        break;

                    case MaritalStatus.Divorced:
                        lre.FamilyStatus = 2;
                        break;

                    case MaritalStatus.Widowed:
                        lre.FamilyStatus = 3;
                        break;

                    case MaritalStatus.LivingTogether:
                        lre.FamilyStatus = 4;
                        break;

                    case MaritalStatus.Separated:
                        lre.FamilyStatus = 5;
                        break;

                    case MaritalStatus.Other:
                        lre.FamilyStatus = 0;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(
                                  "MaritalStatus",
                                  (object)lse.MaritalStatus,
                                  "Unsupported marital status."
                                  );
                    }                     // switch

                    if (lse.IsHomeOwner)
                    {
                        lre.HomeOwnership = 1;
                    }
                    else
                    {
                        switch (lse.PropertyStatusDescription.ToLower())
                        {
                        case "social house":
                            lre.HomeOwnership = 3;
                            break;

                        case "renting":
                            lre.HomeOwnership = 0;
                            break;

                        case "living with parents":
                            lre.HomeOwnership = 2;
                            break;

                        default:
                            lre.HomeOwnership = null;
                            break;
                        }                         // switch
                    }

                    switch (lse.TypeOfBusiness)
                    {
                    case TypeOfBusiness.Entrepreneur:
                    case TypeOfBusiness.SoleTrader:
                        lre.TypeOfBusiness = 0;
                        break;

                    case TypeOfBusiness.LLP:
                    case TypeOfBusiness.Limited:
                        lre.TypeOfBusiness = 2;
                        break;

                    case TypeOfBusiness.PShip3P:
                    case TypeOfBusiness.PShip:
                        lre.TypeOfBusiness = 1;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }                     // switch

                    lre.SourceRef = lse.ReferenceSource;

                    lre.Category1 = "";                     // TODO
                    lre.Category2 = "";                     // TODO
                    lre.Category3 = "";                     // TODO

                    lre.Region = CustomerRegions.ContainsKey(nCustomerID) ? CustomerRegions[nCustomerID] : "";

                    lre.LastCashRequestID = lse.RequestIDHistory[lse.RequestIDHistory.Count - 1];
                }         // for each entry
            }             // for each customer

            return(oResult);
        }         // Generate