Beispiel #1
0
        /// <summary>
        /// Gets the history list comparing one found on db and the intended update data
        /// </summary>
        /// <param name="activityTransfer"></param>
        /// <param name="isAdd"></param>
        /// <param name="activityRow"></param>
        /// <returns></returns>
        private Dictionary <string, HistoryEntry> GetUpdateHistoryList(ActivityTransfer activityTransfer, bool isAdd, Activity activityRow)
        {
            Dictionary <string, HistoryEntry> historyList = new Dictionary <string, HistoryEntry>();

            if (!isAdd)
            {
                historyList = GetHistoryList(activityTransfer, activityRow, isAdd);
            }
            return(historyList);
        }
Beispiel #2
0
        public ActivityTransfer GetMonitoringData(long activityId)
        {
            try
            {
                var activity = misContext.Activity
                               .Include(p => p.Awp)
                               .Include(p => p.ActStatus)
                               .Include(p => p.ActivityHistory)
                               .FirstOrDefault(p => p.ActivityId == activityId);

                if (activity == null)
                {
                    throw new Exception("Invalid Activity Id");
                }

                var transfer = new ActivityTransfer()
                {
                    ActivityId      = activity.ActivityId,
                    LastMonitorDate = activity.ActivityHistory == null ? null : activity.ActivityHistory.OrderByDescending(p => p.ActHistoryDate).Select(p => p.ActHistoryDate).FirstOrDefault(),
                    ActivityCode    = Helper.GetCode(new Activity()
                    {
                        ActivityId = activity.ActivityId, ActivityCodeSequence = activity.ActivityCodeSequence, Strategy = activity.Strategy, Unit = activity.Unit, Awp = activity.Awp, Dsp = activity.Dsp
                    }),
                    ReasonForDelay   = activity.ActivityDelayReason,
                    ImmeadiateAction = activity.ActivityImmediateAction,
                    ProgressNote     = activity.ActivityProgress,
                    NewTimeFrame     = activity.ActivityNewTimeframeDate,
                    StatusName       = activity.ActStatus == null ? "" : activity.ActStatus.ActStatusName,
                    StatusId         = activity.ActStatusId,
                };

                long?lastMonitoredById = activity.ActivityHistory == null ? null : activity.ActivityHistory.OrderByDescending(p => p.ActHistoryDate).Select(p => p.UserId).FirstOrDefault();
                transfer.LastMonitoredByUserName = lastMonitoredById == null ? null : misContext.UserApplication.Where(p => p.UserId == lastMonitoredById).Select(p => string.Format("{0} {1}", p.UserFirstName, p.UserLastName)).FirstOrDefault();
                transfer.MonitoringHistoryList   = misContext.ActivityHistory.Include(p => p.User).Where(p => p.ActivityId == activityId).OrderByDescending(p => p.ActHistoryDate).ToList();

                return(transfer);
            }
            catch (Exception ex)
            {
                var tt = ex;
                //logService.SaveLog(lookupUser.CurrentUser.UserId, LogType.Error, MISPage.ActivityPage, ex, Method.SaveActivity);
                return(null);
            }
        }
