Exemple #1
0
 private void ReportValidate(TimeReportEntity report)
 {
     if (report.EndDate.Date > DateTime.Today)
     {
         throw new ValidationException("End date maximum value is today", "EndDate");
     }
     if (report.EndDate < report.StartDate)
     {
         throw new ValidationException("Start date can't be later then end date", "StartDate");
     }
     if (report.Effort <= 0)
     {
         throw new ValidationException("Effort can't be equal to zero or below zero", "Effort");
     }
     if (report.Effort > 8 * ((report.EndDate - report.StartDate).Days + 1))
     {
         throw new ValidationException("Effort can't be bigger then 8 hrs/day", "Effort");
     }
     if (report.Overtime < 0)
     {
         throw new ValidationException("Overtime can't be below zero", "Overtime");
     }
     if (report.Effort < 8 && report.Overtime > 0)
     {
         throw new ValidationException("Overtime can't be above zero if Effort is below eight", "Overtime");
     }
     //Project, Task are allways correct because of TimeReportsView. Description can be empty
 }
        public async Task <PartialViewResult> EditTimeReport(int id)
        {
            TimeReportEntity reportEntity = await unitOfWork.TimeReportRepository.GetByID(id);

            var model = new ManageTimeReportModel
            {
                Id         = reportEntity.TimeReportId,
                SpentHours = new ReportSpentHours
                {
                    Effort   = reportEntity.Effort,
                    Overtime = reportEntity.Overtime
                },
                TimeInterval = new TimeReportInterval
                {
                    StartDate = reportEntity.StartDate,
                    EndDate   = reportEntity.EndDate
                },
                ProjectId = reportEntity.Projects?.ProjectId ?? 1000,
                TaskId    = reportEntity.TaskId,
                //Tasks = unitOfWork.TaskRepository.GetAll(), //todo: проверить чтобы таски соответствовали проекту!!!!
                Tasks = allTasks.Select(taskEntity => new TaskEntity//задачи из словаря
                {
                    TaskId = taskEntity.Key,
                    Title  = taskEntity.Value,
                }),
                Projects    = await unitOfWork.ProjectRepository.GetAll(),
                Description = reportEntity.Description
            };

            return(this.PartialView("EditableTimeReportRow", model));
        }
Exemple #3
0
        public async System.Threading.Tasks.Task Update(TimeReportEntity reportWithChanges)
        {
            var reportInDb = await unitOfWork.TimeReportRepository.GetByID(reportWithChanges.TimeReportId);

            if (reportInDb == null)
            {
                throw new ValidationException("ID not found", "id");
            }
            if (reportInDb.Status != ReportStatus.Open)
            {
                throw new ValidationException("Could not edit report which is not opened", "Status");
            }
            ReportValidate(reportWithChanges);
            reportInDb.Description = reportWithChanges.Description;
            reportInDb.StartDate   = reportWithChanges.StartDate;
            reportInDb.EndDate     = reportWithChanges.EndDate;
            reportInDb.Accounts    = reportWithChanges.Accounts;
            reportInDb.Effort      = reportWithChanges.Effort;
            reportInDb.Overtime    = reportWithChanges.Overtime;
            reportInDb.ProjectId   = reportWithChanges.ProjectId;
            reportInDb.Projects    = reportWithChanges.Projects;
            reportInDb.TaskId      = reportWithChanges.TaskId;
            reportInDb.Status      = reportWithChanges.Status;
            unitOfWork.Save();
            //unitOfWork.TimeReportRepository.Update(reportWithChanges);
        }
        public RedirectToRouteResult Save(ManageTimeReportModel postModel)
        {
            TimeReportEntity newReport = new TimeReportEntity
            {
                Id          = postModel.Id,
                Effort      = postModel.SpentHours.Effort,
                Overtime    = postModel.SpentHours.Overtime,
                StartDate   = postModel.TimeInterval.StartDate,
                EndDate     = postModel.TimeInterval.EndDate,
                Status      = ReportStatus.Open,
                Task        = tasksRepository.GetById(postModel.TaskId), //todo: if PostModel.ProjectId != Task.Project.Id => Exception - таски должны соответствовать проекту
                Description = postModel.Description
            };
            var report = reportsRepository.GetById(postModel.Id);

            if (report == null)
            {
                this.reportsRepository.Add(newReport);
            }
            else
            {
                reportsRepository.Update(newReport);
            }
            return(RedirectToAction("Index"));
        }
