Exemplo n.º 1
0
        public async Task <TimeEntryDto> SaveAsync(TimeEntryDto timeEntry)
        {
            timeEntry.TimeEntryId = _uniqueIdGenerator.GetUid();

            _timeEntries.Add(timeEntry);

            return(timeEntry);
        }
Exemplo n.º 2
0
        private TimeEntryUpdatedStatusDto SaveOrUpdateTimeEntry(TimeEntryDto timeEntryDto, User user)
        {
            var response = new TimeEntryUpdatedStatusDto();

            response.Guid = timeEntryDto.Guid;
            response.IsOK = true;

            var task          = _taskRepository.GetByGuid(timeEntryDto.TaskGuid);
            var timeEntryType = _timeEntryTypeRepository.GetById(timeEntryDto.TimeEntryTypeId);
            var pricePrHour   = _priceService.GetPrice(timeEntryDto.PricePrHour, user, task);

            if (_timeEntryRepository.Exists(timeEntryDto.Guid))
            {
                var changedTimeEntry = _timeEntryRepository.GetByGuid(timeEntryDto.Guid);

                if (changedTimeEntry.Invoice != null)
                {
                    //throw
                    response.IsOK       = false;
                    response.ReasonText = "Can not edit timeentry that has marked as invoiced!";
                    return(response);
                }

                changedTimeEntry.User          = user;
                changedTimeEntry.Task          = task;
                changedTimeEntry.TimeEntryType = timeEntryType;
                changedTimeEntry.StartTime     = timeEntryDto.StartTime;
                changedTimeEntry.EndTime       = timeEntryDto.EndTime;
                changedTimeEntry.Description   = timeEntryDto.Description;
                changedTimeEntry.TimeSpent     = timeEntryDto.TimeSpent;
                changedTimeEntry.BillableTime  = timeEntryDto.BillableTime;
                changedTimeEntry.Billable      = timeEntryDto.Billable;
                changedTimeEntry.Price         = pricePrHour;

                _timeEntryRepository.SaveOrUpdate(changedTimeEntry);
                return(response);
            }

            var newTimeEntry = _timeEntryFactory.Create(
                timeEntryDto.Guid,
                user,
                task,
                timeEntryType,
                timeEntryDto.StartTime,
                timeEntryDto.EndTime,
                timeEntryDto.Description,
                timeEntryDto.TimeSpent,
                0,
                timeEntryDto.BillableTime,
                timeEntryDto.Billable,
                pricePrHour,
                timeEntryDto.ClientSourceId
                );

            _timeEntryRepository.SaveOrUpdate(newTimeEntry);

            return(response);
        }
Exemplo n.º 3
0
 public TimeEntryValidationServiceTests()
 {
     _validationService = new TimeEntryValidationService(_uniqueIdGenerator);
     _timeEntry         = new TimeEntryDto
     {
         ProjectId = ProjectId
     };
     _uniqueIdGenerator.IsValidUid(ProjectId).Returns(true);
 }
Exemplo n.º 4
0
        public async Task CanUpdateAsync()
        {
            var expected = new TimeEntryDto();

            _repository.UpdateAsync(_timeEntry).Returns(expected);

            var actual = await _controller.UpdateAsync(_timeEntry);

            actual.Should().Be(expected);
        }
Exemplo n.º 5
0
 public TimeEntriesControllerTests()
 {
     _controller = new TimeEntriesController(_validationService, _repository);
     _timeEntry  = new TimeEntryDto
     {
         TimeEntryId = "TimeEntryId",
         Date        = "2020-02-02",
         UserId      = "UserId",
         ProjectId   = "ProjectId"
     };
 }
Exemplo n.º 6
0
        public async Task ValidateSaveAsync(TimeEntryDto timeEntry)
        {
            var errors = new List <string>();

            if (_uniqueIdGenerator.IsValidUid(timeEntry.ProjectId) == false)
            {
                errors.Add("Project is not specified, please choose any.");
            }

            ThrowIfErrors(errors);
        }
Exemplo n.º 7
0
        public static TimeEntryDto ConvertToDto(Entity entity)
        {
            var result = new TimeEntryDto
            {
                Start            = entity.GetAttributeValue <DateTime>(TimeEntry.Properties.Start).ToUniversalTime(),
                End              = entity.GetAttributeValue <DateTime>(TimeEntry.Properties.End).ToUniversalTime(),
                BookableResource = entity.GetAttributeValue <EntityReference>(TimeEntry.Properties.BookableResource)
            };

            return(result);
        }
 public async Task InsertEntry(string email, TimeEntryDto timeEntryDto)
 {
     var entity = new TimeEntry
     {
         PartitionKey = email,
         RowKey       = timeEntryDto.DateTime.Ticks + "_" + Guid.NewGuid().ToString("n").Substring(0, 8),
         Amount       = timeEntryDto.Amount,
         Unit         = timeEntryDto.Unit,
         ProjectName  = timeEntryDto.ProjectName
     };
     var operation = TableOperation.InsertOrReplace(entity);
     await _timeEntryTable.ExecuteAsync(operation);
 }
