Beispiel #1
0
        public IActionResult ResetUserTimeSheet()
        {
            TimeSheetUtil.ResetUserTimeSheet(
                this.GetService <TimeSheetService>(),
                this.GetService <UserTimeSheetStatusService>());

            return(Redirect("~/Home"));
        }
Beispiel #2
0
        public string ImportTimeSheets([FromBody] List <TimeSheet> timesheets)
        {
            List <string> result = new List <string>();

            try
            {
                var timeSheetService           = this.GetService <TimeSheetService>();
                var userTimeSheetStatusService = this.GetService <UserTimeSheetStatusService>();
                var projectService             = this.GetService <ProjectService>();
                var userService       = this.GetService <UserService>();
                var departmentService = this.GetService <DepartmentService>();

                foreach (var item in timesheets)
                {
                    try
                    {
                        var project   = projectService.Get(item.ProjectId);
                        var timeSheet = timeSheetService.Get(item.Id);

                        if (timeSheet == null)
                        {
                            timeSheet = new TimeSheet(item.ProjectId, item.UserId);
                            timeSheetService.Create(timeSheet);
                        }

                        if (timeSheet.WeekTimeSheets == null)
                        {
                            timeSheet.WeekTimeSheets = new Dictionary <string, Dictionary <int, double[]> >();
                        }

                        foreach (var week in item.WeekTimeSheets)
                        {
                            if (timeSheet.WeekTimeSheets.ContainsKey(week.Key))
                            {
                                timeSheet.WeekTimeSheets[week.Key] = week.Value;
                            }
                            else
                            {
                                timeSheet.WeekTimeSheets.Add(week.Key, week.Value);
                            }

                            //userTimeSheetStatusService.UpdateUserTimeSheet(item.UserId, week.Key, Status.Ongoing, 40);
                        }

                        timeSheetService.Update(timeSheet);

                        //更新动态数据
                        projectService.UpdateActualParts(timeSheet);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex.Message);
                    }
                }

                var projects = projectService.GetByIds(timesheets.Select(o => o.ProjectId).ToList());
                TimeSheetUtil.RefreshProjectTask(projectService, departmentService, userService, projects);
                TimeSheetUtil.UpdateProject(timeSheetService, projectService, projects);
                var items = timeSheetService.GetByIds(timesheets.Select(o => o.Id).ToList());
                TimeSheetUtil.ResetTimeSheet(projectService, timeSheetService, items);
                var userTimeSheetStatuses = userTimeSheetStatusService.GetByIds(timesheets.Select(o => o.UserId).Distinct().ToList());
                TimeSheetUtil.ResetUserTimeSheet(timeSheetService, userTimeSheetStatusService, userTimeSheetStatuses);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(ex.Message);
            }

            return("Done");
        }