Exemple #1
0
        public void Test_For_DeleteEntity_Valid(int testProjectId, bool expectedResult)
        {
            var testProjectToDelete = testingProjectRepo.GetById(testProjectId);
            var actualResult        = testingProjectRepo.Delete(testProjectToDelete);

            Assert.Equal(expectedResult, actualResult);
        }
 public ActionResult <ProjectDTO> GetProject(long projectId)
 {
     try
     {
         return(new ProjectDTO(_projects.GetById(projectId)));
     }
     catch (ArgumentNullException)
     {
         return(NotFound(new CustomErrorDTO("Project niet gevonden")));
     }
 }
        public bool EndProject(int projId)
        {
            var projectToEnd = _projectRepo.GetById(projId);

            if (projectToEnd != null)
            {
                projectToEnd.ProjectEnd = System.DateTime.Today;
                return(_projectRepo.Update(projectToEnd));
            }
            else
            {
                return(false);
            }
        }
        public async Task <ProjectDto> GetById(int userId, int projectId)
        {
            // TODO: [TESTS] (ProjectService.GetById) Add tests
            var builder = new ServiceMetricBuilder(nameof(ProjectService), nameof(GetById))
                          .WithCategory(MetricCategory.Project, MetricSubCategory.GetById)
                          .WithCustomInt1(userId)
                          .WithCustomInt2(0)
                          .WithCustomInt3(projectId);

            try
            {
                using (builder.WithTiming())
                {
                    ProjectEntity dbEntry;
                    using (builder.WithCustomTiming1())
                    {
                        builder.IncrementQueryCount();
                        dbEntry = await _projectRepo.GetById(projectId);

                        builder.CountResult(dbEntry);
                    }

                    if (dbEntry == null)
                    {
                        // TODO: [HANDLE] (ProjectService.GetById) Handle this
                        return(null);
                    }

                    builder.WithCustomInt2(dbEntry.ProductId);
                    if (dbEntry.UserId != userId)
                    {
                        // TODO: [HANDLE] (ProjectService.GetById) Handle this
                        return(null);
                    }

                    return(ProjectDto.FromEntity(dbEntry));
                }
            }
            catch (Exception ex)
            {
                _logger.LogUnexpectedException(ex);
                builder.WithException(ex);
                return(null);
            }
            finally
            {
                await _metrics.SubmitPointAsync(builder.Build());
            }
        }
        public async Task <GetTimeSheetResponse> UpdateEntry(AddTimeSheetEntryRequest request)
        {
            // TODO: [TESTS] (TimeSheetService.UpdateEntry) Add tests
            var loggedTime = request.LoggedTimeMin;
            var dbProject  = await _projectRepo.GetById(request.ProjectId);

            var baseDate  = new DateTime(request.EntryDate.Year, request.EntryDate.Month, request.EntryDate.Day);
            var entryDate = DateTime.SpecifyKind(baseDate, DateTimeKind.Utc);

            var dbEntry = await _entriesRepo.GetProjectTimeSheetEntry(request.ProjectId, request.EntryDate);

            if (dbEntry == null)
            {
                // TODO: [EX] (TimeSheetService.UpdateEntry) Throw better exception here
                if (await _entriesRepo.AddEntry(CreateTimeSheetEntry(dbProject, entryDate, loggedTime)) == 0)
                {
                    throw new Exception("Unable to create entry");
                }
            }
            else
            {
                dbEntry.EntryVersion += 1;
                dbEntry.EntryTimeMin  = loggedTime;
                // TODO: [EX] (TimeSheetService.UpdateEntry) Throw better exception
                if (await _entriesRepo.UpdateEntry(dbEntry) == 0)
                {
                    throw new Exception("Unable to update entry");
                }
            }

            return(await GetTimeSheet(new GetTimeSheetRequest
            {
                ClientId = dbProject.ClientId,
                StartDate = request.StartDate,
                EndDate = request.EndDate
            }));
        }
Exemple #6
0
        public ActionResult Details(int id)
        {
            Project project = projectRepo.GetById(id);

            return(View(project));
        }