Exemplo n.º 9
0
        public TimeEntryDto SaveTimeEntry(TimeEntryDto timeEntryDto, int userId)
        {
            var user          = _userRepository.GetByUserID(userId);
            var task          = _taskRepository.GetByGuid(timeEntryDto.TaskGuid);
            var timeEntryType = _timeEntryTypeRepository.GetById(timeEntryDto.TimeEntryTypeId);
            var pricePrHour   = _priceService.GetPrice(timeEntryDto.PricePrHour, user, task);

            if (!_timeEntryRepository.Exists(timeEntryDto.Guid))
            {
                //TODO: Do logic that splits the timeentry in two, if a dateshift has occurred
                //    if(timeEntry.StartTime.Date != timeEntry.EndTime.Date)

                var newTimeEntry = _timeEntryFactory.Create(
                    timeEntryDto.Guid,
                    user,
                    task,
                    timeEntryType,
                    timeEntryDto.StartTime,
                    timeEntryDto.EndTime,
                    timeEntryDto.Description,
                    timeEntryDto.TimeSpent,
                    0,
                    timeEntryDto.BillableTime,
                    timeEntryDto.Billable,
                    pricePrHour,
                    timeEntryDto.ClientSourceId
                    );

                _timeEntryRepository.SaveOrUpdate(newTimeEntry);
                timeEntryDto.Id = newTimeEntry.Id;
            }
            else
            {
                var changedTimeEntry = _timeEntryRepository.GetByGuid(timeEntryDto.Guid);
                changedTimeEntry.User          = user;
                changedTimeEntry.Task          = task;
                changedTimeEntry.TimeEntryType = timeEntryType;
                changedTimeEntry.StartTime     = timeEntryDto.StartTime;
                changedTimeEntry.EndTime       = timeEntryDto.EndTime;
                changedTimeEntry.Description   = timeEntryDto.Description;
                changedTimeEntry.TimeSpent     = timeEntryDto.TimeSpent;
                changedTimeEntry.BillableTime  = timeEntryDto.BillableTime;
                changedTimeEntry.Billable      = timeEntryDto.Billable;
                changedTimeEntry.Price         = pricePrHour;

                _timeEntryRepository.SaveOrUpdate(changedTimeEntry);
            }

            return(timeEntryDto);
        }
Exemplo n.º 10
0
 private async Task <TimeEntry> ConvertToTimeEntry(TimeEntryDto newTimeEntry)
 {
     if (newTimeEntry == null)
     {
         return(null);
     }
     return(new TimeEntry()
     {
         Id = newTimeEntry.id,
         Description = newTimeEntry.description,
         Start = DateTime.Parse(newTimeEntry.start),
         Project = newTimeEntry.pid == null ? null : await _projectService.GetProject(newTimeEntry.pid.Value),
         Duration = TimeSpan.FromSeconds(newTimeEntry.duration)
     });
 }
Exemplo n.º 11
0
        public async Task CanSaveAsync()
        {
            var timeEntry = new TimeEntryDto
            {
                UserId      = UserId,
                ProjectId   = "ProjectId",
                Date        = "Date",
                Remarks     = "Remarks",
                IsPaid      = true,
                PriceMinor  = 12345,
                ProjectName = "ProjectName"
            };

            await _repository.SaveAsync(timeEntry);

            var actual = (await _repository.LoadTimeEntriesAsync(UserId)).Single();

            actual.TimeEntryId.Should().Be(TimeEntryId);
            actual.Should().BeEquivalentTo(timeEntry);
        }
Exemplo n.º 12
0
        public void CanGetTimeEntrySummaries()
        {
            // Establish Context
            IList <TimeEntryDto> timeEntrySummariesToExpect = new List <TimeEntryDto>();

            var timeEntryDto = new TimeEntryDto();

            timeEntrySummariesToExpect.Add(timeEntryDto);

            _timeEntryRepository.Expect(r => r.GetTimeEntrySummaries())
            .Return(timeEntrySummariesToExpect);

            // Act
            IList <TimeEntryDto> timeEntrySummariesRetrieved =
                _timeEntryManagementService.GetTimeEntrySummaries();

            // Assert
            timeEntrySummariesRetrieved.ShouldNotBeNull();
            timeEntrySummariesRetrieved.Count.ShouldEqual(1);
            timeEntrySummariesRetrieved[0].ShouldNotBeNull();
            timeEntrySummariesRetrieved[0].ShouldEqual(timeEntryDto);
        }
