Esempio n. 1
0
 public TTaskDto UpdateTask(TContextDto context, TTaskDto task)
 {
     try
     {
         if (task.TTaskID > 0)
         {
             var existingTask = _db.TTasks.SingleOrDefault(e => e.TTaskID == task.TTaskID);
             if (existingTask != null)
             {
                 if (existingTask.TProject.TUserID == context.TUserID)
                 {
                     // if there are no entries, remove it instead
                     if (task.IsObsolete && !_db.TEntries.Any(e => e.TTaskID == task.TTaskID))
                     {
                         _db.TTasks.Remove(existingTask);
                     }
                     else
                     {
                         if (!string.IsNullOrWhiteSpace(task.Name))
                         {
                             existingTask.Name = task.Name;
                         }
                         existingTask.IsObsolete   = task.IsObsolete;
                         existingTask.DisplayOrder = task.DisplayOrder;
                     }
                     _db.SaveChanges();
                 }
                 return(Mapper.Map <TTaskDto>(existingTask));
             }
         }
         else if (task.TProjectID > 0 && !task.IsObsolete && !string.IsNullOrWhiteSpace(task.Name))
         {
             var existingProject = _db.TProjects.SingleOrDefault(p => p.TProjectID == task.TProjectID && p.TUserID == context.TUserID);
             if (existingProject != null)
             {
                 var newTask = new TTask
                 {
                     DisplayOrder = task.DisplayOrder,
                     IsObsolete   = task.IsObsolete,
                     Name         = task.Name,
                     TProjectID   = task.TProjectID
                 };
                 _db.TTasks.Add(newTask);
                 _db.SaveChanges();
                 return(Mapper.Map <TTaskDto>(newTask));
             }
         }
         return(null);
     }
     catch (Exception ex)
     {
         throw new WebFaultException <string>(ex.Message, HttpStatusCode.BadRequest);
     }
 }
Esempio n. 2
0
 public TStatusModelDto GetStatusModel(TContextDto context)
 {
     try
     {
         var calc = new TracktorCalculator(context, _db);
         return(calc.BuildStatusModel());
     }
     catch (Exception ex)
     {
         throw new WebFaultException <string>(ex.Message, HttpStatusCode.BadRequest);
     }
 }
Esempio n. 3
0
 public void StopTask(TContextDto context, int currentTaskID)
 {
     try
     {
         var states = new TracktorStates(context, _db);
         states.Stop(currentTaskID);
     }
     catch (Exception ex)
     {
         throw new WebFaultException <string>(ex.Message, HttpStatusCode.BadRequest);
     }
 }
Esempio n. 4
0
 public TReportModelDto GetReportModel(TContextDto context, DateTime?startDate, DateTime?endDate, int projectID, int taskID)
 {
     try
     {
         var calculator = new TracktorCalculator(context, _db);
         return(Mapper.Map <TReportModelDto>(calculator.GetReport(startDate, calculator.DateOrLocalNow(endDate), projectID, taskID)));
     }
     catch (Exception ex)
     {
         throw new WebFaultException <string>(ex.Message, HttpStatusCode.BadRequest);
     }
 }
Esempio n. 5
0
 public TEntryDto GetEntry(TContextDto context, int entryID)
 {
     try
     {
         var calc  = new TracktorCalculator(context, _db);
         var entry = _db.TEntries.Single(e => e.TEntryID == entryID && e.TTask.TProject.TUserID == context.TUserID);
         return(calc.EnrichTEntry(null, entry));
     }
     catch (Exception ex)
     {
         throw new WebFaultException <string>(ex.Message, HttpStatusCode.BadRequest);
     }
 }
Esempio n. 6
0
 public TProjectDto UpdateProject(TContextDto context, TProjectDto project)
 {
     try
     {
         if (project.TProjectID > 0)
         {
             var existingProject = _db.TProjects.SingleOrDefault(e => e.TProjectID == project.TProjectID);
             if (existingProject != null)
             {
                 if (existingProject.TUserID == context.TUserID)
                 {
                     // if there are no tasks, remove it instead
                     if (project.IsObsolete && !_db.TTasks.Any(e => e.TProjectID == project.TProjectID))
                     {
                         _db.TProjects.Remove(existingProject);
                     }
                     else
                     {
                         if (!string.IsNullOrWhiteSpace(project.Name))
                         {
                             existingProject.Name = project.Name;
                         }
                         existingProject.IsObsolete   = project.IsObsolete;
                         existingProject.DisplayOrder = project.DisplayOrder;
                     }
                     _db.SaveChanges();
                 }
                 return(Mapper.Map <TProjectDto>(existingProject));
             }
         }
         else if (!project.IsObsolete && !string.IsNullOrWhiteSpace(project.Name))
         {
             var newProject = new TProject
             {
                 DisplayOrder = project.DisplayOrder,
                 IsObsolete   = project.IsObsolete,
                 Name         = project.Name,
                 TUserID      = context.TUserID
             };
             _db.TProjects.Add(newProject);
             _db.SaveChanges();
             return(Mapper.Map <TProjectDto>(newProject));
         }
         return(null);
     }
     catch (Exception ex)
     {
         throw new WebFaultException <string>(ex.Message, HttpStatusCode.BadRequest);
     }
 }
