Esempio n. 1
0
        } // end Execute

        public static int Execute(Connection connection, string sUserId, int iTaskID)
        {
            int iTimeLogID;

            connection.BeginTransaction();

            iTimeLogID = Stop.Execute(connection, sUserId);
            if (iTimeLogID >= 0)
            {
                // Pause for a second to ensure the start is not the same as the stop
                System.Threading.Thread.Sleep(1000);

                iTimeLogID = TimeLogEntry.Create(connection, ActionTypes.Start, sUserId, iTaskID);
            } // end if

            if (iTimeLogID > 0)
            {
                connection.CommitTransaction();

                return(iTimeLogID);
            } // end if
            else
            {
                connection.RollbackTransaction();

                return(iTimeLogID);
            } // end else
        }     // end Execute
Esempio n. 2
0
        public override async void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
        {
            switch (editingStyle)
            {
            case UITableViewCellEditingStyle.Delete:
                TimeLogEntry item = indexedTableItems[keys[indexPath.Section]][indexPath.Row];

                if (isActiveTimeLog(item))
                {
                    ViewControllerHelper.ShowAlert(owner, "Oops", "You are currently logging time to this time log. Please stop the timmer first.");
                }
                else
                {
                    try
                    {
                        await PDashAPI.Controller.DeleteTimeLog(item.Id.ToString());
                    }
                    catch (Exception ex)
                    {
                        ViewControllerHelper.ShowAlert(owner, "Delete Time Log", ex.Message + " Please try again later.");
                    }
                }

                indexedTableItems[keys[indexPath.Section]].RemoveAt(indexPath.Row);
                tableView.DeleteRows(new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade);
                // save the time log entry deletion to server

                break;

            case UITableViewCellEditingStyle.None:
                Console.WriteLine("CommitEditingStyle:None called");
                break;
            }
        }
Esempio n. 3
0
        public async Task Add(MainDbContext db, Guid pollId, IList <PollResponseAddRequest> reqs)
        {
            var createdTimeUtc = _timeService.UtcNow;

            for (int i = 0; i < reqs.Count; i++)
            {
                var req = reqs[i];
                ValidatePollResponseAddRequest(req, i);

                // Round down to the nearest minute.
                var savedFromTime = ToStartOfMinute(req.TimeCollected);

                var newEntry = new TimeLogEntry
                {
                    Id             = Guid.NewGuid(),
                    PollId         = pollId,
                    FromTime       = savedFromTime,
                    ToTime         = savedFromTime + req.TimeBlockLength,
                    EntryText      = req.ResponseText,
                    CreatedTimeUtc = createdTimeUtc,
                    TimeZone       = req.TimeZone,
                    TimeZoneOffset = req.TimeZoneOffset,
                    SubmissionType = req.SubmissionType,
                };

                db.TimeLogEntries.Add(newEntry);
            }

            await db.SaveChangesAsync();
        }
Esempio n. 4
0
        protected TimeLogEntry InsertUndoTimeLogEntry(TimeLogEntry entry)
        {
            var undoEntry = entry.CopyAndChangeId();

            undoEntry.UndoTarget     = entry.Id;
            undoEntry.CreatedTimeUtc = entry.CreatedTimeUtc.AddSeconds(3);

            Db.Mock.TimeLogEntries.QueryData.Add(undoEntry);
            return(undoEntry);
        }
        public void SetData(string projectName, string taskName, string taskId, TimeLogEntry timeLog)
        {
            _projectName = projectName;
            _taskName    = taskName;
            _timeLog     = timeLog;
            _taskId      = taskId;

            Debug.WriteLine("PN :" + _projectName);
            Debug.WriteLine("TN :" + _taskName);

            Debug.WriteLine("Time log ; " + _timeLog);
            Debug.WriteLine("Task ID :" + _taskId);
        }
Esempio n. 6
0
 private TimeLogEntryMsgWithDeletionMarker ToMsg(TimeLogEntry timeLogEntry)
 {
     return(new TimeLogEntryMsgWithDeletionMarker
     {
         Id = timeLogEntry.Id,
         FromTime = timeLogEntry.FromTime,
         TimeBlockLength = timeLogEntry.ToTime - timeLogEntry.FromTime,
         EntryText = timeLogEntry.EntryText,
         CreatedTimeUtc = timeLogEntry.CreatedTimeUtc,
         IsDeletion = timeLogEntry.IsDeletion,
         SubmissionType = timeLogEntry.SubmissionType,
     });
 }
