Esempio n. 1
0
        public ActionResult Add(int?toDoListPK)
        {
            ToDoListView toDoListView = new ToDoListView();

            if (toDoListPK != null)
            {
                IToDoListsRepository toDoListsRepository = new ToDoListsRepository(db);
                ToDoList             toDoList            = toDoListsRepository.GetToDoListByPK((int)toDoListPK);
                IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db);

                toDoList.Finished = false;

                toDoListView.ConvertFrom(toDoList, toDoListView);

                var legalEntitiesSelectedValue = workDonesRepository.GetWorkDonesCreatedWithToDo((int)toDoListPK).Select(a => a.LegalEntityFK);

                ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db);
                toDoListView.Companies = new MultiSelectList(legalEntitiesRepository.GetValidLegalEntities().OrderBy("name ASC"), "LegalEntityPK", "Name", legalEntitiesSelectedValue);
            }
            else
            {
                ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db);
                toDoListView.Companies = new MultiSelectList(legalEntitiesRepository.GetValidLegalEntities().OrderBy("name ASC"), "LegalEntityPK", "Name");
            }

            return(View(toDoListView));
        }
Esempio n. 2
0
        public ActionResult Finish(int?toDoListPK)
        {
            IToDoListsRepository toDoListsRepository = new ToDoListsRepository(db);

            if (toDoListPK != null)
            {
                ToDoList toDoList = toDoListsRepository.GetToDoListByPK((int)toDoListPK);

                toDoList.Finished = true;

                toDoListsRepository.SaveChanges();
            }

            return(Redirect(Request.UrlReferrer.AbsoluteUri));
        }
Esempio n. 3
0
        public ActionResult Delete(int?toDoListPK)
        {
            IToDoListsRepository toDoListsRepository = new ToDoListsRepository(db);

            if (toDoListPK != null)
            {
                ToDoList toDoList = toDoListsRepository.GetToDoListByPK((int)toDoListPK);

                toDoList.Deleted = true;

                toDoListsRepository.SaveChanges();

                TempData["message"] = LayoutHelper.GetMessage("DELETE", toDoList.ToDoListPK);
            }

            return(Redirect(Request.UrlReferrer.AbsoluteUri));
        }
Esempio n. 4
0
        public ActionResult Edit(ToDoListView toDoListView, FormCollection form)
        {
            if (ModelState.IsValid)
            {
                IToDoListsRepository toDoListsRepository = new ToDoListsRepository(db);
                ToDoList             toDoList            = toDoListsRepository.GetToDoListByPK((int)toDoListView.ToDoListPK);
                toDoListView.ConvertTo(toDoListView, toDoList);

                toDoListsRepository.SaveChanges();

                string[] legalEntitiesSelectedValues = new string[500];
                if (form["LegalEntityPK"] != null)
                {
                    legalEntitiesSelectedValues = ((string)form["LegalEntityPK"]).Split(',');
                }
                else
                {
                    legalEntitiesSelectedValues = null;
                }

                IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db);

                var legalEntitiesValueFromDB = workDonesRepository.GetWorkDonesCreatedWithToDo((int)toDoListView.ToDoListPK).Select(a => a.LegalEntityFK);

                if (legalEntitiesSelectedValues != null)
                {
                    // Add work dones
                    foreach (string legalEntity in legalEntitiesSelectedValues)
                    {
                        int legalEntityFK = Convert.ToInt32(legalEntity);

                        if (!legalEntitiesValueFromDB.Contains(legalEntityFK))
                        {
                            WorkDone workDone = new WorkDone();

                            workDone.ToDoListFK      = toDoList.ToDoListPK;
                            workDone.LegalEntityFK   = legalEntityFK;
                            workDone.CreatedWithToDo = true;

                            workDonesRepository.Add(workDone);
                        }
                    }

                    workDonesRepository.SaveChanges();

                    List <WorkDone> workDones = workDonesRepository.GetWorkDonesCreatedWithToDo((int)toDoListView.ToDoListPK).ToList();

                    // delete existing
                    foreach (WorkDone workDone in workDones)
                    {
                        int legalEntityFK = (int)workDone.LegalEntityFK;

                        if (!legalEntitiesSelectedValues.ToList().Contains(legalEntityFK.ToString()))
                        {
                            workDone.Deleted = true;

                            workDonesRepository.SaveChanges();
                        }
                    }
                }

                TempData["message"] = LayoutHelper.GetMessage("UPDATE", toDoList.ToDoListPK);

                return(RedirectToAction("Index", "ToDoList"));
            }
            else
            {
                IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db);

                var legalEntitiesSelectedValue = workDonesRepository.GetWorkDonesCreatedWithToDo((int)toDoListView.ToDoListPK).Select(a => a.LegalEntityFK);

                ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db);
                toDoListView.Companies = new MultiSelectList(legalEntitiesRepository.GetValidLegalEntities().OrderBy("name ASC"), "LegalEntityPK", "Name", legalEntitiesSelectedValue);

                return(View(toDoListView));
            }
        }
Esempio n. 5
0
        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"
            });
        }
Esempio n. 6
0
        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()));
        }