示例#1
0
        public static SaveMap SoftDeleteMap(this SaveMap saveMap, int loggedInUserId)
        {
            var predicate =
                saveMap
                .Where(map => typeof(ISoftDelete)
                       .IsAssignableFrom(map.Key))
                .SelectMany(map => map.Value)
                .Select(info => info);

            foreach (var info in predicate)
            {
                var softDeletable = info.Entity as ISoftDelete;

                Contract.Assert(softDeletable != null);

                softDeletable.DeletedById = loggedInUserId;
                softDeletable.DeletedDate = DateTime.Now;
                softDeletable.IsDeleted   = true;

                if (info.OriginalValuesMap == null)
                {
                    continue;
                }

                info.OriginalValuesMap["DeletedById"] = null;
                info.OriginalValuesMap["DeletedDate"] = null;
                info.OriginalValuesMap["IsDeleted"]   = null;
            }

            return(saveMap);
        }
示例#2
0
        public static SaveMap AuditMap(this SaveMap saveMap, int loggedInUserId)
        {
            var predicate =
                saveMap
                .Where(map => typeof(IAuditable)
                       .IsAssignableFrom(map.Key))
                .SelectMany(map => map.Value)
                .Select(info => info);

            foreach (var info in predicate)
            {
                var auditable = info.Entity as IAuditable;

                Contract.Assert(auditable != null);

                auditable.ModifiedById = loggedInUserId;
                auditable.ModifiedDate = DateTime.Now;

                if (info.OriginalValuesMap == null)
                {
                    continue;
                }

                info.OriginalValuesMap["ModifiedById"] = null;
                info.OriginalValuesMap["ModifiedDate"] = null;
            }

            return(saveMap);
        }
        public SaveMap BeforeSaveEntities(SaveMap saveMap)
        {
            var unAuthorizedMaps = saveMap.Where(map => map.Key != _tWg &&
                                                 map.Key != _tFacComment &&
                                                 map.Key != _tFacStratResp &&
                                                 map.Key != _tFacSpResp &&
                                                 map.Key != _tStudCommentFlag &&
                                                 map.Key != _tFacCommentFlag)
                                   .ToList();

            //.Select(map => map.Key);

            saveMap.RemoveMaps(unAuthorizedMaps);

            var courseMonitorEntities = saveMap.MonitorCourseMaps()?.ToList();

            //if (courseMonitorEntities != null) ProcessCourseMonitoredMaps(courseMonitorEntities);

            var workGroupMonitorEntities = saveMap.MonitorWgMaps()?.ToList();

            //if (workGroupMonitorEntities != null) ProcessWorkGroupMonitoredMaps(workGroupMonitorEntities);

            //moved processing for monitored entities to monitoredguard
            if (courseMonitorEntities != null || workGroupMonitorEntities != null)
            {
                var monitoredGuard = new MonitoredGuard(ctxManager);

                if (courseMonitorEntities != null)
                {
                    monitoredGuard.ProcessCourseMonitoredMaps(courseMonitorEntities);
                }

                if (workGroupMonitorEntities != null)
                {
                    monitoredGuard.ProcessFacultyWorkGroupMonitoredMaps(workGroupMonitorEntities);
                }
            }

            if (saveMap.ContainsKey(_tWg))
            {
                var workGroupMap = ProcessWorkGroup(saveMap[_tWg]);
                saveMap.MergeMap(workGroupMap);
            }

            if (saveMap.ContainsKey(_tFacComment))
            {
                ProcessComments(saveMap[_tFacComment]);
            }

            saveMap.AuditMap(loggedInUser.PersonId);
            saveMap.SoftDeleteMap(loggedInUser.PersonId);
            return(saveMap);
        }
