예제 #1
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);
        }
예제 #2
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);
        }
        public ActionConfirmation SaveOrUpdate(TimeEntry timeEntry)
        {
            if (timeEntry.IsValid())
            {
                _timeEntryRepository.SaveOrUpdate(timeEntry);

                ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation("");
                saveOrUpdateConfirmation.Value = timeEntry;

                return(saveOrUpdateConfirmation);
            }
            else
            {
                _timeEntryRepository.DbContext.RollbackTransaction();

                return(ActionConfirmation.CreateFailureConfirmation(
                           "The Time Entry could not be saved due to missing or invalid information."));
            }
        }