Example #1
0
        public static List <ValidationMessage> RemoveTimeEntry(
            ValidatableParameter <Guid> timeEntryId
            )
        {
            List <ValidationMessage> errors = new List <ValidationMessage>();

            if (timeEntryId.Value == Guid.Empty)
            {
                errors.Add(new ValidationMessage {
                    MessageText = "Time Entry must be supplied", Source = timeEntryId.Source
                });
            }

            //perform add if no errors
            if (errors.Count == 0)
            {
                AllTimeEntry items     = new AllTimeEntry();
                TimeEntry    existItem = items.Where(i => i.TimeEntryId == timeEntryId.Value).Single();

                if (existItem != null)
                {
                    items.Remove(existItem);
                }

                items.Save();
            }

            return(errors);
        }
Example #2
0
        public static List <ReportingItemSummary> GetReportingItems(DateTime startDate, DateTime endDate, IEnumerable <string> fileNames)
        {
            //get all projects, tasks and users for efficiency (rather than looking each one up from file each time)
            List <Project> projs = OperationsReadOnly.GetAllProjects();
            List <Task>    tasks = OperationsReadOnly.GetAllTasks();
            List <User>    users = OperationsReadOnly.GetAllUsers();

            List <ReportingItemSummary> results = new List <ReportingItemSummary>();

            foreach (string currFile in fileNames)
            {
                List <TimeEntry> entries = AllTimeEntry.GetBetween(startDate, endDate, true, currFile);

                foreach (TimeEntry currEntry in entries)
                {
                    ReportingItemSummary item = new ReportingItemSummary();
                    item.Details          = currEntry.Details;
                    item.EndDateTime      = currEntry.EndDateTime;
                    item.ExceptionDetails = currEntry.ExceptionDetails;
                    item.ExceptionMinutes = currEntry.ExceptionMinutes;
                    item.ProjectId        = currEntry.ProjectId;
                    Project prj = projs.Where(i => i.Id == currEntry.ProjectId).FirstOrDefault();
                    item.ProjectName   = prj == null ? string.Empty : prj.Description;
                    item.StartDateTime = currEntry.StartDateTime;
                    item.TaskId        = currEntry.TaskId;
                    Task tsk = tasks.Where(i => i.Id == currEntry.TaskId).FirstOrDefault();
                    item.TaskName     = tsk == null ? string.Empty : tsk.Description;
                    item.TimeEntryId  = currEntry.TimeEntryId;
                    item.TotalMinutes = currEntry.TotalMinutesMinusExceptions;
                    User usr = users.Where(i => i.UserId == currEntry.UserId).FirstOrDefault();
                    item.UserDisplayName = usr == null ? string.Empty : usr.DisplayName;
                    item.UserId          = currEntry.UserId;

                    results.Add(item);
                }
            }

            return(results);
        }