Exemplo n.º 13
0
 public async Task ValidateUpdateAsync(TimeEntryDto timeEntry)
 {
     throw new System.NotImplementedException();
 }
        private IEnumerable <TimeEntryDto> FakeDataForTestingWithNoSQL()
        {
            var t1 = new TimeEntryDto()
            {
                Id                   = 1,
                PreceptorId          = 1,
                StudentId            = 2,
                Hours                = 2,
                Notes                = "Notes",
                Rotation             = "GI",
                Date                 = DateConverter.Convert(DateTime.Now),
                PreceptorDisplayName = "Dave",
                StudentDisplayName   = "Me",
            };

            yield return(t1);

            var t2 = new TimeEntryDto()
            {
                Id                   = 2,
                PreceptorId          = 3,
                StudentId            = 2,
                Hours                = 5,
                Notes                = "notes asdsadas dasd sad asd asd ",
                Rotation             = "Endo",
                Date                 = DateConverter.Convert(DateTime.Now),
                PreceptorDisplayName = "Brad",
                StudentDisplayName   = "Me",
            };

            yield return(t2);

            var t3 = new TimeEntryDto()
            {
                Id                   = 3,
                PreceptorId          = 4,
                StudentId            = 5,
                Hours                = 2,
                Notes                = "notes",
                Rotation             = "Endo",
                Date                 = DateConverter.Convert(DateTime.Now),
                PreceptorDisplayName = "MECEPTOR",
                StudentDisplayName   = "peeps",
            };

            yield return(t3);

            var t4 = new TimeEntryDto()
            {
                Id                   = 4,
                PreceptorId          = 4,
                StudentId            = 6,
                Hours                = 4,
                Notes                = "notes asdsadas dasd sad asd asd ",
                Rotation             = "Endo",
                Date                 = DateConverter.Convert(DateTime.Now),
                PreceptorDisplayName = "MECEPTOR",
                StudentDisplayName   = "other peeps",
            };

            yield return(t4);
        }
Exemplo n.º 15
0
        public async Task <TimeEntryDto> UpdateAsync(TimeEntryDto timeEntry)
        {
            var exisiting = _timeEntries.First(t => t.TimeEntryId == timeEntry.TimeEntryId);

            return(exisiting);
        }
Exemplo n.º 16
0
        public async Task <TimeEntryDto> UpdateAsync(TimeEntryDto timeEntry)
        {
            await _validationService.ValidateUpdateAsync(timeEntry);

            return(await _timeEntryRepository.UpdateAsync(timeEntry));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="pluginExecutionFacade"></param>
        /// <param name="newTimeEntryDto"></param>
        /// <returns></returns>
        private IEnumerable <DateTime> GetExistingTimeEntryDates(PluginExecutionFacade pluginExecutionFacade, TimeEntryDto newTimeEntryDto)
        {
            var queryExpression = TimeEntryQueryExpressionBuilder.Build(new GetEntryTimeRangeRequest(
                                                                            start: newTimeEntryDto.Start,
                                                                            end: newTimeEntryDto.End,
                                                                            resourceId: newTimeEntryDto.BookableResource.Id));
            var service          = pluginExecutionFacade.OrganizationService;
            var entityCollection = service.RetrieveMultiple(queryExpression);

            return(entityCollection.Entities.Select(e => e.GetAttributeValue <DateTime>(TimeEntry.Properties.Start).ToUniversalTime().Date));
        }
        public int AddNewEntry(TimeEntryDto timeEntry)
        {
            DateTime date = DateTime.Parse(timeEntry.Date);

            return(10);
        }
 public bool EditEntry(TimeEntryDto timeEntry)
 {
     return(true);
 }
Exemplo n.º 20
0
        public async Task <TimeEntryDto> SaveAsync([FromBody] TimeEntryDto timeEntry)
        {
            await _validationService.ValidateSaveAsync(timeEntry);

            return(await _timeEntryRepository.SaveAsync(timeEntry));
        }
Exemplo n.º 21
0
 public TimeEntryDtoBuilder()
 {
     _timeEntryDto = WithDefaults();
 }