示例#1
0
 public bool Add(ProjectDescription desc)
 {
     if (ProjectsDict.ContainsKey(desc.ProjectID))
     {
         ProjectsDict [desc.ProjectID] = desc;
     }
     else
     {
         ProjectsDict.Add(desc.ProjectID, desc);
     }
     return(Save());
 }
        private void logChanges(Tasks t, Guid userID)
        {
            string log           = string.Empty;
            string Delimiterline = string.Empty;

            if (t.ChangeTracker.State == ObjectState.Modified)
            {
                if (t.ChangeTracker.ChangedProperties.Count > 0)
                {
                    DateTime?dateClosed = t.dateClosed;
                    Delimiterline = getLogDelimiterLine(logDelimiterMode.Modified, userID, t.taskName);
                    foreach (string changedProperty in t.ChangeTracker.ChangedProperties)
                    {
                        PropertyInfo piInstance =
                            typeof(Tasks).GetProperty(changedProperty);
                        var    val          = piInstance.GetValue(t, null);
                        string currentValue = string.Empty;
                        if (val != null)
                        {
                            currentValue = val.ToString();
                        }

                        switch (changedProperty.ToLower())
                        {
                        case "taskstatusid":
                            if (currentValue.Length == 0)
                            {
                                log += string.Format("Status Cleared{0}", Environment.NewLine);
                            }
                            else
                            {
                                if (Int32.Parse(currentValue) == 4)     //finished
                                {
                                    dateClosed = DateTime.Now;
                                }
                                log += string.Format("Status changed to '{0}'{1}", StatusDict[Int32.Parse(currentValue)], Environment.NewLine);
                            }

                            break;

                        case "requesterid":
                            if (currentValue.Length == 0)
                            {
                                log += string.Format("Requested by Cleared{0}", Environment.NewLine);
                            }
                            else
                            {
                                log += string.Format("Requester changed to '{0}'{1}", UsersDict[Guid.Parse(currentValue)].userName, Environment.NewLine);
                            }
                            break;

                        case "projectid":
                            if (currentValue.Length == 0)
                            {
                                log += string.Format("Project Cleared{0}", Environment.NewLine);
                            }
                            else
                            {
                                if (ProjectsDict.ContainsKey(Guid.Parse(currentValue)))
                                {
                                    log += string.Format("Project changed to '{0}'{1}", ProjectsDict[Guid.Parse(currentValue)], Environment.NewLine);
                                }
                            }
                            break;

                        case "remarks":
                            log += string.Format("Remarks Change{0}", Environment.NewLine);
                            break;

                        case "priority":
                            //skip logging changes in priority
                            break;

                        case "userid":
                            log += string.Format("Task was assigned to: '{0}'{1}", UsersDict[Guid.Parse(currentValue)].userName, Environment.NewLine);
                            break;

                        default:
                            if (changedProperty.ToLower() != "updateslog")
                            {
                                log += string.Format("'{0}' changed to : '{1}'{2}", changedProperty, currentValue, Environment.NewLine);
                            }
                            break;
                        }
                    }
                    t.dateClosed = dateClosed;
                }
            }
            else if (t.ChangeTracker.State == ObjectState.Added)
            {
                t.dateEntered = DateTime.Now;
                log           = getLogDelimiterLine(logDelimiterMode.Added, userID, t.taskName); //string.Format("{0}{1}{2} - Added by '{3}':{4}{5}{6}", LINE_DELIMITER, Environment.NewLine, DateTime.Now, friendlyUserName, Environment.NewLine, LINE_DELIMITER, Environment.NewLine);
            }
            if (log.Length > 0)
            {
                t.UpdatesLog = Delimiterline + log + t.UpdatesLog;
            }
        }