public ActionResult Index() { IWorkSubtypesRepository workSubtypesRepository = new WorkSubtypesRepository(db); IWorkTypesRepository workTypesRepository = new WorkTypesRepository(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"] : "WorkSubtypePK"; string ordering = sortColumn + " " + sortOrder; ordering = ordering.Trim(); IQueryable <WorkSubtypeView> workSubtypes = WorkSubtypeView.GetWorkSubtypeView(workSubtypesRepository.GetValid(), workTypesRepository.GetValid()) .OrderBy(ordering); if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"])) { string searchString = Request.QueryString["searchString"].ToString(); workSubtypes = workSubtypes.Where(c => c.Name.Contains(searchString)); } workSubtypes = workSubtypes.Page(page, pageSize); if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"])) { string searchString = Request.QueryString["searchString"].ToString(); ViewData["numberOfRecords"] = workSubtypesRepository.GetValid().Where(c => c.Name.Contains(searchString)).Count(); } else { ViewData["numberOfRecords"] = workSubtypesRepository.GetValid().Count(); } int numberOfPages = ((int)ViewData["numberOfRecords"] + pageSize - 1) / pageSize; if (page > numberOfPages) { string url = LinkHelper.getQueryStringArray(new string[] { "page" }); return(Redirect("WorkSubtype?" + url + "page=" + numberOfPages)); } else { return(View("Index", workSubtypes.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 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())); } }
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())); }