Beispiel #1
0
        private UpdateMessage GetDbStatus(string projectId)
        {
            UpdateMessage dbStatus = new UpdateMessage();

            var lastModified = _session.ProjectsLastModified.Where(pr => pr.ProjectId.Equals(projectId)).OrderByDescending(pr => pr.LastModified).FirstOrDefault();
            if (lastModified != null)
            {
                if (!lastModified.DumpCreated)
                {
                    dbStatus.Code = UpdateMessage.OK;
                }
                else
                {
                    dbStatus.Code = UpdateMessage.ERROR;
                    dbStatus.Description = "Tracker updates are not permitted at this time. Updates can be made once the data is refreshed in the morning.";
                }
            }

            return dbStatus;
        }
Beispiel #2
0
        private UpdateMessage UpdateTaskDate(DateTime? date, string taskName, string siteNumber, string userName, string projectId)
        {
            UpdateMessage message = new UpdateMessage();
            message.Code = UpdateMessage.OK;

            try
            {

                taskName = XmlConvert.DecodeName(taskName);
                string taskId = taskName.Replace("Task ", "").Replace(" Actual", "").Replace(" Forecasted", "");

                List<RolloutTracking> allTasksPerSite = _session.RolloutTracking.Where(rt => rt.SiteNumber.Trim().Equals(siteNumber))
                    .OrderBy(rt => rt.TaskId).ToList();

                if (date.HasValue)
                {
                    // Set the time of the updated date to be always at noon
                    // This will help us avoid issues with time zones
                    TimeSpan noon = new TimeSpan(12, 0, 0);
                    date = ((DateTime)date).Date + noon;

                    if (taskName.EndsWith("Forecasted"))
                    {
                        // Validte the FORECASTED date modification

                        // RULE = "Date is in the past - error"
                        if (message.Code == UpdateMessage.OK)
                        {
                            DateTime today = DateTime.Now;
                            // By making a .Date comparison between 2 DateTime objects, the time will be ignored
                            if (today.Date > date.Value.Date)
                            {
                                message.Code = UpdateMessage.ERROR;
                                message.Description = string.Format("Site {0} / Task {1} - Forecasted date cannot be in the past.", siteNumber, taskId);
                            }
                        }

                        // RULE = "Task has an actual date - error"
                        if (message.Code == UpdateMessage.OK)
                        {
                            RolloutTracking modifiedSite = allTasksPerSite.Where(rt => rt.TaskId.TrimEnd().Equals(taskId)).FirstOrDefault();
                            if (modifiedSite == null)
                            {
                                message.Code = UpdateMessage.ERROR;
                                message.Description = string.Format("Site {0} is not associated with Task {1}", siteNumber, taskId);
                            }
                            else if (modifiedSite.CompletedDate != null)
                            {
                                message.Code = UpdateMessage.ERROR;
                                message.Description = string.Format("Site {0} / Task {1} - Forecasted date cannot be modified because the Task has already a valid Actual date.", siteNumber, taskId);
                            }
                        }

                        // RULE = "Future date exceeds forecast date of downstream tasks - warning"
                        if (message.Code == UpdateMessage.OK)
                        {
                            IEnumerable<RolloutTracking> upStreamTasks = allTasksPerSite.Where(rt => string.Compare(rt.TaskId.TrimEnd(), taskId) > 0);
                            foreach (RolloutTracking rt in upStreamTasks)
                            {
                                // By making a .Date comparison between 2 DateTime objects, the time will be ignored
                                if (rt.ForecastDate != null && date.Value.Date > ((DateTime)rt.ForecastDate).Date)
                                {
                                    message.Code = UpdateMessage.WARNING;
                                    message.Description = string.Format("Site {0} / Task {1} - The selected Forecast date is greater than Task {2} ({3}) ",
                                                                        siteNumber, taskId, rt.TaskId.TrimEnd(), ((DateTime)rt.ForecastDate).ToShortDateString());
                                    break;
                                }
                            }
                        }

                        // RULE = "Future date is within 3 days of downstream tasks - warning"
                        if (message.Code == UpdateMessage.OK)
                        {
                            IEnumerable<RolloutTracking> upStreamTasks = allTasksPerSite.Where(rt => string.Compare(rt.TaskId.Trim(), taskId) > 0);
                            foreach (RolloutTracking rt in upStreamTasks)
                            {
                                if (rt.ForecastDate != null
                                    && date.Value.Date < ((DateTime)rt.ForecastDate).Date
                                    && date.Value.Date >= ((DateTime)rt.ForecastDate).AddDays(3).Date)
                                {
                                    message.Code = UpdateMessage.WARNING;
                                    message.Description = string.Format("Site {0} / Task {1} - The selected Forecast date is within 3 days of Task {2} ({3}) ",
                                                                        siteNumber, taskId, rt.TaskId.TrimEnd(), ((DateTime)rt.ForecastDate).ToShortDateString());
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        // Validate the ACTUAL date modification

                        // RULE = "Date is in the future - error"
                        if (message.Code == UpdateMessage.OK)
                        {
                            DateTime today = DateTime.Now;
                            if (today.Date < date.Value.Date)
                            {
                                message.Code = UpdateMessage.ERROR;
                                message.Description = string.Format("Site {0} / Task {1} - Actual date cannot be in the future.", siteNumber, taskId);
                            }
                        }

                        // RULE = "Predecessor has no actual date - warning"
                        if (message.Code == UpdateMessage.OK)
                        {
                            IEnumerable<RolloutTracking> downStreamNullActualTasks = allTasksPerSite.Where(rt => string.Compare(rt.TaskId.Trim(), taskId) < 0 && rt.CompletedDate == null);
                            if (downStreamNullActualTasks.Count() > 0)
                            {
                                message.Code = UpdateMessage.WARNING;
                                message.Description = string.Format("Site {0} / Task {1} - Not all the previous Milestones have been completed ({2})",
                                                                    siteNumber, taskId, downStreamNullActualTasks.Select(rt => rt.TaskId.TrimEnd()).ToArray<string>().Aggregate((i, j) => i + "," + j));
                            }
                        }
                    }
                }

                // Validation has finished


                // After validation, mark the modified DB entity as modified
                // Also, add an automated comment 

                if (message.Code == UpdateMessage.OK || message.Code == UpdateMessage.WARNING)
                {
                    // Mark the DB Entity as Modified
                    RolloutTracking modifiedEntity = allTasksPerSite.FirstOrDefault(rt => rt.TaskId.TrimEnd().Equals(taskId));

                    if (taskName.EndsWith("Actual"))
                    {
                        AddAutomaticComment(siteNumber, taskId, "ACTUAL", modifiedEntity.CompletedDate, date, userName, projectId);
                        modifiedEntity.CompletedDate = date;
                    }
                    else if (taskName.EndsWith("Forecasted"))
                    {
                        AddAutomaticComment(siteNumber, taskId, "FORECASTED", modifiedEntity.ForecastDate, date, userName, projectId);
                        modifiedEntity.ForecastDate = date;
                    }

                    //_session.Entry(modifiedEntity).State = EntityState.Modified;
                }
            }
            catch (Exception)
            {
                message.Code = UpdateMessage.ERROR;
                message.Description = "An unknown error has occured while updating.";
            }

            return message;
        }