public ActionResult Add(ContractView contractView) { if (ModelState.IsValid) { IContractsRepository contractsRepository = new ContractsRepository(db); Contract contract = new Contract(); contractView.ConvertTo(contractView, contract); contractsRepository.Add(contract); contractsRepository.SaveChanges(); TempData["message"] = LayoutHelper.GetMessage("INSERT", contract.ContractPK); if (TempData["legalEntityFK"] != null) { return(RedirectToAction("Index", "LegalEntity")); } else { return(RedirectToAction("Index", "Contract")); } } else { contractView.BindDDLs(contractView, db); return(View(contractView)); } }
public ActionResult Index() { IAnnexContractsRepository annexContractsRepository = new AnnexContractsRepository(db); IContractsRepository contractsRepository = new ContractsRepository(db); int page = !String.IsNullOrWhiteSpace(Request.QueryString["page"]) ? Convert.ToInt32(Request.QueryString["page"]) : 1; int pageSize = !String.IsNullOrWhiteSpace(Request.QueryString["pageSize"]) ? Convert.ToInt32(Request.QueryString["pageSize"]) : Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ResultsPerPage"]); string sortOrder = !String.IsNullOrWhiteSpace(Request.QueryString["sortOrder"]) ? Request.QueryString["sortOrder"] : "DESC"; string sortColumn = !String.IsNullOrWhiteSpace(Request.QueryString["sortColumn"]) ? Request.QueryString["sortColumn"] : "AnnexContractPK"; string ordering = sortColumn + " " + sortOrder; ordering = ordering.Trim(); IQueryable <AnnexContractView> annexContracts = AnnexContractView.GetAnnexContractView(annexContractsRepository.GetValid(), contractsRepository.GetValid()) .OrderBy(ordering); //contracts ddl ViewBag.Contracts = new SelectList(contractsRepository.GetValid().OrderBy("Name ASC").ToList(), "ContractPK", "Name", Request.QueryString["contractFK"]); if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"])) { string searchString = Request.QueryString["searchString"].ToString(); annexContracts = annexContracts.Where(c => c.Name.Contains(searchString) || c.Number.Contains(searchString)); } if (!String.IsNullOrWhiteSpace(Request.QueryString["contractFK"])) { int contractFK = Convert.ToInt32(Request.QueryString["contractFK"]); annexContracts = annexContracts.Where(c => c.ContractFK == contractFK); } annexContracts = annexContracts.Page(page, pageSize); if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"])) { string searchString = Request.QueryString["searchString"].ToString(); ViewData["numberOfRecords"] = annexContractsRepository.GetValid().Where(c => c.Name.Contains(searchString) || c.Number.Contains(searchString)).Count(); } else { ViewData["numberOfRecords"] = annexContractsRepository.GetValid().Count(); } ViewData["numberOfRecords"] = annexContractsRepository.GetValid().Count(); int numberOfPages = ((int)ViewData["numberOfRecords"] + pageSize - 1) / pageSize; if (page > numberOfPages) { string url = LinkHelper.getQueryStringArray(new string[] { "page" }); return(Redirect("AnnexContract?" + url + "page=" + numberOfPages)); } else { return(View("Index", annexContracts.ToList())); } }
public ActionResult Delete(int?contractPK) { IContractsRepository contractsRepository = new ContractsRepository(db); if (contractPK != null) { Contract contract = contractsRepository.GetContractByPK((int)contractPK); contract.Deleted = true; contractsRepository.SaveChanges(); TempData["message"] = LayoutHelper.GetMessage("DELETE", contract.ContractPK); } return(Redirect(Request.UrlReferrer.AbsoluteUri)); }
public void BindDDLs(AnnexContractView annexContractView, ObjectContext db) { //contract validities ddl IContractValiditiesRepository contractValiditiesRepository = new ContractValiditiesRepository(db); annexContractView.ContractValidities = new SelectList(contractValiditiesRepository.GetValid().OrderBy("Name ASC").ToList(), "ContractValidityPK", "Name"); //contracts ddl IContractsRepository contractsRepository = new ContractsRepository(db); annexContractView.Contracts = new SelectList(contractsRepository.GetValid().OrderBy("Name ASC").ToList(), "ContractPK", "Name"); //currencies ddl ICurrenciesRepository currenciesRepository = new CurrenciesRepository(db); annexContractView.Currencies = new SelectList(currenciesRepository.GetValid().OrderBy(c => c.Name).Select(c => new { value = c.CurrencyPK, text = c.Name + " (" + c.Sign + ")" }), "value", "text"); }
public ActionResult Index() { ILegalEntityLegalRepresentativesRepository legalEntityLegalRepresentativesRepository = new LegalEntityLegalRepresentativesRepository(db); LegalEntityLegalRepresentativeView legalEntityLegalRepresentativeView = new LegalEntityLegalRepresentativeView(); IContractsRepository contractsRepository = new ContractsRepository(db); ILegalEntityBranchesRepository legalEntityBranchesRepository = new LegalEntityBranchesRepository(db); ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db); IPhysicalEntitiesRepository physicalEntitiesRepository = new PhysicalEntitiesRepository(db); int page = !String.IsNullOrWhiteSpace(Request.QueryString["page"]) ? Convert.ToInt32(Request.QueryString["page"]) : 1; int pageSize = !String.IsNullOrWhiteSpace(Request.QueryString["pageSize"]) ? Convert.ToInt32(Request.QueryString["pageSize"]) : Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ResultsPerPage"]); string sortOrder = !String.IsNullOrWhiteSpace(Request.QueryString["sortOrder"]) ? Request.QueryString["sortOrder"] : "DESC"; string sortColumn = !String.IsNullOrWhiteSpace(Request.QueryString["sortColumn"]) ? Request.QueryString["sortColumn"] : "LegalEntityLegalRepresentativePK"; string ordering = sortColumn + " " + sortOrder; ordering = ordering.Trim(); IQueryable <LegalEntityLegalRepresentativeView> legalEntityLegalRepresentatives = LegalEntityLegalRepresentativeView.GetLegalEntityLegalRepresentativeView(legalEntityLegalRepresentativesRepository.GetValid(), legalEntitiesRepository.GetValid(), physicalEntitiesRepository.GetValid()) .OrderBy(ordering); //legalEntities ddl ViewBag.LegalEntities = new SelectList(legalEntitiesRepository.GetValidLegalEntities().OrderBy("Name ASC").ToList(), "LegalEntityPK", "Name", Request.QueryString["legalEntityFK"]); if (!String.IsNullOrWhiteSpace(Request.QueryString["legalEntityFK"])) { int legalEntityFK = Convert.ToInt32(Request.QueryString["legalEntityFK"]); legalEntityLegalRepresentatives = legalEntityLegalRepresentatives.Where(c => c.LegalEntityFK == legalEntityFK); } legalEntityLegalRepresentatives = legalEntityLegalRepresentatives.Page(page, pageSize); ViewData["numberOfRecords"] = legalEntityLegalRepresentatives.Count(); int numberOfPages = ((int)ViewData["numberOfRecords"] + pageSize - 1) / pageSize; if (page > numberOfPages) { string url = LinkHelper.getQueryStringArray(new string[] { "page" }); return(Redirect("LegalEntityLegalRepresentative?" + url + "page=" + numberOfPages)); } else { return(View("Index", legalEntityLegalRepresentatives.ToList())); } }
public ActionResult Edit(int?contractPK) { if (contractPK != null) { IContractsRepository contractsRepository = new ContractsRepository(db); Contract contract = contractsRepository.GetContractByPK((int)contractPK); ContractView contractView = new ContractView(); contractView.ConvertFrom(contract, contractView, db); contractView.BindDDLs(contractView, db); return(View(contractView)); } else { return(RedirectToAction("Index", "Contract")); } }
public void ItReturnsNotNullModel() { // Arrange AviTradeContext dbContext = new AviTradeContext(); IItemsRepository itemsRepository = new ItemsRepository(dbContext); IAirportsRepository airportsRepository = new AirportsRepository(dbContext); IAircraftsRepository aircraftsRepository = new AircraftsRepository(dbContext); IContractsRepository contractsRepository = new ContractsRepository(dbContext); ITradersRepository tradersRepository = new TradersRepository(dbContext); IPeriodsRepository periodsRepository = new PeriodsRepository(dbContext); IInvoicesRepository invoicesRepository = new InvoicesRepository(dbContext, periodsRepository); ICurrenciesRepository currenciesRepository = new CurrenciesRepository(dbContext); IOrdersRepository ordersRepository = new OrdersRepository(dbContext, contractsRepository, airportsRepository, aircraftsRepository, itemsRepository, currenciesRepository, invoicesRepository); DataServiceController controller = null; // new DataServiceController(contractsRepository, tradersRepository, ordersRepository, itemsRepository, airportsRepository, aircraftsRepository); // Act AjaxOrdersViewModel model = controller.BuildAjaxOrdersViewModel(1, 0, "1,2,3,4", DateTime.Now.AddDays(30), true, 0, 20); // Assert Assert.IsNotNull(model); }
public ActionResult Edit(ContractView contractView) { if (ModelState.IsValid) { IContractsRepository contractsRepository = new ContractsRepository(db); Contract contract = contractsRepository.GetContractByPK((int)contractView.ContractPK); contractView.ConvertTo(contractView, contract); contractsRepository.SaveChanges(); TempData["message"] = LayoutHelper.GetMessage("UPDATE", contract.ContractPK); return(RedirectToAction("Index", "Contract")); } else { contractView.BindDDLs(contractView, db); return(View(contractView)); } }
public ContractsService(ContractsRepository repository) { _repository = repository; }
public ContractsService(ContractsRepository repo) { _repo = repo; }
public ActionResult Index() { ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db); IContractsRepository contractsRepository = new ContractsRepository(db); ILegalEntityBranchesRepository legalEntityBranchesRepository = new LegalEntityBranchesRepository(db); IBanksRepository banksRepository = new BanksRepository(db); ILegalEntityBanksRepository legalEntitiesBanksRepository = new LegalEntityBanksRepository(db); ILegalEntityLegalRepresentativesRepository legalEntityLegalRepresentativesRepository = new LegalEntityLegalRepresentativesRepository(db); ILegalEntityOwnersRepository legalEntityOwnersRepository = new LegalEntityOwnersRepository(db); IAssessmentsRepository assessmentsRepository = new AssessmentsRepository(db); int page = !String.IsNullOrWhiteSpace(Request.QueryString["page"]) ? Convert.ToInt32(Request.QueryString["page"]) : 1; int pageSize = !String.IsNullOrWhiteSpace(Request.QueryString["pageSize"]) ? Convert.ToInt32(Request.QueryString["pageSize"]) : Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ResultsPerPage"]); string sortOrder = !String.IsNullOrWhiteSpace(Request.QueryString["sortOrder"]) ? Request.QueryString["sortOrder"] : "DESC"; string sortColumn = !String.IsNullOrWhiteSpace(Request.QueryString["sortColumn"]) ? Request.QueryString["sortColumn"] : "LegalEntityPK"; string ordering = sortColumn + " " + sortOrder; ordering = ordering.Trim(); IQueryable <LegalEntityView> legalEntities = LegalEntityView.GetLegalEntityView(legalEntitiesRepository.GetValid(), legalEntityBranchesRepository.GetValid(), contractsRepository.GetValid(), banksRepository.GetValid(), legalEntitiesBanksRepository.GetValid(), legalEntityLegalRepresentativesRepository.GetValid(), legalEntityOwnersRepository.GetValid(), assessmentsRepository.GetValid()) .OrderBy(ordering); if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"])) { string searchString = Request.QueryString["searchString"]; legalEntities = legalEntities.Where(c => c.Name.Contains(searchString)); } if (!String.IsNullOrWhiteSpace(Request.QueryString["company"]) && Request.QueryString["company"].Contains("true")) { legalEntities = legalEntities.Where(c => c.Company == true); } if (String.IsNullOrWhiteSpace(Request.QueryString["active"])) { legalEntities = legalEntities.Where(c => c.Active == true); } else { var active = Request.QueryString["active"].Contains("true"); legalEntities = legalEntities.Where(c => c.Active == active); } ViewData["numberOfRecords"] = legalEntities.Count(); legalEntities = legalEntities.Page(page, pageSize); int numberOfPages = ((int)ViewData["numberOfRecords"] + pageSize - 1) / pageSize; if (page > numberOfPages) { string url = LinkHelper.getQueryStringArray(new string[] { "page" }); return(Redirect("LegalEntity?" + url + "page=" + numberOfPages)); } else { return(View("Index", legalEntities.ToList())); } }
//[PITAuthorize(Roles = "add, edit, view, delete")] public ActionResult LegalEntity(int?legalEntityFK, string ShowBasicInfo, string ShowLegalEntityHistory, string ShowLegalEntityLegalRepresentatives, string ShowLegalEntityLegalRepresentativesHistory, string ShowLegalEntityBanks, string ShowLegalEntityBanksHistory, string ShowContracts, string ShowBranches, string ShowBranchesHistory, string ShowLegalEntityOwners, string ShowLegalEntityOwnersHistory) { LegalEntityView legalEntityView = new LegalEntityView(); ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db); if (legalEntityFK != null) { int legalEntityPK = (int)legalEntityFK; if (ShowBasicInfo == "on" || ShowBasicInfo == "true") { legalEntityView = LegalEntityView.GetLegalEntityReport(db, legalEntityPK); } if (ShowLegalEntityLegalRepresentatives == "on" || ShowLegalEntityLegalRepresentatives == "true") { IPhysicalEntitiesRepository physicalEntitiesRepository = new PhysicalEntitiesRepository(db); ILegalEntityLegalRepresentativesRepository legalEntityLegalRepresentativesRepository = new LegalEntityLegalRepresentativesRepository(db); IQueryable <LegalEntityLegalRepresentativeView> legalEntityLegalRepresentatives = LegalEntityLegalRepresentativeView.GetLegalEntityLegalRepresentativeView(legalEntityLegalRepresentativesRepository.GetValid(), legalEntitiesRepository.GetValidLegalEntities(), physicalEntitiesRepository.GetValid()); ViewBag.LegalEntityLegalRepresentatives = legalEntityLegalRepresentatives.Where(c => c.LegalEntityFK == legalEntityPK).ToList(); } if (ShowLegalEntityBanks == "on" || ShowLegalEntityBanks == "true") { ILegalEntityBanksRepository legalEntitiesBanksRepository = new LegalEntityBanksRepository(db); IBanksRepository banksRepository = new BanksRepository(db); IQueryable <LegalEntityBankView> legalEntitiesBanks = LegalEntityBankView.GetLegalEntityBankView(legalEntitiesBanksRepository.GetValid(), banksRepository.GetValid(), legalEntitiesRepository.GetValidLegalEntities()); ViewBag.LegalEntityBanks = legalEntitiesBanks.Where(c => c.LegalEntityFK == legalEntityPK).ToList(); } if (ShowContracts == "on" || ShowContracts == "true") { IContractsRepository contractsRepository = new ContractsRepository(db); IAnnexContractsRepository annexContractsRepository = new AnnexContractsRepository(db); IQueryable <ContractView> contracts = ContractView.GetContractsView(contractsRepository.GetValid(), annexContractsRepository.GetValid(), legalEntitiesRepository.GetValidLegalEntities()); ViewBag.Contracts = contracts.Where(c => c.LegalEntityFK == legalEntityPK).ToList(); } if (ShowBranches == "on" || ShowBranches == "true") { ILegalEntityBranchesRepository legalEntityBranchesRepository = new LegalEntityBranchesRepository(db); IQueryable <LegalEntityBranchView> legalEntityBranches = LegalEntityBranchView.GetLegalEntityBranchView(legalEntityBranchesRepository.GetValid(), legalEntitiesRepository.GetValidLegalEntities()); ViewBag.Branches = legalEntityBranches.Where(c => c.LegalEntityFK == legalEntityPK).ToList(); } // history if (ShowLegalEntityHistory == "on" || ShowLegalEntityHistory == "true") { List <LegalEntityAuditView> legalEntityHistory = LegalEntityAuditView.GetLegalEntityAuditView(db, legalEntityPK); ViewBag.legalEntityHistory = legalEntityHistory.ToList(); } if (ShowLegalEntityBanksHistory == "on" || ShowLegalEntityBanksHistory == "true") { List <List <LegalEntityBankAuditView> > legalEntityBanksHistory = LegalEntityBankAuditView.GetLegalEntityBanksAuditView(db, legalEntityPK); List <DateTime> legalEntityBanksDatesHistory = new List <DateTime>(); foreach (List <LegalEntityBankAuditView> legalEntityBank in legalEntityBanksHistory) { foreach (LegalEntityBankAuditView legalEntityBankAuditView in legalEntityBank) { if (!legalEntityBanksDatesHistory.Contains(legalEntityBankAuditView.ChangeDate.Value)) { legalEntityBanksDatesHistory.Add(legalEntityBankAuditView.ChangeDate.Value); } } } ViewBag.legalEntityBanksDatesHistory = legalEntityBanksDatesHistory.OrderBy(c => c.Date).ToList(); ViewBag.legalEntityBanksHistory = legalEntityBanksHistory; } if (ShowLegalEntityLegalRepresentativesHistory == "on" || ShowLegalEntityLegalRepresentativesHistory == "true") { List <List <LegalEntityLegalRepresentativeAuditView> > legalEntityLegalRepresentativesHistory = LegalEntityLegalRepresentativeAuditView.GetLegalEntityLegalRepresentativesAuditView(db, legalEntityPK); ViewBag.legalEntityLegalRepresentativesHistory = legalEntityLegalRepresentativesHistory; } if (ShowLegalEntityOwnersHistory == "on" || ShowLegalEntityOwnersHistory == "true") { List <List <LegalEntityOwnerAuditView> > legalEntityOwnersHistory = LegalEntityOwnerAuditView.GetLegalEntityOwnersAuditView(db, legalEntityPK); ViewBag.legalEntityOwnersHistory = legalEntityOwnersHistory; } if (ShowBranchesHistory == "on" || ShowBranchesHistory == "on") { List <List <LegalEntityBranchAuditView> > legalEntityBranchesHistory = LegalEntityBranchAuditView.GetLegalEntityBranchesAuditView(db, legalEntityPK); ViewBag.legalEntityBranchesHistory = legalEntityBranchesHistory; } } return(View(legalEntityView)); }
public ActionResult Index() { IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db); IWorkDoneAttachmentsRepository workDoneAttachmentsRepository = new WorkDoneAttachmentsRepository(db); WorkDoneView workDoneView = new WorkDoneView(); IContractsRepository contractsRepository = new ContractsRepository(db); ILegalEntityBranchesRepository legalEntityBranchesRepository = new LegalEntityBranchesRepository(db); IToDoListsRepository toDoListsRepository = new ToDoListsRepository(db); IWorkTypesRepository workTypesRepository = new WorkTypesRepository(db); IWorkSubtypesRepository workSubtypesRepository = new WorkSubtypesRepository(db); IServiceTypesRepository serviceTypesRepository = new ServiceTypesRepository(db); IUsersRepository usersRepository = new UsersRepository(db); ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db); int page = !String.IsNullOrWhiteSpace(Request.QueryString["page"]) ? Convert.ToInt32(Request.QueryString["page"]) : 1; int pageSize = !String.IsNullOrWhiteSpace(Request.QueryString["pageSize"]) ? Convert.ToInt32(Request.QueryString["pageSize"]) : Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ResultsPerPage"]); string sortOrder = !String.IsNullOrWhiteSpace(Request.QueryString["sortOrder"]) ? Request.QueryString["sortOrder"] : "DESC"; string sortColumn = !String.IsNullOrWhiteSpace(Request.QueryString["sortColumn"]) ? Request.QueryString["sortColumn"] : "WorkDonePK"; string ordering = sortColumn + " " + sortOrder; ordering = ordering.Trim(); IQueryable <WorkDoneView> workDones = WorkDoneView.GetWorkDoneView(workDonesRepository.GetValid(), toDoListsRepository.GetValid(), workDoneAttachmentsRepository.GetValid(), legalEntitiesRepository.GetValidLegalEntities(), workTypesRepository.GetValid(), workSubtypesRepository.GetValid(), serviceTypesRepository.GetValid(), usersRepository.GetValid()) .OrderBy(ordering); //grid filters ddl ViewBag.ToDoLists = new SelectList(toDoListsRepository.GetValid().OrderBy("Name ASC").ToList(), "ToDoListPK", "Name", Request.QueryString["toDoListFK"]); ViewBag.LegalEntities = new SelectList(legalEntitiesRepository.GetValidLegalEntities().OrderBy("Name ASC").OrderBy("name").ToList(), "LegalEntityPK", "Name", Request.QueryString["legalEntityFK"]); ViewBag.WorkTypes = new SelectList(workTypesRepository.GetValid().OrderBy("name").OrderBy("Name ASC").ToList(), "WorkTypePK", "Name", Request.QueryString["workTypeFK"]); if (!String.IsNullOrWhiteSpace(Request.QueryString["workTypeFK"])) { int workTypeFK = Convert.ToInt32(Request.QueryString["workTypeFK"]); ViewBag.WorkSubtypes = new SelectList(workSubtypesRepository.GetValidByWorkType(workTypeFK).OrderBy("name").ToList(), "WorkSubtypePK", "Name", Request.QueryString["workSubtypeFK"]); } else { ViewBag.WorkSubtypes = new SelectList(new List <County>(), "WorkSubtypePK", "Name"); } ViewBag.Users = new SelectList(usersRepository.GetValid().OrderBy("username").ToList(), "UserPK", "Username", Request.QueryString["userFK"]); // search construct if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"])) { string searchString = Request.QueryString["searchString"].ToString(); workDones = workDones.Where(c => c.Description.Contains(searchString) || c.Comment.Contains(searchString)); } if (!String.IsNullOrWhiteSpace(Request.QueryString["createdWithToDo"])) { bool createdWithToDo = Convert.ToBoolean(Request.QueryString["createdWithToDo"]); workDones = workDones.Where(c => c.CreatedWithToDo == createdWithToDo); } else { workDones = workDones.Where(c => c.Description != null && c.WorkTypeName != null && c.WorkSubtypeName != null && c.ServiceTypeName != null && c.TimeSpent != null); } if (!String.IsNullOrWhiteSpace(Request.QueryString["toDoListFK"])) { int toDoListFK = Convert.ToInt32(Request.QueryString["toDoListFK"]); workDones = workDones.Where(c => c.ToDoListFK == toDoListFK); } if (!String.IsNullOrWhiteSpace(Request.QueryString["legalEntityFK"])) { int legalEntityFK = Convert.ToInt32(Request.QueryString["legalEntityFK"]); workDones = workDones.Where(c => c.LegalEntityFK == legalEntityFK); } if (!String.IsNullOrWhiteSpace(Request.QueryString["workTypeFK"])) { int workTypeFK = Convert.ToInt32(Request.QueryString["workTypeFK"]); workDones = workDones.Where(c => c.WorkTypeFK == workTypeFK); } if (!String.IsNullOrWhiteSpace(Request.QueryString["workSubtypeFK"])) { int workSubtypeFK = Convert.ToInt32(Request.QueryString["workSubtypeFK"]); workDones = workDones.Where(c => c.WorkSubtypeFK == workSubtypeFK); } if (!String.IsNullOrWhiteSpace(Request.QueryString["userFK"])) { int userFK = Convert.ToInt32(Request.QueryString["userFK"]); workDones = workDones.Where(c => c.UserFK == userFK); } if (!String.IsNullOrWhiteSpace(Request.QueryString["date"])) { DateTime Date = DateTime.ParseExact(Request.QueryString["date"], "dd.MM.yyyy.", null); workDones = workDones.Where(c => c.Date == Date); } workDones = workDones.Page(page, pageSize); ViewData["numberOfRecords"] = workDones.Count(); int numberOfPages = ((int)ViewData["numberOfRecords"] + pageSize - 1) / pageSize; if (page > numberOfPages) { string url = LinkHelper.getQueryStringArray(new string[] { "page" }); return(Redirect("WorkDone?" + url + "page=" + numberOfPages)); } else { return(View("Index", workDones.ToList())); } }
private static void SetupRepositories(AviTradeContext ctx) { _contractsRepository = new ContractsRepository(ctx); _airportsRepository = new AirportsRepository(ctx); _aircraftsRepository = new AircraftsRepository(ctx); _itemsRepository = new ItemsRepository(ctx); _currenciesRepository = new CurrenciesRepository(ctx); _periodsRepository = new PeriodsRepository(ctx); _invoicesRepository = new InvoicesRepository(ctx, _periodsRepository); _ordersRepository = new OrdersRepository(ctx, _contractsRepository, _airportsRepository, _aircraftsRepository, _itemsRepository, _currenciesRepository, _invoicesRepository); _tradersRepository = new TradersRepository(ctx); }
public ActionResult Index() { IPhysicalEntitiesRepository physicalEntitiesRepository = new PhysicalEntitiesRepository(db); PhysicalEntityView physicalEntityView = new PhysicalEntityView(); IContractsRepository contractsRepository = new ContractsRepository(db); ILegalEntityBranchesRepository legalEntityBranchesRepository = new LegalEntityBranchesRepository(db); int page = !String.IsNullOrWhiteSpace(Request.QueryString["page"]) ? Convert.ToInt32(Request.QueryString["page"]) : 1; int pageSize = !String.IsNullOrWhiteSpace(Request.QueryString["pageSize"]) ? Convert.ToInt32(Request.QueryString["pageSize"]) : Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ResultsPerPage"]); string sortOrder = !String.IsNullOrWhiteSpace(Request.QueryString["sortOrder"]) ? Request.QueryString["sortOrder"] : "DESC"; string sortColumn = !String.IsNullOrWhiteSpace(Request.QueryString["sortColumn"]) ? Request.QueryString["sortColumn"] : "PhysicalEntityPK"; string ordering = sortColumn + " " + sortOrder; ordering = ordering.Trim(); IQueryable <PhysicalEntityView> physicalEntities = PhysicalEntityView.GetPhysicalEntityView(physicalEntitiesRepository.GetValid()) .OrderBy(ordering); if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"])) { string searchString = Request.QueryString["searchString"].ToString(); physicalEntities = physicalEntities.Where(c => c.Firstname.Contains(searchString) || c.Lastname.Contains(searchString) || c.OIB.Contains(searchString)); } if (!String.IsNullOrWhiteSpace(Request.QueryString["dateOfBirth"]) && String.IsNullOrWhiteSpace(Request.QueryString["dateOfBirthTo"])) { DateTime dateOfBirth = DateTime.ParseExact(Request.QueryString["dateOfBirth"], "dd.MM.yyyy.", null); int dateOfBirthMonth = dateOfBirth.Month; int dateOfBirthDay = dateOfBirth.Day; physicalEntities = physicalEntities.Where(c => c.DateOfBirth.Value.Month == dateOfBirthMonth && c.DateOfBirth.Value.Day == dateOfBirthDay); } else if (!String.IsNullOrWhiteSpace(Request.QueryString["dateOfBirth"]) && !String.IsNullOrWhiteSpace(Request.QueryString["dateOfBirthTo"])) { DateTime dateOfBirthFrom = DateTime.ParseExact(Request.QueryString["dateOfBirth"], "dd.MM.yyyy.", null); int dateOfBirthFromMonth = dateOfBirthFrom.Month; int dateOfBirthFromDay = dateOfBirthFrom.Day; DateTime dateOfBirthTo = DateTime.ParseExact(Request.QueryString["dateOfBirthTo"], "dd.MM.yyyy.", null); int dateOfBirthToMonth = dateOfBirthTo.Month; int dateOfBirthToDay = dateOfBirthTo.Day; physicalEntities = physicalEntities.Where(c => (c.DateOfBirth.Value.Month >= dateOfBirthFromMonth && c.DateOfBirth.Value.Day >= dateOfBirthFromDay) && (c.DateOfBirth.Value.Month <= dateOfBirthToMonth && c.DateOfBirth.Value.Day <= dateOfBirthToDay)); } physicalEntities = physicalEntities.Page(page, pageSize); if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"])) { string searchString = Request.QueryString["searchString"].ToString(); ViewData["numberOfRecords"] = physicalEntitiesRepository.GetValid().Where(c => c.Firstname.Contains(searchString) || c.Lastname.Contains(searchString) || c.OIB.Contains(searchString)).Count(); } else { ViewData["numberOfRecords"] = physicalEntitiesRepository.GetValid().Count(); } int numberOfPages = ((int)ViewData["numberOfRecords"] + pageSize - 1) / pageSize; if (page > numberOfPages) { string url = LinkHelper.getQueryStringArray(new string[] { "page" }); return(Redirect("PhysicalEntity?" + url + "page=" + numberOfPages)); } else { return(View("Index", physicalEntities.ToList())); } }
public ActionResult WorkDoneExportToExcel( int?toDoListFK, int?legalEntityFK, int?workTypeFK, int?workSubtypeFK, int?serviceTypeFK, int?userFK, string dateFrom, string dateTo, int?timeSpentFrom, int?timeSpentTo, int?numberOfAttachmentsFrom, int?numberOfAttachmentsTo, string description, bool ShowBasicInfo, bool ShowOrdinal, bool ShowID, bool ShowToDoList, bool ShowLegalEntity, bool ShowWorkType, bool ShowWorkSubtype, bool ShowServiceType, bool ShowDate, bool ShowUsername, bool ShowDescription, bool ShowTimeSpent, bool ShowComment, bool ShowAttachments) { IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db); IWorkDoneAttachmentsRepository workDoneAttachmentsRepository = new WorkDoneAttachmentsRepository(db); WorkDoneView workDoneView = new WorkDoneView(); IContractsRepository contractsRepository = new ContractsRepository(db); ILegalEntityBranchesRepository legalEntityBranchesRepository = new LegalEntityBranchesRepository(db); IToDoListsRepository toDoListsRepository = new ToDoListsRepository(db); ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db); IWorkTypesRepository workTypesRepository = new WorkTypesRepository(db); IWorkSubtypesRepository workSubtypesRepository = new WorkSubtypesRepository(db); IServiceTypesRepository serviceTypesRepository = new ServiceTypesRepository(db); IUsersRepository usersRepository = new UsersRepository(db); string sortOrder = !string.IsNullOrWhiteSpace(Request.QueryString["sortOrder"]) ? Request.QueryString["sortOrder"] : "DESC"; string sortColumn = !string.IsNullOrWhiteSpace(Request.QueryString["sortColumn"]) ? Request.QueryString["sortColumn"] : "WorkDonePK"; string ordering = sortColumn + " " + sortOrder; ordering = ordering.Trim(); if (legalEntityFK != null) { ViewBag.LegalEntity = legalEntitiesRepository.GetLegalEntityByPK((int)legalEntityFK).Name; } if (toDoListFK != null) { ViewBag.ToDoList = toDoListsRepository.GetToDoListByPK((int)toDoListFK).Name; } if (workTypeFK != null) { ViewBag.WorkType = workTypesRepository.GetWorkTypeByPK((int)workTypeFK).Name; } if (workSubtypeFK != null) { ViewBag.WorkSubtype = workSubtypesRepository.GetWorkSubtypeByPK((int)workSubtypeFK).Name; } if (userFK != null) { ViewBag.User = usersRepository.GetUserByUserID((int)userFK).Username; } DateTime?dateFromTime = null; DateTime?dateToTime = null; if (dateFrom != null && dateFrom != "") { dateFromTime = DateTime.ParseExact(dateFrom, "dd.MM.yyyy.", null); } if (dateTo != null && dateTo != "") { dateToTime = DateTime.ParseExact(dateTo, "dd.MM.yyyy.", null); } // Applying filters IQueryable <WorkDone> workDonesFiltered = WorkDoneView.GetWorkDonesReport(db, toDoListFK, legalEntityFK, workTypeFK, workSubtypeFK, serviceTypeFK, userFK, dateFromTime, dateToTime, timeSpentFrom, timeSpentTo, numberOfAttachmentsFrom, numberOfAttachmentsTo, description); IQueryable <WorkDoneView> workDones = WorkDoneView.GetWorkDoneView(workDonesFiltered, toDoListsRepository.GetValid(), workDoneAttachmentsRepository.GetValid(), legalEntitiesRepository.GetValidLegalEntities(), workTypesRepository.GetValid(), workSubtypesRepository.GetValid(), serviceTypesRepository.GetValid(), usersRepository.GetValid()) .OrderBy(ordering); var workDonesList = workDones.ToList(); var columns = new Dictionary <string, int>(); var ms = new MemoryStream(); using (var package = new ExcelPackage(ms)) { ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Izvršeni posao"); var columnPosition = 1; Action <bool, string> setColumnHeader = (columnVisible, columnName) => { if (columnVisible) { worksheet.Cells[1, columnPosition].Value = columnName; worksheet.Cells[1, columnPosition].Style.Font.Bold = true; columns.Add(columnName, columnPosition++); } }; setColumnHeader(ShowOrdinal, "#"); setColumnHeader(ShowID, "ID"); setColumnHeader(ShowToDoList, "Obaveza"); setColumnHeader(ShowLegalEntity, "Tvrtka"); setColumnHeader(ShowWorkType, "Vrsta rada"); setColumnHeader(ShowWorkSubtype, "Vrsta posla"); setColumnHeader(ShowServiceType, "Vrsta usluge"); setColumnHeader(ShowDate, "Datum izvršenja"); setColumnHeader(ShowUsername, "Korisnik"); setColumnHeader(ShowDescription, "Opis"); setColumnHeader(ShowTimeSpent, "Utrošeno vrijeme"); setColumnHeader(ShowComment, "Važna napomena"); setColumnHeader(ShowAttachments, "Prilozi"); Action <int, bool, string, object> setRowValue = (ri, columnVisible, columnName, value) => { if (columnVisible) { worksheet.Cells[ri, columns[columnName]].Value = value; } }; var rowIndex = 2; foreach (var item in workDonesList) { setRowValue(rowIndex, ShowOrdinal, "#", rowIndex - 1); setRowValue(rowIndex, ShowID, "ID", item.WorkDonePK); setRowValue(rowIndex, ShowToDoList, "Obaveza", item.ToDoListName); setRowValue(rowIndex, ShowLegalEntity, "Tvrtka", item.LegalEntityName); setRowValue(rowIndex, ShowWorkType, "Vrsta rada", item.WorkTypeName); setRowValue(rowIndex, ShowWorkSubtype, "Vrsta posla", item.WorkSubtypeName); setRowValue(rowIndex, ShowServiceType, "Vrsta usluge", item.ServiceTypeName); setRowValue(rowIndex, ShowDate, "Datum izvršenja", item.Date?.ToString("dd.MM.yyyy.")); setRowValue(rowIndex, ShowUsername, "Korisnik", item.UserUsername); setRowValue(rowIndex, ShowDescription, "Opis", item.Description); setRowValue(rowIndex, ShowTimeSpent, "Utrošeno vrijeme", LinkHelper.calculateTimeSpent(item.TimeSpent)); setRowValue(rowIndex, ShowComment, "Važna napomena", item.Comment); setRowValue(rowIndex, ShowAttachments, "Prilozi", item.WorkDoneAttachmentsCount); rowIndex++; } worksheet.Calculate(); worksheet.Cells.AutoFitColumns(0); package.Save(); } ms.Seek(0, SeekOrigin.Begin); return(new FileStreamResult(ms, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { FileDownloadName = $"Izvršeni posao {DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss")}.xlsx" }); }
public ActionResult WorkDone(int?toDoListFK, int?legalEntityFK, int?workTypeFK, int?workSubtypeFK, int?serviceTypeFK, int?userFK, string dateFrom, string dateTo, int?timeSpentFrom, int?timeSpentTo, int?numberOfAttachmentsFrom, int?numberOfAttachmentsTo, string description) { IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db); IWorkDoneAttachmentsRepository workDoneAttachmentsRepository = new WorkDoneAttachmentsRepository(db); WorkDoneView workDoneView = new WorkDoneView(); IContractsRepository contractsRepository = new ContractsRepository(db); ILegalEntityBranchesRepository legalEntityBranchesRepository = new LegalEntityBranchesRepository(db); IToDoListsRepository toDoListsRepository = new ToDoListsRepository(db); ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db); IWorkTypesRepository workTypesRepository = new WorkTypesRepository(db); IWorkSubtypesRepository workSubtypesRepository = new WorkSubtypesRepository(db); IServiceTypesRepository serviceTypesRepository = new ServiceTypesRepository(db); IUsersRepository usersRepository = new UsersRepository(db); string sortOrder = !string.IsNullOrWhiteSpace(Request.QueryString["sortOrder"]) ? Request.QueryString["sortOrder"] : "DESC"; string sortColumn = !string.IsNullOrWhiteSpace(Request.QueryString["sortColumn"]) ? Request.QueryString["sortColumn"] : "WorkDonePK"; string ordering = sortColumn + " " + sortOrder; ordering = ordering.Trim(); //grid filters ddl ViewBag.ToDoLists = new SelectList(toDoListsRepository.GetValid().OrderBy("Name ASC").ToList(), "ToDoListPK", "Name", toDoListFK); ViewBag.LegalEntities = new SelectList(legalEntitiesRepository.GetValidLegalEntities().OrderBy("Name ASC").ToList(), "LegalEntityPK", "Name", legalEntityFK); ViewBag.WorkTypes = new SelectList(workTypesRepository.GetValid().OrderBy("Name ASC").ToList(), "WorkTypePK", "Name", workTypeFK); ViewBag.WorkSubtypes = new SelectList(workSubtypesRepository.GetValid().OrderBy("Name ASC").ToList(), "WorkSubtypePK", "Name", workSubtypeFK); ViewBag.ServiceTypes = new SelectList(serviceTypesRepository.GetValid().OrderBy("Name ASC").ToList(), "ServiceTypePK", "Name", serviceTypeFK); ViewBag.Users = new SelectList(usersRepository.GetValid().OrderBy("Username ASC").ToList(), "UserPK", "Username", userFK); if (legalEntityFK != null) { ViewBag.LegalEntity = legalEntitiesRepository.GetLegalEntityByPK((int)legalEntityFK).Name; } if (toDoListFK != null) { ViewBag.ToDoList = toDoListsRepository.GetToDoListByPK((int)toDoListFK).Name; } if (workTypeFK != null) { ViewBag.WorkType = workTypesRepository.GetWorkTypeByPK((int)workTypeFK).Name; } if (workSubtypeFK != null) { ViewBag.WorkSubtype = workSubtypesRepository.GetWorkSubtypeByPK((int)workSubtypeFK).Name; } if (userFK != null) { ViewBag.User = usersRepository.GetUserByUserID((int)userFK).Username; } DateTime?dateFromTime = null; DateTime?dateToTime = null; if (dateFrom != null && dateFrom != "") { dateFromTime = DateTime.ParseExact(dateFrom, "dd.MM.yyyy.", null); } if (dateTo != null && dateTo != "") { dateToTime = DateTime.ParseExact(dateTo, "dd.MM.yyyy.", null); } // Applying filters IQueryable <WorkDone> workDonesFiltered = WorkDoneView.GetWorkDonesReport(db, toDoListFK, legalEntityFK, workTypeFK, workSubtypeFK, serviceTypeFK, userFK, dateFromTime, dateToTime, timeSpentFrom, timeSpentTo, numberOfAttachmentsFrom, numberOfAttachmentsTo, description); IQueryable <WorkDoneView> workDones = WorkDoneView.GetWorkDoneView(workDonesFiltered, toDoListsRepository.GetValid(), workDoneAttachmentsRepository.GetValid(), legalEntitiesRepository.GetValidLegalEntities(), workTypesRepository.GetValid(), workSubtypesRepository.GetValid(), serviceTypesRepository.GetValid(), usersRepository.GetValid()) .OrderBy(ordering); // Excluding temporary deleted items from view workDonesPKPKsToExclude = new List <int>(); // Empty session on first request if (Request.QueryString.Count == 0) { Session["workDonesPKPKsToExclude"] = null; } if (Session["workDonesPKPKsToExclude"] != null) { workDonesPKPKsToExclude = (List <int>)Session["workDonesPKPKsToExclude"]; workDones = workDones.Where(c => !workDonesPKPKsToExclude.Contains(c.WorkDonePK)); } return(View("WorkDone", workDones.ToList())); }