本文整理汇总了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();
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
}