Ejemplo n.º 1
0
        public ActionResult Edit(WorkDoneAttachmentView workDoneAttachmentView, IEnumerable <HttpPostedFileBase> files)
        {
            if (ModelState.IsValid)
            {
                string sessionToken = Audit.GenerateNewSessionToken();

                int workDoneFK = (int)workDoneAttachmentView.WorkDoneFK;

                foreach (var file in files)
                {
                    if (file != null && file.ContentLength > 0)
                    {
                        // save attachment to local drive
                        string originalFileName = Path.GetFileName(file.FileName);
                        string fileExtension    = Path.GetExtension(originalFileName);
                        string newFileName      = System.Guid.NewGuid().ToString();

                        var path = Path.Combine(Path.GetDirectoryName(Server.MapPath("~")) + "\\Attachments", newFileName + fileExtension);

                        file.SaveAs(path);

                        // save attachment to database
                        IAttachmentsRepository attachmentsRepository = new AttachmentsRepository(db);

                        Attachment attachment = new Attachment();

                        attachment.Name        = originalFileName;
                        attachment.Filename    = newFileName;
                        attachment.Extension   = fileExtension;
                        attachment.ContentType = "text/plain";

                        attachmentsRepository.Add(attachment);
                        attachmentsRepository.SaveChanges(sessionToken);

                        int attachmentFK = attachment.AttachmentPK;

                        // save attachment to work done attachments
                        IWorkDoneAttachmentsRepository workDoneAttachmentsRepository = new WorkDoneAttachmentsRepository(db);

                        WorkDoneAttachment workDoneAttachment = new WorkDoneAttachment();

                        workDoneAttachment.AttachmentFK = attachmentFK;
                        workDoneAttachment.WorkDoneFK   = workDoneFK;

                        workDoneAttachmentsRepository.Add(workDoneAttachment);
                        workDoneAttachmentsRepository.SaveChanges(sessionToken);
                    }
                }

                return(RedirectToAction("Index", "WorkDoneAttachment"));
            }
            else
            {
                //WorkDones ddl
                IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db);
                workDoneAttachmentView.WorkDones = new SelectList(workDonesRepository.GetValid().OrderBy("Description ASC").ToList(), "WorkDonePK", "Description");

                return(View(workDoneAttachmentView));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Index()
        {
            IWorkDoneAttachmentsRepository workDoneAttachmentsRepository = new WorkDoneAttachmentsRepository(db);
            IAttachmentsRepository         attachmentsRepository         = new AttachmentsRepository(db);
            IWorkDonesRepository           workDonesRepository           = new WorkDonesRepository(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"] : "WorkDoneAttachmentPK";
            string ordering   = sortColumn + " " + sortOrder;

            ordering = ordering.Trim();

            IQueryable <WorkDoneAttachmentView> workDoneAttachments = WorkDoneAttachmentView.GetWorkDoneAttachmentView(workDoneAttachmentsRepository.GetValid(), attachmentsRepository.GetValid(), workDonesRepository.GetValid())
                                                                      .OrderBy(ordering);

            //WorkDones ddl
            ViewBag.WorkDones = new SelectList(workDonesRepository.GetValid().OrderBy("comment").ToList(), "WorkDonePK", "Description", Request.QueryString["workDoneFK"]);

            if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"]))
            {
                string searchString = Request.QueryString["searchString"].ToString();
                workDoneAttachments = workDoneAttachments.Where(c => c.AttachmentName.Contains(searchString));
            }

            if (!String.IsNullOrWhiteSpace(Request.QueryString["workDoneFK"]))
            {
                int workDoneFK = Convert.ToInt32(Request.QueryString["workDoneFK"]);
                workDoneAttachments = workDoneAttachments.Where(c => c.WorkDoneFK == workDoneFK);
            }

            workDoneAttachments = workDoneAttachments.Page(page, pageSize);

            if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"]))
            {
                string searchString = Request.QueryString["searchString"].ToString();
                ViewData["numberOfRecords"] = workDoneAttachments.Where(c => c.AttachmentName.Contains(searchString)).Count();
            }
            else
            {
                ViewData["numberOfRecords"] = workDoneAttachments.Count();
            }

            int numberOfPages = ((int)ViewData["numberOfRecords"] + pageSize - 1) / pageSize;

            if (page > numberOfPages)
            {
                string url = LinkHelper.getQueryStringArray(new string[] { "page" });
                return(Redirect("WorkDoneAttachment?" + url + "page=" + numberOfPages));
            }
            else
            {
                return(View("Index", workDoneAttachments.ToList()));
            }
        }
Ejemplo n.º 3
0
        public ActionResult Add(int?workDoneFK)
        {
            WorkDoneAttachmentView workDoneAttachmentView = new WorkDoneAttachmentView();

            //WorkDones ddl
            IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db);

            workDoneAttachmentView.WorkDones = new SelectList(workDonesRepository.GetValid().OrderBy("Description ASC").ToList(), "WorkDonePK", "Description");

            if (workDoneFK != null)
            {
                workDoneAttachmentView.WorkDoneFK = workDoneFK;
            }

            return(View(workDoneAttachmentView));
        }
Ejemplo n.º 4
0
        public ActionResult Edit(int?workDoneAttachmentPK)
        {
            if (workDoneAttachmentPK != null)
            {
                IWorkDoneAttachmentsRepository workDoneAttachmentsRepository = new WorkDoneAttachmentsRepository(db);
                WorkDoneAttachment             workDoneAttachment            = workDoneAttachmentsRepository.GetWorkDoneAttachmentByPK((int)workDoneAttachmentPK);
                WorkDoneAttachmentView         workDoneAttachmentView        = new WorkDoneAttachmentView();

                workDoneAttachmentView.ConvertFrom(workDoneAttachment, workDoneAttachmentView);

                //WorkDones ddl
                IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db);
                workDoneAttachmentView.WorkDones = new SelectList(workDonesRepository.GetValid().OrderBy("Description ASC").ToList(), "WorkDonePK", "Description");

                return(View(workDoneAttachmentView));
            }
            else
            {
                return(RedirectToAction("Index", "WorkDoneAttachment"));
            }
        }