Esempio n. 7
0
        //====================== Private =======================
        private TimeLogEntry InsertDeletion(DateTime fromTime, DateTime toTime)
        {
            var entry = new TimeLogEntry
            {
                Id             = Guid.NewGuid(),
                PollId         = DefaultPollId,
                FromTime       = fromTime,
                ToTime         = toTime,
                EntryText      = "[deletion]",
                CreatedTimeUtc = fromTime.AddSeconds(3),
                IsDeletion     = true,
            };

            Db.Mock.TimeLogEntries.QueryData.Add(entry);
            return(entry);
        }
Esempio n. 8
0
        /// <summary>
        /// Called by the TableView to get the actual UITableViewCell to render for the particular section and row
        /// </summary>
        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            CustomTimeLogCell cell = tableView.DequeueReusableCell(cellIdentifier) as CustomTimeLogCell;
            TimeLogEntry      item = indexedTableItems[keys[indexPath.Section]][indexPath.Row];

            // if there are no cells to reuse, create a new one
            if (cell == null)
            {
                cell = new CustomTimeLogCell((NSString)cellIdentifier);
            }

            //cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;

            cell.UpdateCell(item.Task.FullName.ToString()
                            , item.StartDate.ToLocalTime().ToShortTimeString()
                            , TimeSpan.FromMinutes(item.LoggedTime).ToString(@"hh\:mm"));

            return(cell);
        }
Esempio n. 9
0
      } // end HandleDayOverlaps

      private static int HandleDayOverlaps(Connection connection, TaskLogEntry taskLogEntry)
      {
         DateTime dtStartDateTime;
         DateTime dtEndDateTime;
         int iTimeLogID = 0;

         for (dtEndDateTime = taskLogEntry.TaskDate.AddTicks(863990000000), dtStartDateTime = taskLogEntry.TaskDate.AddDays(1);
              dtEndDateTime.Date <= DateTime.Today;
              dtEndDateTime = dtEndDateTime.AddDays(1), dtStartDateTime = dtStartDateTime.AddDays(1))
         {
            if (dtEndDateTime.Date == DateTime.Today)
            {
               iTimeLogID = TimeLogEntry.CreateStop(connection, iTimeLogID);
               if (iTimeLogID > 0)
               {
                  return (iTimeLogID);
               } // end if
               else
               {
                  return (0);
               } // end else
            } // end if
            else
            {
               iTimeLogID = TimeLogEntry.Create(connection, dtEndDateTime, ActionTypes.Stop, taskLogEntry.TaskLogID);
               if (iTimeLogID > 0)
               {
                  iTimeLogID = Start.Execute(connection, dtStartDateTime, taskLogEntry.UserID, taskLogEntry.Task.TaskID);
                  if (iTimeLogID <= 0)
                  {
                     return (0);
                  }
               } // end if
               else
               {
                  return (0);
               } // end else
            } // end else
         } // end for

         return (iTimeLogID);
      } // end HandleDayOverlaps
Esempio n. 10
0
        protected TimeLogEntry InsertTimeLogEntry(string entryText, DateTime fromTime, DateTime toTime, Guid pollId = default)
        {
            var pollIdToUse = (pollId == default) ? DefaultPollId : pollId;

            var entry = new TimeLogEntry
            {
                Id        = Guid.NewGuid(),
                PollId    = pollIdToUse,
                EntryText = entryText,
                FromTime  = fromTime,
                ToTime    = toTime,

                TimeZone       = "Some time zone",
                TimeZoneOffset = TimeSpan.FromHours(-2),

                CreatedTimeUtc = fromTime.AddSeconds(3),
            };

            Db.Mock.TimeLogEntries.QueryData.Add(entry);
            return(entry);
        }
Esempio n. 11
0
      } // end Execute

      public static int Execute(Connection connection, string sUserId)
      {
         TimeLogEntry timeLogEntry;
         int iTimeLogID;

         connection.BeginTransaction();

         timeLogEntry = TimeLogEntry.LoadActive(connection, sUserId);
         if (timeLogEntry == null)
         {
            connection.RollbackTransaction();

            return (0);
         } // end if
         else
         {
            if (timeLogEntry.ActionTime.Date == DateTime.Today)
            {
               iTimeLogID = TimeLogEntry.CreateStop(connection, timeLogEntry.TimeLogID);
            } // end if
            else
            {
               iTimeLogID = HandleDayOverlaps(connection, timeLogEntry.TaskLogEntry);
            } // end else

            if (iTimeLogID > 0)
            {
               connection.CommitTransaction();

               return (iTimeLogID);
            } // end if
            else
            {
               connection.RollbackTransaction();

               return (0);
            } // end else
         } // end else
      } // end Execute