Esempio n. 7
0
        public TracktorStates(TContextDto context, ITracktorContext db)
        {
            _db           = db;
            mContext      = context;
            mStateMachine = new StateMachine <TState, TTrigger>(GetCurrentState, ChangeState);
            _startTrigger = mStateMachine.SetTriggerParameters <int>(TTrigger.Start);
            _stopTrigger  = mStateMachine.SetTriggerParameters <int>(TTrigger.Stop);

            mStateMachine.Configure(TState.Idle)
            .PermitDynamic(_startTrigger, newTaskId => AcceptStart(newTaskId))
            .OnEntryFrom(_stopTrigger, newTaskId => StopTask(newTaskId));
            mStateMachine.Configure(TState.InProgress)
            .PermitDynamic(_stopTrigger, newTaskId => AcceptStop(newTaskId))
            .OnEntryFrom(_startTrigger, newTaskId => StartTask(newTaskId));
        }
Esempio n. 8
0
 public TEntryDto UpdateEntry(TContextDto context, TEntryDto entry)
 {
     try
     {
         if (entry.TEntryID > 0)
         {
             var existingEntry = _db.TEntries.SingleOrDefault(e => e.TEntryID == entry.TEntryID);
             if (existingEntry != null)
             {
                 var calculator = new TracktorCalculator(context, _db);
                 if (existingEntry.TTask.TProject.TUserID == context.TUserID)
                 {
                     if (entry.IsDeleted == true)
                     {
                         // stop if in progress
                         if (!existingEntry.EndDate.HasValue)
                         {
                             StopTask(context, entry.TTaskID);
                             existingEntry = _db.TEntries.SingleOrDefault(e => e.TEntryID == entry.TEntryID);
                         }
                         _db.TEntries.Remove(existingEntry);
                         _db.SaveChanges();
                         return(null);
                     }
                     else
                     {
                         var startUtc = calculator.ToUtc(entry.StartDate).Value;
                         var endUtc   = calculator.ToUtc(entry.EndDate);
                         var now      = DateTime.UtcNow;
                         if (startUtc <= now &&
                             (!endUtc.HasValue || (endUtc.HasValue && endUtc.Value <= now && endUtc.Value > startUtc)))
                         {
                             existingEntry.StartDate = startUtc;
                             existingEntry.EndDate   = endUtc;
                             _db.SaveChanges();
                         }
                     }
                     return(calculator.EnrichTEntry(null, existingEntry));
                 }
             }
         }
         return(null);
     }
     catch (Exception ex)
     {
         throw new WebFaultException <string>(ex.Message, HttpStatusCode.BadRequest);
     }
 }
Esempio n. 9
0
 public TEntriesModelDto GetEntriesModel(TContextDto context, DateTime?startDate, DateTime?endDate, int projectID, int startNo, int maxEntries)
 {
     try
     {
         var calc    = new TracktorCalculator(context, _db);
         var entries = calc.GetEntries(startDate, calc.DateOrLocalNow(endDate), projectID, 0, startNo, maxEntries);
         return(new TEntriesModelDto
         {
             Entries = calc.CalculateEntryContribs(entries, startDate, calc.DateOrLocalNow(endDate))
         });
     }
     catch (Exception ex)
     {
         throw new WebFaultException <string>(ex.Message, HttpStatusCode.BadRequest);
     }
 }
Esempio n. 10
0
 public void StartTask(TContextDto context, int newTaskID)
 {
     try
     {
         var startTask = _db.TTasks.Single(t => t.TTaskID == newTaskID);
         if (startTask.TProject.TUserID != context.TUserID)
         {
             throw new Exception("Invalid Task ID.");
         }
         var states = new TracktorStates(context, _db);
         states.Start(newTaskID);
     }
     catch (Exception ex)
     {
         throw new WebFaultException <string>(ex.Message, HttpStatusCode.BadRequest);
     }
 }
Esempio n. 11
0
 public TracktorCalculator(TContextDto context, ITracktorContext db)
 {
     _db      = db;
     mContext = context;
 }