Ejemplo n.º 5
0
        public ActionResult Index()
        {
            IToDoListsRepository toDoListsRepository = new ToDoListsRepository(db);
            IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db);
            IUsersRepository     usersRepository     = new UsersRepository(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"] : "ASC";
            string sortColumn = !String.IsNullOrWhiteSpace(Request.QueryString["sortColumn"]) ? Request.QueryString["sortColumn"] : "Deadline";
            string ordering   = sortColumn + " " + sortOrder;

            ordering = ordering.Trim();

            IQueryable <ToDoListView> toDoLists = ToDoListView.GetToDoListView(toDoListsRepository.GetValid(), workDonesRepository.GetValid(), usersRepository.GetValid())
                                                  .OrderBy(ordering);

            string status = "obligations";

            if (!String.IsNullOrWhiteSpace(Request.QueryString["Status"]))
            {
                status = Request.QueryString["Status"];
            }

            ViewBag.dateFrom = Request.QueryString["dateFrom"] != null ? Request.QueryString["dateFrom"] : DateTime.Now.AddDays(-30).ToString("dd.MM.yyyy.");
            ViewBag.dateTo   = Request.QueryString["dateTo"] != null ? Request.QueryString["dateTo"] : DateTime.Now.AddDays(30).ToString("dd.MM.yyyy.");

            ViewBag.FinishedStatuses = new SelectList(GeneratorView.GenerateFinishedStauses(), "Value", "Text", status);

            if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"]))
            {
                string searchString = Request.QueryString["searchString"].ToString();
                toDoLists = toDoLists.Where(c => c.Name.Contains(searchString));
            }

            if (status == "obligations")
            {
                toDoLists = toDoLists.Where(c => c.Finished == false || c.Finished == null);
            }
            else
            {
                if (status == "finished")
                {
                    toDoLists = toDoLists.Where(c => c.Finished == true);
                }

                if (Request.QueryString["dateFrom"] != "")
                {
                    DateTime dateFromDate = new DateTime();
                    dateFromDate = DateTime.ParseExact(ViewBag.dateFrom, "dd.MM.yyyy.", null);
                    toDoLists    = toDoLists.Where(c => c.Deadline >= dateFromDate);
                }

                if (Request.QueryString["dateTo"] != "")
                {
                    DateTime dateToDate = new DateTime();
                    dateToDate = DateTime.ParseExact(ViewBag.dateTo, "dd.MM.yyyy.", null);
                    toDoLists  = toDoLists.Where(c => c.Deadline <= dateToDate);
                }
            }

            toDoLists = toDoLists.Page(page, pageSize);

            ViewData["numberOfRecords"] = toDoLists.Count();

            int numberOfPages = ((int)ViewData["numberOfRecords"] + pageSize - 1) / pageSize;

            if (page > numberOfPages)
            {
                string url = LinkHelper.getQueryStringArray(new string[] { "page" });
                return(Redirect("ToDoList?" + url + "page=" + numberOfPages));
            }
            else
            {
                return(View("Index", toDoLists.ToList()));
            }
        }