Beispiel #3
0
        public ActivityTransfer GetActivity(long activityId)
        {
            try
            {
                var activity = misContext.Activity
                               .Include(p => p.Strategy)
                               .Include(p => p.Unit)
                               .Include(p => p.Dsp)
                               .Include(p => p.Section)
                               .Include(p => p.Awp)
                               .Include(p => p.ActStatus)
                               .Include(p => p.UserIdActivityLeaderNavigation)
                               .Include(p => p.Priority)
                               .Include(p => p.GroupActivity)
                               .Include(p => p.Project)
                               .Include(p => p.Expense)
                               .ThenInclude(e => e.BudgetLine)
                               .Include(p => p.Expense)
                               .ThenInclude(e => e.ExpenseType)
                               .FirstOrDefault(p => p.ActivityId == activityId);

                if (activity == null)
                {
                    throw new Exception("Invalid Activity Id");
                }

                long awpId = activity.AWPId.GetValueOrDefault();

                var transfer = new ActivityTransfer()
                {
                    ActivityCode     = Helper.GetCode(activity),
                    ActivityName     = activity.ActivityName,
                    ActivityId       = activity.ActivityId,
                    DateAdded        = activity.DateAdded,
                    StatusIcon       = activity.ActStatus.ActStatusImgPath.Replace("gif", "png").Replace("~", ""),
                    ActivityLeader   = activity.UserIdActivityLeaderNavigation == null ? "" : activity.UserIdActivityLeaderNavigation.UserFirstName + " " + activity.UserIdActivityLeaderNavigation.UserLastName,
                    ActivityLeaderId = activity.UserIdActivityLeader.GetValueOrDefault(),

                    ActivityDescription = activity.ActivityDescription,
                    AwpName             = activity.Awp == null ? "" : activity.Awp.AWPName,
                    AwpId             = activity.AWPId.GetValueOrDefault(),
                    StrategyCode      = activity.Strategy == null ? "" : activity.Strategy.StartegyName,
                    StrategyId        = activity.StrategyId.GetValueOrDefault(),
                    UnitCode          = activity.Unit == null ? "" : activity.Unit.UnitCode,
                    UnitId            = activity.UnitId.GetValueOrDefault(),
                    DpCode            = activity.Dsp == null ? "" : activity.Dsp.DspCode,
                    DpId              = activity.DSPId.GetValueOrDefault(),
                    SectionCode       = activity.Section == null ? "" : activity.Section.SectionCode,
                    SectionId         = activity.SectionId.GetValueOrDefault(),
                    StartDate         = activity.ActivityStartDate,
                    EndDate           = activity.ActivityEndDate,
                    CapacityLevelId   = activity.PriorityId,
                    CapacityLevel     = activity.Priority == null ? "" : activity.Priority.PriorityName,
                    Project           = activity.Project == null ? "" : activity.Project.ProjectName,
                    FunctionalGroup   = activity.GroupActivity == null ? "" : activity.GroupActivity.GroupActivityName,
                    FunctionalGroupId = activity.GroupActivityId.GetValueOrDefault(),

                    IsPublicHealthTraining = activity.ActivityIsPublicHealthTraining,
                    IsPrepardness          = activity.ActivityIsPrepardness,
                    IsICT                  = activity.ActivityIsIct,
                    IsHealthCom            = activity.ActivityIsHealthCom,
                    IsEnlargementCountries = activity.ActivityIsEnlargementCountries,
                    IsEnpCountries         = activity.ActivityIsEnpCountries,
                    IsOtherThirdCountries  = activity.ActivityIsOtherThirdCountries,

                    LastMonitorDate         = activity.ActivityHistory == null ? null : activity.ActivityHistory.OrderByDescending(p => p.ActHistoryDate).Select(p => p.ActHistoryDate).FirstOrDefault(),
                    LastMonitoredByUserName = activity.ActivityHistory == null ? null : activity.ActivityHistory.OrderByDescending(p => p.ActHistoryDate).Select(p => string.Format("{0} {1}", p.User.UserFirstName, p.User.UserLastName)).FirstOrDefault(),

                    ReasonForDelay   = activity.ActivityDelayReason,
                    ImmeadiateAction = activity.ActivityImmediateAction,
                    ProgressNote     = activity.ActivityProgress,
                    NewTimeFrame     = activity.ActivityNewTimeframeDate,
                    StatusName       = activity.ActStatus == null ? "" : activity.ActStatus.ActStatusName,
                    StatusId         = activity.ActStatusId,
                };

                transfer.ExpenseList           = GetExpenseList(activity.ActivityId);
                transfer.ActivityLeaderPicture = Helper.SetUserPicture(activity.UserIdActivityLeaderNavigation, defaultUserPictureUrl);
                return(transfer);
            }
            catch (Exception ex)
            {
                var ttt = ex;
                //logService.SaveLog(lookupUser.CurrentUser.UserId, LogType.Error, MISPage.ActivityPage, ex, Method.SaveActivity);
                return(null);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Gets a history list which shows the values of monitoring fields before the new changes (if any) are made
        /// </summary>
        /// <param name="activityTransfer">The transfer item with new data</param>
        /// <param name="activityRow">The row being modified or added to db</param>
        /// <param name="isAdd">The current save mode for the activity</param>
        /// <returns>A dic with changes catergorised by what changed</returns>
        private Dictionary <string, HistoryEntry> GetHistoryList(ActivityTransfer activityTransfer, Activity activityRow, bool isAdd)
        {
            Dictionary <string, HistoryEntry> historyList = new Dictionary <string, HistoryEntry>();

            if (isAdd)
            {
                return(historyList);
            }

            if ((activityRow.ActStatusId == null || activityRow.ActStatusId == 0))
            {
                string       historyElementType = "Status";
                HistoryEntry entry = new HistoryEntry()
                {
                    FromValue = "", ToValue = activityTransfer.StatusName, ChangeArea = historyElementType
                };
                historyList.Add(historyElementType, entry);
            }
            else
            {
                if (activityRow.ActStatusId != activityTransfer.StatusId)
                {
                    string       historyElementType = "Status";
                    HistoryEntry entry = new HistoryEntry()
                    {
                        FromValue = activityRow.ActStatus.ActStatusName, ToValue = activityTransfer.StatusName, ChangeArea = historyElementType
                    };
                    historyList.Add(historyElementType, entry);
                }
            }

            if (activityRow.ActivityImmediateAction != activityTransfer.ImmeadiateAction)
            {
                string       historyElementType = "Immediate Action";
                HistoryEntry entry = new HistoryEntry()
                {
                    FromValue = activityRow.ActivityImmediateAction, ToValue = activityTransfer.ImmeadiateAction, ChangeArea = historyElementType
                };
                historyList.Add(historyElementType, entry);
            }
            activityRow.ActivityImmediateAction = activityTransfer.ImmeadiateAction;

            if (!isAdd && activityRow.ActivityNewTimeframeDate != activityTransfer.NewTimeFrame)
            {
                string       historyElementType = "New start Date";
                HistoryEntry entry = new HistoryEntry()
                {
                    FromValue  = activityRow.ActivityNewTimeframeDate == null ? "--" : activityRow.ActivityNewTimeframeDate.GetValueOrDefault().ToShortDateString(),
                    ToValue    = activityTransfer.NewTimeFrame.GetValueOrDefault().ToShortDateString(),
                    ChangeArea = historyElementType
                };
                historyList.Add(historyElementType, entry);
            }
            activityRow.ActivityNewTimeframeDate = activityTransfer.NewTimeFrame;

            if (!isAdd && activityRow.ActivityDelayReason != activityTransfer.ReasonForDelay)
            {
                string       historyElementType = "Reason for Delay";
                HistoryEntry entry = new HistoryEntry()
                {
                    FromValue = activityRow.ActivityDelayReason, ToValue = activityTransfer.ReasonForDelay, ChangeArea = historyElementType
                };
                historyList.Add(historyElementType, entry);
            }
            activityRow.ActivityDelayReason = activityTransfer.ReasonForDelay;

            if (!isAdd && activityRow.ActivityProgress != activityTransfer.ProgressNote)
            {
                string       historyElementType = "Progress";
                HistoryEntry entry = new HistoryEntry()
                {
                    FromValue = activityRow.ActivityProgress, ToValue = activityTransfer.ProgressNote, ChangeArea = historyElementType
                };
                historyList.Add(historyElementType, entry);
            }
            activityRow.ActivityProgress = activityTransfer.ProgressNote;

            return(historyList);
        }
Beispiel #5
0
        public long Post([FromBody] ActivityTransfer activityTransfer)
        {
            try
            {
                Activity activity = misContext.Activity
                                    .Include(p => p.ActStatus)
                                    .Where(p => p.ActivityId == activityTransfer.ActivityId).FirstOrDefault();

                bool isAdd = false;
                if (activity == null)
                {
                    isAdd    = true;
                    activity = new Activity()
                    {
                        UserAdded           = currentUser.UserId,
                        DateAdded           = DateTime.Now,
                        ActivityIsRequested = false,
                        ActivityIsValidated = false,
                        ActivityIsForReview = false,
                        ActStatusId         = 5,
                        ActAppStatusId      = 5,
                        ActivityStartDate   = new DateTime(DateTime.Now.Year, 1, 1),
                        ActivityEndDate     = new DateTime(DateTime.Now.Year, 12, 31)
                    };
                }
                else
                {
                    activity.DateMod = DateTime.Now;
                    activity.UserMod = currentUser.UserId;
                }

                //Save history data
                Dictionary <string, HistoryEntry> historyList = GetUpdateHistoryList(activityTransfer, isAdd, activity);
                if (!isAdd)
                {
                    AddActivityHistoryEntry(activity, historyList, activity.UserMod);
                }

                //LastMonitorDate = activity.ActivityHistory == null ? null : activity.ActivityHistory.OrderByDescending(p => p.ActHistoryDate).Select(p => p.ActHistoryDate).FirstOrDefault(),
                //LastMonitoredByUserName = activity.ActivityHistory == null ? null : activity.ActivityHistory.OrderByDescending(p => p.ActHistoryDate).Select(p => string.Format("{0} {1}", p.User.UserFirstName, p.User.UserLastName)).FirstOrDefault(),

                activity.ActivityDelayReason      = activity.ActivityDelayReason = activityTransfer.ReasonForDelay;
                activity.ActivityImmediateAction  = activityTransfer.ImmeadiateAction;
                activity.ActivityProgress         = activityTransfer.ProgressNote;
                activity.ActivityNewTimeframeDate = activityTransfer.NewTimeFrame;
                activity.ActStatusId = activityTransfer.StatusId;

                if (isAdd)
                {
                    misContext.Entry(activity).State = EntityState.Added;
                    misContext.Add(activity);
                }
                else
                {
                    misContext.Entry(activity).State = EntityState.Modified;
                }

                misContext.SaveChanges();
                return(activity.ActivityId);
            }
            catch (Exception ex)
            {
                var tt = ex;
                //logService.SaveLog(lookupUser.CurrentUser.UserId, LogType.Error, MISPage.ActivityPage, ex, Method.MonitorActivity);
                return(0);
            }
        }