Example #3
0
        public static List <ValidationMessage> SaveTimeEntry(
            ValidatableParameter <Guid> timeEntryId,
            ValidatableParameter <Guid> userId,
            ValidatableParameter <Guid> projectId,
            ValidatableParameter <Guid> taskId,
            ValidatableParameter <string> details,
            ValidatableParameter <DateTime?> startTime,
            ValidatableParameter <DateTime?> endTime,
            ValidatableParameter <int> exceptionMinutes,
            ValidatableParameter <string> exceptionDetail,
            out TimeEntry savedItem
            )
        {
            savedItem = null;

            List <ValidationMessage> errors = new List <ValidationMessage>();

            //check if user exists
            User usr = OperationsReadOnly.GetUser(userId.Value);

            if (usr == null)
            {
                errors.Add(new ValidationMessage {
                    MessageText = string.Format("User with id '{0}' was not found", userId.Value.ToString()), Source = userId.Source
                });
            }
            else
            {
                //check if project exists
                if (projectId.Value == Guid.Empty)
                {
                    errors.Add(new ValidationMessage {
                        MessageText = string.Format("Project must be selected"), Source = projectId.Source
                    });
                }
                else if (OperationsReadOnly.GetProjectForUser(projectId.Value, usr.UserId) == null)
                {
                    //check if project exists for user
                    errors.Add(new ValidationMessage {
                        MessageText = string.Format("Project with id '{0}' is not associated with User '{1}'", projectId.Value.ToString(), userId.Value.ToString()), Source = projectId.Source
                    });
                }

                //check if task exists
                if (taskId.Value == Guid.Empty)
                {
                    errors.Add(new ValidationMessage {
                        MessageText = string.Format("Task must be selected"), Source = taskId.Source
                    });
                }
                else if (OperationsReadOnly.GetTaskById(taskId.Value, projectId.Value, usr.UserId) == null)
                {
                    //check if project exists for user
                    errors.Add(new ValidationMessage {
                        MessageText = string.Format("Task with id '{0}' is not associated with Project '{1}' and/or User '{2}'", taskId.Value.ToString(), projectId.Value.ToString(), userId.Value.ToString()), Source = taskId.Source
                    });
                }
            }

            //check dates
            if (startTime.Value == null || !startTime.Value.HasValue)
            {
                errors.Add(new ValidationMessage {
                    MessageText = string.Format("Start time must be supplied"), Source = startTime.Source
                });
            }
            else if (endTime.Value == null || !endTime.Value.HasValue)
            {
                errors.Add(new ValidationMessage {
                    MessageText = string.Format("End time was not supplied"), Source = endTime.Source
                });
            }
            else
            {
                //we have both dates, compare
                if (startTime.Value >= endTime.Value)
                {
                    errors.Add(new ValidationMessage {
                        MessageText = string.Format("Start time must be before End time"), Source = startTime.Source
                    });
                    errors.Add(new ValidationMessage {
                        MessageText = string.Format("End time must be after Start time"), Source = endTime.Source
                    });
                }
                else
                {
                    //check for overlaps
                    List <TimeEntry> overlaps = OperationsReadOnly.GetTimeEntryForDateTimesRange(startTime.Value.Value, endTime.Value.Value, userId.Value);
                    if (overlaps != null && overlaps.Count > 0)
                    {
                        foreach (TimeEntry currItem in overlaps)
                        {
                            if (currItem.TimeEntryId != timeEntryId.Value)
                            {
                                if (currItem.StartDateTime < startTime.Value.Value)
                                {
                                    errors.Add(new ValidationMessage {
                                        MessageText = string.Format("Start time overlaps with another item, Project: {0}, Task: {1} with start time {2} and end time {3}", currItem.ProjectName, currItem.TaskName, currItem.StartDateTime.ToString(Constants.cstrDateFormatDisplay), currItem.EndDateTime.ToString(Constants.cstrDateFormatDisplay)), Source = startTime.Source
                                    });
                                }

                                if (currItem.EndDateTime > endTime.Value.Value)
                                {
                                    errors.Add(new ValidationMessage {
                                        MessageText = string.Format("End time overlaps with another item, Project: {0}, Task: {1} with start time {2} and end time {3}", currItem.ProjectName, currItem.TaskName, currItem.StartDateTime.ToString(Constants.cstrDateFormatDisplay), currItem.EndDateTime.ToString(Constants.cstrDateFormatDisplay)), Source = endTime.Source
                                    });
                                }
                            }
                        }
                    }

                    if (exceptionMinutes.Value > 0 && exceptionDetail.Value.Trim().Length == 0)
                    {
                        errors.Add(new ValidationMessage {
                            MessageText = string.Format("Subtract description text must be entered if period in minutes is to be recorded"), Source = exceptionDetail.Source
                        });
                    }

                    //check for minutes empty but text not
                    if (exceptionMinutes.Value <= 0 && exceptionDetail.Value.Trim().Length > 0)
                    {
                        errors.Add(new ValidationMessage {
                            MessageText = string.Format("Subtract period in minutes must be entered if text is be recorded"), Source = exceptionMinutes.Source
                        });
                    }

                    int timeDifferenceMinutes = Convert.ToInt32(endTime.Value.Value.Subtract(startTime.Value.Value).TotalMinutes);
                    if (exceptionMinutes.Value > timeDifferenceMinutes)
                    {
                        errors.Add(new ValidationMessage {
                            MessageText = string.Format("Subtract period in minutes must be less than the total number of minutes spent on the task"), Source = exceptionMinutes.Source
                        });
                    }


                    //if ( exceptionEntries != null && exceptionEntries.Count > 0 )
                    //{
                    //    //we have both dates, we can check exceptions
                    //    int timeDifferenceMinutes = Convert.ToInt32( endTime.Value.Value.Subtract( startTime.Value.Value ).TotalMinutes );

                    //    bool hadOneGreater = false;
                    //    int totalExceptionMinutes = 0;

                    //    foreach ( ValidatableIntStringPair currEx in exceptionEntries )
                    //    {
                    //        //Check for text empty but minutes not
                    //        if ( currEx.IntValue.Value > 0 && currEx.StringValue.Value.Trim().Length == 0 )
                    //        {
                    //            errors.Add( new ValidationMessage { MessageText = string.Format( "Exception text must be entered if period in minutes is to be recorded" ), Source = currEx.StringValue.Source } );
                    //        }

                    //        //check for minutes empty but text not
                    //        if ( currEx.IntValue.Value <= 0 && currEx.StringValue.Value.Trim().Length > 0 )
                    //        {
                    //            errors.Add( new ValidationMessage { MessageText = string.Format( "Exception period in minutes must be entered if text is be recorded" ), Source = currEx.IntValue.Source } );
                    //        }

                    //        //check if any one is greater then the actual task number of minutes
                    //        if ( currEx.IntValue.Value > 0 && currEx.IntValue.Value > timeDifferenceMinutes )
                    //        {
                    //            errors.Add( new ValidationMessage { MessageText = string.Format( "An exception period must be less than than the total time spent on the task" ), Source = currEx.IntValue.Source } );
                    //            hadOneGreater = true;
                    //        }

                    //        if ( !hadOneGreater && ( currEx.IntValue.Value > 0 ) )
                    //        {
                    //            //if not one single one was greater than the tiem difference, check if the total minutes is greater
                    //            //than the actual task number of minutes - If so attach error to it (any any after it)
                    //            totalExceptionMinutes += currEx.IntValue.Value;
                    //            if ( totalExceptionMinutes >= timeDifferenceMinutes )
                    //            {
                    //                errors.Add( new ValidationMessage { MessageText = string.Format( "The total exception period of all exceptions together must be less than the total time spent on the task" ), Source = currEx.IntValue.Source } );
                    //            }
                    //        }
                    //    }
                    //}
                }
            }

            if (errors.Count == 0)
            {
                AllTimeEntry dataItems = new AllTimeEntry();

                TimeEntry item = new TimeEntry {
                    EndDateTime = endTime.Value.Value, Details = details.Value, ProjectId = projectId.Value, StartDateTime = startTime.Value.Value, TaskId = taskId.Value, TimeEntryId = timeEntryId.Value, UserId = userId.Value, ExceptionDetails = exceptionDetail.Value, ExceptionMinutes = exceptionMinutes.Value
                };
                if (timeEntryId.Value != Guid.Empty)
                {
                    //update
                    TimeEntry updItem = dataItems.Where(i => i.TimeEntryId == item.TimeEntryId).SingleOrDefault();

                    if (updItem == null)
                    {
                        throw new ApplicationException(string.Format("Time entry with id '{0}' not found", timeEntryId.Value.ToString()));
                    }
                    else
                    {
                        //save it
                        dataItems.Remove(updItem);
                        dataItems.Add(item);
                    }
                }
                else
                {
                    //add time entry
                    item.TimeEntryId = Guid.NewGuid();  //set id
                    dataItems.Add(item);
                }

                dataItems.Save();
                savedItem = item; //set the saved item
            }

            return(errors);
        }
