//const int RecordsPerPage = 10; // GET: Investment //public ActionResult Index() //{ // InvestmentSearchViewModel model = new InvestmentSearchViewModel(); // List<InvestmentViewModel> investments = InvestmentRepository.GetInvestments(); // var pageIndex = model.Page ?? 1; // model.SearchResults = investments.ToPagedList(pageIndex, RecordsPerPage); // return View(model); //} public ActionResult Index(InvestmentSearchViewModel model) { //List<InvestmentViewModel> investments = InvestmentRepository.GetInvestments(model); //var pageIndex = model.Page ?? 1; model.SearchResults = InvestmentRepository.GetInvestments(model); return(View(model)); }
public static IPagedList <InvestmentViewModel> GetInvestments(InvestmentSearchViewModel criteria) { using (var db = new ApplicationDbContext()) { var query = (from investment in db.Investments join sector in db.Statuses on investment.Sector equals sector.Value join investmentPermittedAddress in db.Addresses on investment.InvestmentPermittedAddressId equals investmentPermittedAddress.UID join formofinvestment in db.Statuses on investment.FormofInvestment equals formofinvestment.Value join investingCountry in db.Countries on investment.InvestingCountry equals investingCountry.ISO select new InvestmentViewModel { UID = investment.UID, TypeOfInvestmentValue = investment.TypeOfInvestment, InvestorName = investment.InvestorName, Citizenship = investment.Citizenship, OrganizationName = investment.OrganizationName, IncorporationPlace = investment.IncorporationPlace, BusinessType = investment.BusinessType, InvestmentPermittedAddress = investmentPermittedAddress, AmountofForeignCapital = investment.AmountofForeignCapital, PeriodforForeignCapitalBroughtin = investment.PeriodforForeignCapitalBroughtin, PeriodforForeignCapitalBroughtinType = investment.PeriodforForeignCapitalBroughtinType, TotalAmountofCapital = investment.TotalAmountofCapital, CapitalCurrency = investment.CapitalCurrency, ConstructionPeriod = investment.ConstructionPeriod, ConstructionPeriodType = investment.ConstructionPeriodType, ValidityofInvestmentPermit = investment.ValidityofInvestmentPermit, ValidityofInvestmentPermitPeriodType = investment.ValidityofInvestmentPermitPeriodType, FormofInvestment = formofinvestment.Name, CompanyNameinMyanmar = investment.CompanyNameinMyanmar, PermitNo = investment.PermitNo, PermitDate = investment.PermitDate, Sector = sector.Name, InvestingCountry = investingCountry.Name, CreatedBy = investment.CreatedBy, CreatedOn = (DateTimeOffset)investment.CreatedOn, ModifiedBy = investment.ModifiedBy, ModifiedOn = (DateTimeOffset)investment.ModifiedOn, SectorValue = sector.Value, InvestingCountryValue = investingCountry.ISO, Note = investment.Note, LandUsePremium = investment.LandUsePremium, LandUsePreminumCurrency = investment.LandUsePreminumCurrency, FinancialYearFrom = investment.FinancialYearFrom, FinancialYearTo = investment.FinancialYearTo }); if (!string.IsNullOrEmpty(criteria.TypeOfInvestment)) { query = query.Where(i => i.TypeOfInvestmentValue.Equals(criteria.TypeOfInvestment)); } if (!string.IsNullOrEmpty(criteria.Sector)) { query = query.Where(i => i.SectorValue.Equals(criteria.Sector)); } if (!string.IsNullOrEmpty(criteria.InvestingCountry)) { query = query.Where(i => i.InvestingCountryValue.Equals(criteria.InvestingCountry)); } if (!string.IsNullOrEmpty(criteria.CompanyNameinMyanmar)) { query = query.Where(i => i.CompanyNameinMyanmar.Contains(criteria.CompanyNameinMyanmar)); } if (!string.IsNullOrEmpty(criteria.InvestorName)) { query = query.Where(i => i.InvestorName.Contains(criteria.InvestorName)); } if (!string.IsNullOrEmpty(criteria.CreatedBy)) { query = query.Where(i => i.CreatedBy.Contains(criteria.CreatedBy)); } if (criteria.FinancialYearFrom > 0) { query = query.Where(i => i.FinancialYearFrom == criteria.FinancialYearFrom); } if (criteria.FinancialYearTo > 0) { query = query.Where(i => i.FinancialYearTo == criteria.FinancialYearTo); } var pageIndex = criteria.Page ?? 1; return(query.OrderBy(i => i.CompanyNameinMyanmar).ToPagedList(pageIndex, RecordsPerPage)); } }