示例#4
0
        public static IEnumerable <EntityInfo> MonitorCourseMaps(this SaveMap saveMap)
        {
            //Is there anything to monitored?
            var anyCourseMonitors = saveMap.Keys.Where(key => typeof(ICourseMonitored).IsAssignableFrom(key)).ToList();

            if (!anyCourseMonitors.Any())
            {
                return(null);
            }

            return(saveMap.Where(map => anyCourseMonitors.Contains(map.Key))
                   .SelectMany(info => info.Value));
        }
示例#5
0
        public SaveMap BeforeSaveEntities(SaveMap saveMap)
        {
            var unAuthorizedMaps = saveMap.Where(map => map.Key != _tPerson &&
                                                 map.Key != _tProfileExternal &&
                                                 map.Key != _tProfileFaculty &&
                                                 map.Key != _tProfileStudent &&
                                                 map.Key != _tProfileSecurity &&
                                                 map.Key != _tProfileStaff &&
                                                 map.Key != _tCogResponse &&
                                                 map.Key != _tCogEcpeResult &&
                                                 map.Key != _tCogEsalbResult &&
                                                 map.Key != _tCogEtmpreResult &&
                                                 map.Key != _tCogEcmspeResult &&
                                                 map.Key != _tRoadRunner)
                                   .ToList();

            saveMap.RemoveMaps(unAuthorizedMaps);

            saveMap.AuditMap(loggedInUser.PersonId);
            saveMap.SoftDeleteMap(loggedInUser.PersonId);
            return(saveMap);
        }
示例#6
0
        public SaveMap BeforeSaveEntities(SaveMap saveMap)
        {
            var unAuthorizedMaps = saveMap.Where(map => map.Key != tStudComment &&
                                                 map.Key != tSpResponse &&
                                                 map.Key != tStudInGroup &&
                                                 map.Key != tStratResponse &&
                                                 map.Key != tStudCommentFlag)
                                   .ToList();

            saveMap.RemoveMaps(unAuthorizedMaps);

            //Process any monitored entities to see if saves are allowed.
            var courseMonitorEntities    = saveMap.MonitorCourseMaps()?.ToList();
            var workGroupMonitorEntities = saveMap.MonitorWgMaps()?.ToList();

            if (courseMonitorEntities != null || workGroupMonitorEntities != null)
            {
                var monitorGuard = new MonitoredGuard(ctxManager);
                if (courseMonitorEntities != null)
                {
                    monitorGuard.ProcessCourseMonitoredMaps(courseMonitorEntities);
                }
                if (workGroupMonitorEntities != null)
                {
                    monitorGuard.ProcessStudentWorkGroupMonitoredMaps(workGroupMonitorEntities);
                }
            }

            //Process studInGroup to ensure that only the logged student' is being handled.
            if (saveMap.ContainsKey(tStudInGroup))
            {
                var infos = (from info in saveMap[tStudInGroup]
                             let sig = info.Entity as CrseStudentInGroup
                                       where sig != null && sig.StudentId == loggedInUserId
                                       where info.EntityState == EntityState.Modified
                                       where info.OriginalValuesMap.ContainsKey("HasAcknowledged")
                                       select info).ToList();

                if (infos.Any())
                {
                    foreach (var info in infos)
                    {
                        info.OriginalValuesMap = new Dictionary <string, object>()
                        {
                            { "HasAcknowledged", null }
                        };
                    }

                    saveMap[tStudInGroup] = infos;
                }
                else
                {
                    saveMap.Remove(tStudInGroup);
                }
            }

            if (saveMap.ContainsKey(tStudComment))
            {
                var newComments = saveMap[tStudComment]
                                  .Where(info => info.EntityState == EntityState.Added)
                                  .Select(info => info.Entity)
                                  .OfType <StudSpComment>()
                                  .ToList();

                foreach (var comment in newComments)
                {
                    comment.CreatedDate = DateTime.UtcNow;
                }
            }

            saveMap.AuditMap(loggedInUserId);
            saveMap.SoftDeleteMap(loggedInUserId);
            return(saveMap);
        }