protected override void Context()
        {
            _timeregistrationHandler = Resolve<TimeRegistrationHandlers>();
            _timeregistrationRepository = Resolve<ITimeRegistrationRepository>();
            _tenantContext = Resolve<ITenantContext>();

            _tenantContext.SetTenantId(_tenant);
        }
        protected override void Context()
        {
            _clientHandler = Resolve<ClientHandlers>();
            _projectHandler = Resolve<ProjectHandlers>();
            _timeregistrationHandler = Resolve<TimeRegistrationHandlers>();
            _timeregistrationRepository = Resolve<ITimeRegistrationRepository>();
            _tenantContext = Resolve<ITenantContext>();

            _tenantContext.SetTenantId(_tenant);
            _clientHandler.AsDynamic().Handle(new ClientCreated(_clientId, "John Doe BVBA", DateTime.UtcNow) { Version = 1 });
            _projectHandler.AsDynamic().Handle(new ProjectCreated(_projectId, "Project 1", "A test project", _clientId, DateTime.UtcNow) { Version = 1 });
        }
        public TimeRegistrationModule(ITimeRegistrationRepository timeRegistrationRepository)
            : base("/read/timeregistrations")
        {
            this.RequiresAuthentication();

            Get["/"] = _ => Json(timeRegistrationRepository.ToList());

            Get["/{id:guid}"] = parameters => Json(timeRegistrationRepository.GetById((Guid)parameters.id));

            Get["/getfordate/{date:datetime}"] = parameters => Json(timeRegistrationRepository.GetForPeriod((DateTime)parameters.date, 
                                                                                                            ((DateTime)parameters.date).AddDays(1)));

            Get["/getforperiod/{fromDate}/{toDate}"] = parameters => Json(timeRegistrationRepository.GetForPeriod((DateTime)parameters.fromDate,
                                                                                                                  ((DateTime)parameters.toDate).AddDays(1)));

            Get["/getinfo/{fromDate}/{toDate}"] = parameters =>
            {
                var items = timeRegistrationRepository.GetForPeriod((DateTime)parameters.fromDate, 
                                                                    ((DateTime)parameters.toDate).AddDays(1));

                var summary = new TimeRegistrationPeriodInfo
                {
                    Count = items.Count(),
                    Income = Math.Round(items.Sum(i => i.Minutes.HasValue ? i.CorrectedIncome != null ? i.CorrectedIncome.Value : (i.Minutes.Value * ((decimal)i.Rate / 60)) : 0), 2),
                    BillableMinutes = items.Sum(i => i.Minutes.HasValue && ((i.CorrectedIncome != null && i.CorrectedIncome.Value > 0) || i.Rate > 0) ? i.Minutes.Value : 0),
                    UnbillableMinutes = items.Sum(i => i.Minutes.HasValue && ((i.CorrectedIncome == null || i.CorrectedIncome.Value <= 0) && i.Rate <= 0) ? i.Minutes.Value : 0),
                };

                var perTask = items.GroupBy(r => new { r.ClientId, r.ClientName, r.ProjectId, r.ProjectName, r.Task })
                                   .Select(g =>
                                   {
                                        return new TimeRegistrationPeriodInfoPerTask
                                        {
                                            ClientId = g.Key.ClientId,
                                            Client = g.Key.ClientName,
                                            ProjectId = g.Key.ProjectId,
                                            Project = g.Key.ProjectName,
                                            Task = g.Key.Task,
                                            Count = g.Count(),
                                            Income = Math.Round(g.Sum(i => i.Minutes.HasValue ? i.CorrectedIncome != null ? i.CorrectedIncome.Value : (i.Minutes.Value * ((decimal)i.Rate / 60)) : 0), 2),
                                            BillableMinutes = g.Sum(i => i.Minutes.HasValue && ((i.CorrectedIncome != null && i.CorrectedIncome.Value > 0) || i.Rate > 0) ? i.Minutes.Value : 0),
                                            UnbillableMinutes = g.Sum(i => i.Minutes.HasValue && ((i.CorrectedIncome == null || i.CorrectedIncome.Value <= 0) && i.Rate <= 0) ? i.Minutes.Value : 0),
                                        };
                                   }).ToList();

                return new
                {
                    Summary = summary,
                    PerTask = perTask
                };
            };
        }
        protected override void Context()
        {
            _clientHandler = Resolve<ClientHandlers>();
            _projectHandler = Resolve<ProjectHandlers>();
            _timeregistrationHandler = Resolve<TimeRegistrationHandlers>();
            _timeregistrationRepository = Resolve<ITimeRegistrationRepository>();
            _tenantContext = Resolve<ITenantContext>();

            _tenantContext.SetTenantId(_tenant);
            _clientHandler.AsDynamic().Handle(new ClientCreated(_clientId, "John Doe BVBA", DateTime.UtcNow) { Version = 1 });
            _projectHandler.AsDynamic().Handle(new ProjectCreated(_projectId, "Project 1", "A test project", _clientId, DateTime.UtcNow) { Version = 1 });
            _timeregistrationHandler.AsDynamic().Handle(new TimeRegistrationCreated(_timeregistrationId, _clientId, _projectId,
                                                "Development", 50M, "Doing some work",
                                                Date.Parse("2012-01-30"),
                                                Time.Parse("12:00"), Time.Parse("14:00"),
                                                DateTime.UtcNow) { Version = 1 });
        }
        public TimeRegistrationModule(IProjectRepository projectRepository, 
                                      IClientRepository clientRepository, 
                                      ITimeRegistrationRepository timeRegistrationRepository, 
                                      IIdGenerator idGenerator, 
                                      IAggregateRootRepository aggregateRootRepository,
                                      IRootPathProvider rootPathProvider,
                                      IExcelService excelService)
            : base("/timeregistration")
        {
            this.RequiresAuthentication();

            Get["/"] = _ => View["Index"];

            Get["/overview"] = _ => View["Overview"];

            Get["/report"] = _ => View["Report"];

            Get["/import"] = _ => View["Import"];

            Post["/importupload"] = _ =>
            {
                var fileName = Guid.NewGuid().ToString("N").Substring(0, 4) + "_" + Path.GetFileName((string)Request.Files.First().Name);
                var path = Path.Combine(rootPathProvider.GetRootPath(), "App_Data", "Uploads", fileName);
               
                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    Request.Files.First().Value.CopyTo(fileStream);
                }

                return Response.AsRedirect("~/timeregistration/importmap/" + HttpUtility.UrlEncode(fileName));
            };

            Get["/importmap/{url*}"] = parameters =>
            {
                var viewModel = new ImportViewModel();

                viewModel.ServerFile = Path.Combine(rootPathProvider.GetRootPath(), "App_Data", "Uploads", parameters.url);
                var excelPackage = new ExcelPackage(new FileInfo(viewModel.ServerFile));
                var worksheet = excelPackage.Workbook.Worksheets.First();

                viewModel.ColumnNames = new List<ImportViewModel.ColumnInfo>();
                foreach (var firstRowCell in worksheet.Cells[worksheet.Dimension.Start.Row, worksheet.Dimension.Start.Column, 1, worksheet.Dimension.End.Column])
                    viewModel.ColumnNames.Add(new ImportViewModel.ColumnInfo { Column = firstRowCell.Start.Column, Name = firstRowCell.Text });

                return View["ImportMap", viewModel];
            };

            Post["/import"] = _ =>
            {
                var viewModel = this.Bind<ImportViewModel>();

                var result = excelService.Import(viewModel.ServerFile, viewModel.ProjectIdColumn, viewModel.TaskColumn,
                                                 viewModel.DateColumn, viewModel.FromColumn, viewModel.ToColumn, 
                                                 viewModel.RateColumn, viewModel.DescriptionColumn);

                return View["ImportResult", result];
            };

            Get["/export/{fromDate}/{toDate}"] = parameters =>
            {
                var min = ((DateTime)parameters.fromDate).GetNumericValue();
                var max = ((DateTime)parameters.toDate).AddDays(1).GetNumericValue();

                var items = timeRegistrationRepository
                    .Where(t => t.Date.Numeric >= min && t.Date.Numeric < max)
                    .OrderBy(t => t.Date.Numeric)
                    .ThenBy(t => t.From.Numeric)
                    .ToList();

                return Response.AsExcel(items);
            };
        }
 public RegistrationsController(ITimeRegistrationRepository repository) => _repository = repository;
Esempio n. 7
0
 public TimeRegistrationService(ITimeRegistrationRepository timeRegistrationRepository)
 {
     _timeRegistrationRepository = timeRegistrationRepository;
 }