Ejemplo n.º 6
0
        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()));
            }
        }
Ejemplo n.º 7
0
        public ActionResult Edit(int?workDonePK)
        {
            if (workDonePK != null)
            {
                IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db);
                WorkDone             workDone            = workDonesRepository.GetWorkDoneByPK((int)workDonePK);
                WorkDoneView         workDoneView        = new WorkDoneView();

                workDoneView.ConvertFrom(workDone, workDoneView);

                IWorkDoneAttachmentsRepository      workDoneAttachmentsRepository = new WorkDoneAttachmentsRepository(db);
                IAttachmentsRepository              attachmentsRepository         = new AttachmentsRepository(db);
                IQueryable <WorkDoneAttachmentView> workDoneAttachments           = WorkDoneAttachmentView.GetWorkDoneAttachmentView(workDoneAttachmentsRepository.GetValid(), attachmentsRepository.GetValid(), workDonesRepository.GetValid())
                                                                                    .Where(c => c.WorkDoneFK == workDonePK).OrderBy("WorkDoneAttachmentPK DESC");

                ViewBag.Attachments = workDoneAttachments.ToList();

                //to do list ddl
                IToDoListsRepository toDoListsRepository = new ToDoListsRepository(db);
                workDoneView.ToDoLists = new SelectList(toDoListsRepository.GetValid().ToList(), "ToDoListPK", "Name");

                //legalEntities ddl
                ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db);
                workDoneView.LegalEntities = new SelectList(legalEntitiesRepository.GetValidLegalEntities().OrderBy("Name ASC").ToList(), "LegalEntityPK", "Name");

                //service type ddl
                IServiceTypesRepository serviceTypesRepository = new ServiceTypesRepository(db);
                workDoneView.ServiceTypes = new SelectList(serviceTypesRepository.GetValid().OrderBy("Name ASC").ToList(), "ServiceTypePK", "Name");

                //Work done ddl
                IWorkTypesRepository workTypesRepository = new WorkTypesRepository(db);
                workDoneView.WorkTypes = new SelectList(workTypesRepository.GetValid().OrderBy("Name ASC").ToList(), "WorkTypePK", "Name");

                //worksubtypes ddl
                if (workDoneView.WorkTypeFK != null)
                {
                    IWorkSubtypesRepository workSubtypesRepository = new WorkSubtypesRepository(db);
                    workDoneView.WorkSubtypes = new SelectList(workSubtypesRepository.GetValidByWorkType(Convert.ToInt32(workDoneView.WorkTypeFK)), "WorkSubtypePK", "Name", workDoneView.WorkSubtypeFK);
                }
                else
                {
                    workDoneView.WorkSubtypes = new SelectList(new List <County>(), "WorkSubtypePK", "Name");
                }

                //hours and minutes ddl
                workDoneView.Hours   = GeneratorView.GenerateHours();
                workDoneView.Minutes = GeneratorView.GenerateMinutes();

                return(View(workDoneView));
            }
            else
            {
                return(RedirectToAction("Index", "WorkDone"));
            }
        }
