Example #1
0
        public static TimeEntry ToDtoObject(this Trex.Server.Core.Model.TimeEntry timeEntry, bool includeParent)
        {
            var dtoTimeEntry = new TimeEntry();

            if (includeParent)
            {
                dtoTimeEntry.Task = timeEntry.Task.ToDtoObject(true, false, false);
            }
            dtoTimeEntry.TaskGuid = timeEntry.Task.Guid;
            dtoTimeEntry.TaskId   = timeEntry.Task.Id;

            dtoTimeEntry.Guid          = timeEntry.Guid;
            dtoTimeEntry.Id            = timeEntry.Id;
            dtoTimeEntry.PricePrHour   = timeEntry.Price;
            dtoTimeEntry.StartTime     = timeEntry.StartTime;
            dtoTimeEntry.EndTime       = timeEntry.EndTime;
            dtoTimeEntry.TimeSpent     = timeEntry.TimeSpent;
            dtoTimeEntry.Billable      = timeEntry.Billable;
            dtoTimeEntry.BillableTime  = timeEntry.BillableTime;
            dtoTimeEntry.Description   = timeEntry.Description;
            dtoTimeEntry.User          = timeEntry.User.ToDtoObject(false);
            dtoTimeEntry.TimeEntryType = timeEntry.TimeEntryType.ToDtoObject();
            if (timeEntry.Invoice != null)
            {
                dtoTimeEntry.InvoiceId = timeEntry.Invoice.ID;
            }

            return(dtoTimeEntry);
        }
Example #2
0
        public TimeEntry SaveTimeEntry(TimeEntry timeEntry)
        {
            try
            {
                var timeEntryRepository     = ObjectFactory.GetInstance <ITimeEntryRepository>();
                var taskRepository          = ObjectFactory.GetInstance <ITaskRepository>();
                var timeEntryFactory        = ObjectFactory.GetInstance <ITimeEntryFactory>();
                var priceService            = ObjectFactory.GetInstance <IPriceService>();
                var userRepository          = ObjectFactory.GetInstance <IUserRepository>();
                var timeEntryTypeRepository = ObjectFactory.GetInstance <ITimeEntryTypeRepository>();
                var user          = userRepository.GetByUserID(timeEntry.User.UserId);
                var task          = taskRepository.GetByGuid(timeEntry.TaskGuid);
                var timeEntryType = timeEntryTypeRepository.GetById(timeEntry.TimeEntryType.Id);
                var pricePrHour   = priceService.GetPrice(timeEntry.PricePrHour, task.Id, timeEntry.User.UserId);

                if (!timeEntryRepository.Exists(timeEntry.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(
                        timeEntry.Guid,
                        user,
                        task,
                        timeEntryType,
                        timeEntry.StartTime,
                        timeEntry.EndTime,
                        timeEntry.Description,
                        timeEntry.TimeSpent,
                        0,
                        timeEntry.BillableTime,
                        timeEntry.Billable,
                        pricePrHour
                        );

                    timeEntryRepository.Save(newTimeEntry);

                    timeEntry.Id = newTimeEntry.Id;
                }

                else
                {
                    var changedTimeEntry = timeEntryRepository.GetByGuid(timeEntry.Guid);
                    changedTimeEntry.User          = user;
                    changedTimeEntry.Task          = task;
                    changedTimeEntry.TimeEntryType = timeEntryType;
                    changedTimeEntry.StartTime     = timeEntry.StartTime;
                    changedTimeEntry.EndTime       = timeEntry.EndTime;
                    changedTimeEntry.Description   = timeEntry.Description;
                    changedTimeEntry.TimeSpent     = timeEntry.TimeSpent;
                    changedTimeEntry.BillableTime  = timeEntry.BillableTime;
                    changedTimeEntry.Billable      = timeEntry.Billable;
                    changedTimeEntry.Price         = pricePrHour;

                    timeEntryRepository.Save(changedTimeEntry);
                }

                return(timeEntry);
            }
            catch (Exception ex)
            {
                OnError(ex);
                throw;
            }
        }