Exemple #5
0
 public void Update(TimeReportEntity reportWithChanges)
 {
     if (_reportsRepository.GetById(reportWithChanges.Id) == null)
     {
         throw new ValidationException("ID not found", "id");
     }
     ReportValidate(reportWithChanges);
     _reportsRepository.Update(reportWithChanges);
 }
        public async Task <PartialViewResult> FilterProjectName(int id)
        {
            if (id != -1)
            { //One project
                IEnumerable <TimeReportEntity> timeReports = await unitOfWork.TimeReportRepository.GetAll();


                TimeReportEntity projectSelect = timeReports.FirstOrDefault(project => project.ProjectId == id);

                IList <TimeEffortModel> projectsModel = new List <TimeEffortModel>()
                {
                    new TimeEffortModel
                    {
                        ProjectId   = projectSelect.ProjectId,
                        ProjectName = projectSelect.Projects.Name,
                        Effort      = projectSelect.Effort,
                        Overtime    = projectSelect.Overtime,
                        Total       = projectSelect.Effort + projectSelect.Overtime
                    }
                };

                return(this.PartialView("ProjectFilters", projectsModel));
            }
            else
            { //All projects
                IEnumerable <TimeReportEntity> timeReports = await unitOfWork.TimeReportRepository.GetAll();

                foreach (var report in timeReports)
                {
                    var projectEffort = timeEfforts.FirstOrDefault(x => x.ProjectId == report.Projects?.ProjectId);

                    if (projectEffort == null)
                    {
                        //project is not exist in timeEffort list
                        timeEfforts.Add(new TimeEffortModel()
                        {
                            ProjectId   = report.ProjectId,
                            ProjectName = report.Projects?.Name ?? "Нет доступа",
                            Effort      = report.Effort,
                            Overtime    = report.Overtime,
                            Total       = report.Effort + report.Overtime
                        });
                    }
                    else
                    {
                        //project exist in timeEffort list
                        projectEffort.Effort   += report.Effort;
                        projectEffort.Overtime += report.Overtime;
                        projectEffort.Total     = projectEffort.Effort + projectEffort.Overtime;
                    }
                }

                return(this.PartialView("ProjectFilters", timeEfforts));
            }
        }
        public async Task <RedirectToRouteResult> Decline(int id)
        {
            TimeReportEntity report = await unitOfWork.TimeReportRepository.GetByID(id);

            report.Status = ReportStatus.Declined;

            unitOfWork.TimeReportRepository.Update(report);
            unitOfWork.Save();

            return(RedirectToAction("Index"));
        }
Exemple #8
0
        public void Update(TimeReportEntity reportWithChanges)
        {
            var reportToUpdate = TimeReportsStorage.First(rp => rp.Id == reportWithChanges.Id);

            reportToUpdate.Effort      = reportWithChanges.Effort;
            reportToUpdate.Overtime    = reportWithChanges.Overtime;
            reportToUpdate.StartDate   = reportWithChanges.StartDate;
            reportToUpdate.EndDate     = reportWithChanges.EndDate;
            reportToUpdate.Description = reportWithChanges.Description;
            reportToUpdate.Status      = reportWithChanges.Status;
            reportToUpdate.Task        = reportWithChanges.Task;
        }
Exemple #9
0
 public void Add(TimeReportEntity report)
 {
     if (report.Id == 0)
     {
         report.Id = _reportsRepository.GetAll().Last().Id + 1;
     }
     if (_reportsRepository.GetById(report.Id) != null)
     {
         throw new ValidationException("Duplicated ID found", "id");
     }
     ReportValidate(report);
     _reportsRepository.Add(report);
 }