Ejemplo n.º 8
0
        public static IQueryable <WorkDone> GetWorkDonesReport(ObjectContext db, int?toDoListFK, int?legalEntityFK, int?workTypeFK, int?workSubtypeFK, int?serviceTypeFK, int?userFK, DateTime?dateFrom, DateTime?dateTo, int?timeSpentFrom, int?timeSpentTo, int?numberOfAttachmentsFrom, int?numberOfAttachmentsTo, string description)
        {
            IWorkDonesRepository           workDonesRepository           = new WorkDonesRepository(db);
            IWorkDoneAttachmentsRepository workDoneAttachmentsRepository = new WorkDoneAttachmentsRepository(db);

            IQueryable <WorkDone> workDonesFiltered = workDonesRepository.GetValid();

            if (toDoListFK != null)
            {
                workDonesFiltered = workDonesFiltered.GetWorkDonesByToDoList(toDoListFK);
            }

            if (workDonesFiltered.Count() > 0 && legalEntityFK != null)
            {
                workDonesFiltered = workDonesFiltered.GetWorkDoneByLegalEntity(legalEntityFK);
            }

            if (workDonesFiltered.Count() > 0 && workTypeFK != null)
            {
                workDonesFiltered = workDonesFiltered.GetWorkDoneByWorkType(workTypeFK);
            }

            if (workDonesFiltered.Count() > 0 && workSubtypeFK != null)
            {
                workDonesFiltered = workDonesFiltered.GetWorkDonesByWorkSubtype(workSubtypeFK);
            }

            if (workDonesFiltered.Count() > 0 && serviceTypeFK != null)
            {
                workDonesFiltered = workDonesFiltered.GetWorkDonesByServiceType(serviceTypeFK);
            }

            if (workDonesFiltered.Count() > 0 && userFK != null)
            {
                workDonesFiltered = workDonesFiltered.GetWorkDonesByUser(userFK);
            }

            if (workDonesFiltered.Count() > 0 && dateFrom != null)
            {
                workDonesFiltered = workDonesFiltered.GetWorkDonesByDateFrom(dateFrom);
            }

            if (workDonesFiltered.Count() > 0 && dateTo != null)
            {
                workDonesFiltered = workDonesFiltered.GetWorkDonesByDateTo(dateTo);
            }

            if (workDonesFiltered.Count() > 0 && (timeSpentFrom != null || timeSpentTo != null))
            {
                workDonesFiltered = workDonesFiltered.GetWorkDonesByTimeSpentRange(timeSpentFrom, timeSpentTo);
            }

            if (workDonesFiltered.Count() > 0 && (numberOfAttachmentsFrom != null || numberOfAttachmentsTo != null))
            {
                IQueryable <WorkDoneView> numberOfAttachmentsList = workDoneAttachmentsRepository.GetWorkDoneAttachmentCountByWorkDone(null);

                workDonesFiltered = workDonesFiltered.GetWorkDonesByNumberOfAttachmentsRange(numberOfAttachmentsList, numberOfAttachmentsFrom, numberOfAttachmentsTo);
            }

            if (workDonesFiltered.Count() > 0 && !String.IsNullOrWhiteSpace(description))
            {
                workDonesFiltered = workDonesFiltered.GetWorkDonesByDescription(description);
            }

            return(workDonesFiltered);
        }