Esempio n. 12
0
        private void DeleteEntry(object sender, EventArgs e)
        {
            DataRow[] rows;
            int       iResult;

            if (_grdTimeEntry.SelectedRows.Count == 0)
            {
                MessageBox.Show(this, "Please select at least one row.", "Time Entry Deletion Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                rows = new DataRow[_grdTimeEntry.SelectedRows.Count];

                for (int i = 0; i < _grdTimeEntry.SelectedRows.Count; i++)
                {
                    rows[i] = ((DataRowView)_grdTimeEntry.SelectedRows[i].DataBoundItem).Row;
                }

                try
                {
                    iResult = TimeLogEntry.Delete(_connection, rows);
                    if (iResult == _grdTimeEntry.SelectedRows.Count)
                    {
                        RefreshReportView(null, null);
                    }
                    else
                    {
                        MessageBox.Show(this, "Unable to delete selected rows.", "Time Entry Deletion Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, "Unable to delete selected rows [Details:  " + ex.Message + "].", "Time Entry Deletion Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender)
        {
            base.PrepareForSegue(segue, sender);

            if (segue.Identifier == "eachTimeLogSegue")
            {
                var destVc  = segue.DestinationViewController as TimelogDetailViewController;
                var rowPath = TaskTimeLogTable.IndexPathForSelectedRow;
                destVc.isAddingMode = false;
                destVc.owner        = this;
                destVc.timeLogEntry = timeLogCache[rowPath.Row];
            }
            if (segue.Identifier == "AddTimeLogSegue")
            {
                var          destVc     = segue.DestinationViewController as TimelogDetailViewController;
                TimeLogEntry newTimeLog = new TimeLogEntry();
                newTimeLog.Task      = task;
                newTimeLog.StartDate = DateTime.UtcNow;
                destVc.timeLogEntry  = newTimeLog;
                destVc.isAddingMode  = true;
                destVc.owner         = this;
            }
        }
Esempio n. 14
0
        private bool isActiveTimeLog(TimeLogEntry log)
        {
            TimeLoggingController tlc = TimeLoggingController.GetInstance();

            return(tlc.IsTimerRunning() && tlc.GetActiveTimeLogEntryId().Equals(log.Id.ToString()));
        }
Esempio n. 15
0
        public async Task Update(MainDbContext db, Guid pollId, TimeLogUpdateRequest req)
        {
            if ((req.Deletions == null || req.Deletions.Count == 0) &&
                (req.Additions == null || req.Additions.Count == 0))
            {
                throw new BadRequestException("Must provide additions or deletions.");
            }

            var createdTimeUtc = _timeService.UtcNow;

            // Process deletions.
            if (req.Deletions != null)
            {
                var sortedDeletions        = req.Deletions.OrderByDescending(d => d.ToTime).ToList();
                var deletionEntries        = new List <TimeLogEntry>(sortedDeletions.Count);
                var deletionCreatedTimeUtc = createdTimeUtc - TimeSpan.FromMilliseconds(1);

                TimeLogEntry currentEntry = null;

                for (var i = 0; i < sortedDeletions.Count; i++)
                {
                    var deletion = sortedDeletions[i];

                    // Adjust and validate time ranges.
                    var fromTime = ToStartOfMinute(deletion.FromTime);
                    var toTime   = ToStartOfMinute(deletion.ToTime);

                    if (fromTime >= toTime)
                    {
                        throw new BadRequestException(
                                  $"'fromTime' must be before 'toTime' after truncating to the start of minute. " +
                                  $"In deletion at position {i + 1} found 'fromTime': '{fromTime}', " +
                                  $"'toTime': {toTime}.");
                    }

                    // See if we need to extend the range or start a new one.
                    // We don't need to compare fromTime or currentEntry.ToTime because
                    // the entries are sorted by toTime desc.
                    if (currentEntry != null && toTime >= currentEntry.FromTime)
                    {
                        // The entries overlap. Combine them into a single entry.
                        currentEntry.FromTime = fromTime;
                    }
                    else
                    {
                        // Need to start a new entry.
                        if (currentEntry != null)
                        {
                            db.TimeLogEntries.Add(currentEntry);
                        }

                        currentEntry = new TimeLogEntry
                        {
                            Id             = Guid.NewGuid(),
                            FromTime       = fromTime,
                            ToTime         = toTime,
                            EntryText      = "[deletion]",
                            TimeZone       = deletion.TimeZone,
                            TimeZoneOffset = deletion.TimeZoneOffset,
                            CreatedTimeUtc = deletionCreatedTimeUtc,
                            IsDeletion     = true,
                            PollId         = pollId,
                        };
                    }
                }

                // Save the last deletion.
                if (currentEntry != null)
                {
                    db.TimeLogEntries.Add(currentEntry);
                }
            }

            // Process additions.
            if (req.Additions != null)
            {
                for (int i = 0; i < req.Additions.Count; i++)
                {
                    var additionReq = req.Additions[i];
                    ValidatePollResponseAddRequest(additionReq, i);

                    // Round down to the nearest minute.
                    var savedFromTime = ToStartOfMinute(additionReq.TimeCollected);

                    var newEntry = new TimeLogEntry
                    {
                        Id             = Guid.NewGuid(),
                        PollId         = pollId,
                        FromTime       = savedFromTime,
                        ToTime         = savedFromTime + additionReq.TimeBlockLength,
                        EntryText      = additionReq.ResponseText,
                        CreatedTimeUtc = createdTimeUtc,
                        TimeZone       = additionReq.TimeZone,
                        TimeZoneOffset = additionReq.TimeZoneOffset,
                        SubmissionType = additionReq.SubmissionType,
                    };

                    db.TimeLogEntries.Add(newEntry);
                }
            }

            await db.SaveChangesAsync();
        }
Esempio n. 16
0
        public async Task Delete(MainDbContext db, Guid pollId, TimeLogDeleteRequest req)
        {
            if (req.Deletions == null)
            {
                throw new BadRequestException("'deletions' field is not optional.");
            }

            var sortedDeletions = req.Deletions.OrderByDescending(d => d.ToTime).ToList();
            var deletionEntries = new List <TimeLogEntry>(sortedDeletions.Count);

            TimeLogEntry currentEntry   = null;
            var          createdTimeUtc = _timeService.UtcNow;

            for (var i = 0; i < sortedDeletions.Count; i++)
            {
                var deletion = sortedDeletions[i];

                // Adjust and validate time ranges.
                var fromTime = ToStartOfMinute(deletion.FromTime);
                var toTime   = ToStartOfMinute(deletion.ToTime);

                if (fromTime >= toTime)
                {
                    throw new BadRequestException(
                              $"'fromTime' must be before 'toTime' after truncating to the start of minute. " +
                              $"In deletion at position {i + 1} found 'fromTime': '{fromTime}', " +
                              $"'toTime': {toTime}.");
                }

                // See if we need to extend the range or start a new one.
                // We don't need to compare fromTime or currentEntry.ToTime because
                // the entries are sorted by toTime desc.
                if (currentEntry != null && toTime >= currentEntry.FromTime)
                {
                    // The entries overlap. Combine them into a single entry.
                    currentEntry.FromTime = fromTime;
                }
                else
                {
                    // Need to start a new entry.
                    if (currentEntry != null)
                    {
                        db.TimeLogEntries.Add(currentEntry);
                    }

                    currentEntry = new TimeLogEntry
                    {
                        Id             = Guid.NewGuid(),
                        FromTime       = fromTime,
                        ToTime         = toTime,
                        EntryText      = "[deletion]",
                        TimeZone       = deletion.TimeZone,
                        TimeZoneOffset = deletion.TimeZoneOffset,
                        CreatedTimeUtc = createdTimeUtc,
                        IsDeletion     = true,
                        PollId         = pollId,
                    };
                }
            }

            // Save the last entry.
            if (currentEntry != null)
            {
                db.TimeLogEntries.Add(currentEntry);
            }

            await db.SaveChangesAsync();

            return;
        }
Esempio n. 17
0
        }     // end Execute

        public static int Execute(Connection connection, DateTime dtStartTime, string sUserId, int iTaskID)
        {
            return(TimeLogEntry.Create(connection, dtStartTime, ActionTypes.Start, sUserId, iTaskID));
        } // end Execute
 public void TimeLogEditCallBack(string projectname, string taskName, string taskId, TimeLogEntry timelogId)
 {
     //  throw new NotImplementedException();
     _timeLogDetailFragment = new TimeLogDetail();
     _timeLogDetailFragment.SetData(projectname, taskName, taskId, timelogId);
     SwitchToFragment(FragmentTypes.Globaltimelogdetails);
 }