当前位置: 首页>>代码示例>>C#>>正文


C# DataModel.SaveChanges方法代码示例

本文整理汇总了C#中DataModel.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# DataModel.SaveChanges方法的具体用法?C# DataModel.SaveChanges怎么用?C# DataModel.SaveChanges使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataModel的用法示例。


在下文中一共展示了DataModel.SaveChanges方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        public override void Execute(DataModel context, ILog log)
        {
            var scannedLearners = context.ScannedInLearners.ToList().Where(s => DateTime.Now - s.TimeIn > TimeSpan.FromHours(5));
            var scans = scannedLearners.Select(scannedLearner =>
               new LearnerScan()
               {
                   CreatedAt = DateTime.Now,
                   Activity = "Scanned Out",
                   Details = "Out (Automatic Midnight)",
                   ScanType = "Attendance",
                   Division = scannedLearner.Division,
                   LearnerNumber = scannedLearner.LearnerNumber,
                   Username = "System",
                   Session = scannedLearner.Session,
                   PartnerID = scannedLearner.LinkID
               }
            ).ToList();

            context.LearnerScans.AddRange(scans);
            context.SaveChanges();

            foreach (var scan in scans)
            {
                log.Info($"Scanning out learner: {scan.LearnerNumber} from {scan.Division}");
                if (scan.PartnerID == null) continue;
                var partner = context.LearnerScans.FirstOrDefault(s => s.ID == scan.PartnerID);
                if (partner != null)
                {
                    partner.PartnerID = scan.ID;
                }
            }
            context.ScannedInLearners.RemoveRange(scannedLearners);

            context.SaveChanges();
        }
开发者ID:robertfall,项目名称:LAD,代码行数:35,代码来源:ScanOutLearners.cs

示例2: Execute

        public override void Execute(DataModel context, ILog log)
        {
            var today = DateTime.Today;
            var scannedEmployees = context.ScannedInEmployees
                .Include(e => e.InScan)
                .Where(s => DbFunctions.TruncateTime(s.InScan.CreatedAt) < today)
                .ToList();
            foreach (var scannedEmployee in scannedEmployees)
            {
                var scanIn = context.EmployeeScans.Find(scannedEmployee.ScanID);
                var scan = new EmployeeScan()
                {
                    CreatedAt = scanIn.CreatedAt,
                    EmployeeNumber = scannedEmployee.EmployeeNumber,
                    Division = scanIn.Division,
                    Details = "Out (System)",
                    ScanType = "Type",
                    PartnerID = scanIn.ID,
                    Username = "System"
                };

                log.Info($"Scanning out Employee: {scan.EmployeeNumber} from {scan.Division}");
                context.EmployeeScans.Add(scan);
            }
            context.ScannedInEmployees.RemoveRange(scannedEmployees);
            context.SaveChanges();
        }
开发者ID:robertfall,项目名称:LAD,代码行数:27,代码来源:ScanOutEmployees.cs

示例3: Execute

        public override void Execute(DataModel context, ILog log)
        {
            var learners = Learner.ToBeExpired(context);

            foreach (var learner in learners)
            {
                log.Info($"Expiring Learner: {learner.LearnerNumber} FROM {learner.DivisionAbreviation}");
                learner.Status = LearnerStatus.Expired;
            }

            context.SaveChanges();
        }
开发者ID:robertfall,项目名称:LAD,代码行数:12,代码来源:ExpireLearners.cs

示例4: Execute

        public override void Execute(DataModel context, ILog log)
        {
            var enrollments = Enrollment.ToBeCompleted(context).Include(e => e.Learner);

            foreach (var enrollment in enrollments)
            {
                var learner = enrollment.Learner;
                log.Info($"Completed Enrollment: {enrollment.ID} FOR {learner.LearnerNumber} FROM {learner.DivisionAbreviation}");

                enrollment.CompletedOn = DateTime.Today;
            }
            context.SaveChanges();
        }
开发者ID:robertfall,项目名称:LAD,代码行数:13,代码来源:CompleteEnrollments.cs

示例5: Execute

        public override void Execute(DataModel context, ILog log)
        {
            var learnerPhotoFiles = Directory.GetFiles(Settings.Default.PhotoFolderPath)
               .Where(path => LearnerPhotoFile.ValidTypes.Contains(Path.GetExtension(path).ToLower()))
               .Select(path => new LearnerPhotoFile(path));

            foreach (var lpf in learnerPhotoFiles)
            {
                // Find Learner
                var learner = context.Learners.FirstOrDefault(l => l.IDNumber == lpf.Identifier);
                if (learner == null)
                {
                    PhotoSyncLog.Info(log, lpf.Identifier, "Learner Not Found");
                    continue;
                }

                // Delete Existing Photos
                var existingPhotos = context.Photos.Where(p => p.LearnerNumber == learner.LearnerNumber && p.Division == learner.DivisionAbreviation);
                foreach (var photo in existingPhotos)
                {
                    PhotoSyncLog.Info(log, lpf.Identifier, "Removing Old Photo");
                    context.Photos.Remove(photo);
                }

                // Save New Photo
                PhotoSyncLog.Info(log, lpf.Identifier, "Saving New Photo");
                var newPhoto = new Photo()
                {
                    LearnerNumber = learner.LearnerNumber,
                    Division = learner.DivisionAbreviation,
                    PhotoBytes = lpf.PhotoBytes
                };
                learner.NewLearnerCard = "Yes";
                context.Photos.Add(newPhoto);
                context.SaveChanges();

                var processed = Directory.CreateDirectory(Settings.Default.PhotoFolderPath + "\\processed");
                PhotoSyncLog.Info(log, lpf.Identifier, "Moving Photo to Processed");
                lpf.MoveTo(processed.FullName);
            }
        }
开发者ID:robertfall,项目名称:LAD,代码行数:41,代码来源:ImportPhotos.cs


注:本文中的DataModel.SaveChanges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。