Example #4
0
        public static List <TimeEntry> GetAllTimeEntry()
        {
            AllTimeEntry entries = new AllTimeEntry();

            return(entries);
        }
Example #5
0
 public static TimeEntry GetTimeEntryById(Guid timeEntryId, User usr)
 {
     return(AllTimeEntry.GetEntryByIdForUser(usr.UserId, timeEntryId));
 }
Example #6
0
 public static TimeEntry GetLatestTimeEntry(User usr)
 {
     return(AllTimeEntry.GetLatestForUser(usr.UserId));
 }
Example #7
0
 public static List <TimeEntry> GetTimeEntryForDateTimesRange(DateTime startDate, DateTime endDate, Guid userId)
 {
     return(AllTimeEntry.GetForUserAndBetween(userId, startDate, endDate, false));
 }
Example #8
0
 public static List <TimeEntry> GetTimeEntryForDateRange(DateTime startDate, DateTime endDate, User usr)
 {
     return(AllTimeEntry.GetForUserAndBetween(usr.UserId, startDate, endDate, true));
 }
Example #9
0
 public static List <TimeEntry> GetTimeEntryForDate(DateTime selectedDate, User usr)
 {
     return(AllTimeEntry.GetForUserAndDateReverse(usr.UserId, selectedDate));
 }
Example #10
0
 public static List <TimeEntry> GetRecentTimeEntry(int maxNumber, User usr)
 {
     return(AllTimeEntry.GetForUserRecentReverse(usr.UserId, maxNumber));
 }