Exemple #10
0
        public async System.Threading.Tasks.Task Insert(TimeReportEntity report)
        {
            var a = await unitOfWork.TimeReportRepository.GetAll();

            if (report.TimeReportId == 0)
            {
                report.TimeReportId = a.Last().TimeReportId + 1;
            }
            if (await unitOfWork.TimeReportRepository.GetByID(report.TimeReportId) != null)
            {
                throw new ValidationException("Duplicated ID found", "id");
            }
            ReportValidate(report);
            unitOfWork.TimeReportRepository.Insert(report);
        }
        public async Task <PartialViewResult> FilterProjectName(int id)
        {
            if (id != -1)
            { //One project
                IEnumerable <TimeReportEntity> allTasks = await unitOfWork.TimeReportRepository.GetAll();

                TimeReportEntity taskSelect = allTasks.FirstOrDefault(task => task.TaskId == id);

                IList <ApprovalModel> reportsModel = new List <ApprovalModel>()
                {
                    new ApprovalModel
                    {
                        Id          = taskSelect.TimeReportId,
                        Effort      = taskSelect.Effort,
                        Overtime    = taskSelect.Overtime,
                        StartDate   = taskSelect.StartDate,
                        EndDate     = taskSelect.EndDate,
                        Project     = taskSelect.Projects?.Name ?? "Нет доступа к экземпляру",
                        Task        = taskSelect.Projects?.Tasks?.FirstOrDefault(m => m.TaskId == taskSelect.TaskId)?.Title ?? "Нет доступа",
                        Status      = taskSelect.Status,
                        Description = taskSelect.Description,
                    }
                };

                return(this.PartialView("ApprovalFilters", reportsModel));
            }
            else
            { //All projects
                IEnumerable <TimeReportEntity> allTasks = await unitOfWork.TimeReportRepository.GetAll();

                IEnumerable <ApprovalModel> reportsModel = allTasks.Select(reportEntity => new ApprovalModel
                {
                    Id          = reportEntity.TimeReportId,
                    Effort      = reportEntity.Effort,
                    Overtime    = reportEntity.Overtime,
                    StartDate   = reportEntity.StartDate,
                    EndDate     = reportEntity.EndDate,
                    Project     = reportEntity.Projects?.Name ?? "Нет доступа к экземпляру",
                    Task        = reportEntity.Projects?.Tasks?.FirstOrDefault(m => m.TaskId == reportEntity.TaskId)?.Title ?? "Нет доступа",
                    Status      = reportEntity.Status,
                    Description = reportEntity.Description,
                });
                return(this.PartialView("ApprovalFilters", reportsModel));
            }
        }
        public async Task <RedirectToRouteResult> Save(ManageTimeReportModel postModel)
        {
            postModel.Projects = await unitOfWork.ProjectRepository.GetAll();

            var accounts = await unitOfWork.AccountRepository.GetAll();

            int accountId = accounts.FirstOrDefault(m => m.Login == User.Identity.Name).AccountId;

            TimeReportEntity newReport = new TimeReportEntity
            {
                TimeReportId = postModel.Id,
                ProjectId    = postModel.ProjectId,
                AccountId    = accountId,
                Effort       = postModel.SpentHours.Effort,
                Overtime     = postModel.SpentHours.Overtime,
                StartDate    = postModel.TimeInterval.StartDate,
                EndDate      = postModel.TimeInterval.EndDate,
                Status       = ReportStatus.Open,
                TaskId       = postModel.TaskId, //todo: if PostModel.ProjectId != Task.Project.Id => Exception - таски должны соответствовать проекту
                Description  = postModel.Description
            };

            var report = await unitOfWork.TimeReportRepository.GetByID(postModel.Id);

            //try
            //{
            if (report == null)
            {
                await this.reportsService.Insert(newReport);
            }
            else
            {
                await reportsService.Update(newReport);
            }
            //}
            //catch (Exception e)
            //{
            //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest, e.Message);
            //}

            //return new HttpStatusCodeResult(HttpStatusCode.OK);
            return(RedirectToAction("Index"));
        }
Exemple #13
0
 private void ReportValidate(TimeReportEntity report)
 {
     if (report.EndDate < report.StartDate)
     {
         throw new ValidationException("Start date can't be later then end date", "StartDate");
     }
     if (report.Effort <= 0)
     {
         throw new ValidationException("Effort can't be equal to zero or below zero", "Effort");
     }
     if (report.Effort > 8)
     {
         throw new ValidationException("Effort can't be bigger then '8'", "Effort");
     }
     if (report.Overtime < 0)
     {
         throw new ValidationException("Overtime can't be below zerp", "Overtime");
     }
     if (report.Effort < 8 && report.Overtime > 0)
     {
         throw new ValidationException("Overtime can't be above zero if Effort is below eight", "Overtime");
     }
     //Project, Task are allways correct because of TimeReportsView. Description can be empty
 }
        public PartialViewResult EditTimeReport(int id)
        {
            TimeReportEntity reportEntity = this.reportsRepository.GetById(id);
            var model = new ManageTimeReportModel
            {
                Id         = reportEntity.Id,
                SpentHours = new ReportSpentHours
                {
                    Effort   = reportEntity.Effort,
                    Overtime = reportEntity.Overtime
                },
                TimeInterval = new TimeReportInterval
                {
                    StartDate = reportEntity.StartDate,
                    EndDate   = reportEntity.EndDate
                },
                ProjectId   = reportEntity.Task.Project.Id,
                TaskId      = reportEntity.Task.Id,
                Tasks       = tasksRepository.GetAll(), //todo: проверить чтобы таски соответствовали проекту!!!!
                Description = reportEntity.Description
            };

            return(this.PartialView("EditableTimeReportRow", model));
        }
Exemple #15
0
 public void Add(TimeReportEntity report)
 {
     report.Id = TimeReportsStorage.Count + 1;
     TimeReportsStorage.Add(report);
 }