本文整理汇总了C#中UnitOfWork.AddObject方法的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWork.AddObject方法的具体用法?C# UnitOfWork.AddObject怎么用?C# UnitOfWork.AddObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork.AddObject方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateComputingTask
public Guid CreateComputingTask(Guid userID, DateTime monthYear)
{
using (var context = new VnrHrmDataContext())
{
IUnitOfWork unitOfWork = new UnitOfWork(context);
Sys_AsynTask task = new Sys_AsynTask();
task.ID = Guid.NewGuid();
task.PercentComplete = 0.01D;
task.TimeStart = DateTime.Now;
task.Status = AsynTaskStatus.Doing.ToString();
task.Type = AsynTask.Attendance_Computing.ToString();
task.Summary = "Attendance: " + monthYear.ToString("MM/yyyy");
unitOfWork.AddObject(typeof(Sys_AsynTask), task);
unitOfWork.SaveChanges(userID);
return task.ID;
}
}
示例2: CreateComputingTask
public Guid CreateComputingTask(Guid userID, DateTime dateFrom, DateTime dateTo)
{
#region Khởi tạo Sys_AsynTask cho mỗi lần xử lý
using (var context = new VnrHrmDataContext())
{
IUnitOfWork unitOfWork = new UnitOfWork(context);
Sys_AsynTask task = new Sys_AsynTask();
task.ID = Guid.NewGuid();
task.PercentComplete = 0.01D;
task.TimeStart = DateTime.Now;
task.Status = AsynTaskStatus.Doing.ToString();
task.Type = AsynTask.Download_TimeLog_CMS.ToString();
task.Summary = "CMS TimeLog: " + dateFrom.ToString("dd/MM/yyyy") + " - " + dateTo.ToString("dd/MM/yyyy");
unitOfWork.AddObject(typeof(Sys_AsynTask), task);
unitOfWork.SaveChanges(userID);
return task.ID;
}
#endregion
}
示例3: SaveTAMLog
//.........这里部分代码省略.........
string waitStatus = ProfileStatusSyn.E_WAITING.ToString();
List<Can_TamScanLogCMS> listTAMScanLog = new List<Can_TamScanLogCMS>();
var profileQueryable = unitOfWork.CreateQueryable<Hre_Profile>(userID, pro => (pro.StatusSyn == null
|| pro.StatusSyn != waitStatus) && (pro.DateQuit == null || pro.DateQuit.Value > dateFrom));
var cardHistoryQueryable = unitOfWork.CreateQueryable<Hre_CardHistory>(userID);
if (listProfileID != null && listProfileID.Count() > 0)
{
profileQueryable = profileQueryable.Where(pro => listProfileID.Contains(pro.ID));
cardHistoryQueryable = cardHistoryQueryable.Where(pro => pro.ProfileID.HasValue && listProfileID.Contains(pro.ProfileID.Value));
}
else
{
cardHistoryQueryable = cardHistoryQueryable.Where(cr => cr.Hre_Profile != null
&& (!cr.Hre_Profile.IsDelete.HasValue || cr.Hre_Profile.IsDelete == false));
}
var listAllProfile = profileQueryable.Select(d =>
new Hre_ProfileEntity
{
ID = d.ID,
CodeEmp = d.CodeEmp
}).ToList<Hre_ProfileEntity>();
var listAllCardHistory = cardHistoryQueryable.Select(d =>
new Hre_CardHistoryEntity
{
ID = d.ID,
ProfileID = d.ProfileID,
CardCode = d.CardCode,
DateEffect = d.DateEffect
}).ToList<Hre_CardHistoryEntity>();
for (int i = 0; i < rows.Length; i++)
{
DataRow row = rows[i];
string cardCode = row[0].ToString();
cardCode = cardCode.ToUpper().Trim();
Can_TamScanLogCMS tam = new Can_TamScanLogCMS();
if (filterByCodeEmp)
{
tam.CodeEmp = cardCode;
tam.Comment = "Hệ thống cũ";
}
else
{
tam.CardCode = cardCode;
}
tam.TimeLog = Convert.ToDateTime(row[1].ToString().Trim());
tam.Type = row[2].ToString().Trim();
tam.MachineCode = row[3].ToString().Trim();
tam.Status = TAMScanStatus.E_LOADED.ToString();
List<Hre_ProfileEntity> listProfileByCode = null;
if (!string.IsNullOrWhiteSpace(tam.CardCode))
{
var listCardHistoryByCode = listAllCardHistory.Where(ch => ch.CardCode != null
&& ch.CardCode.ToString().ToUpper().Trim() == cardCode).ToList();
if (listCardHistoryByCode.Count() <= 0)
{
listProfileByCode = listAllProfile.Where(d => d.CodeAttendance != null
&& d.CodeAttendance.ToString().ToUpper().Trim() == cardCode).ToList();
}
else
{
var listProfileIDByCode = listCardHistoryByCode.Select(d => d.ProfileID).ToList();
listProfileByCode = listAllProfile.Where(d => listProfileIDByCode.Contains(d.ID)).ToList();
}
}
else if (!string.IsNullOrWhiteSpace(tam.CodeEmp))
{
listProfileByCode = listAllProfile.Where(d => d.CodeEmp != null
&& d.CodeEmp.ToString().ToUpper().Trim() == cardCode).ToList();
}
if (listProfileByCode != null && listProfileByCode.Count > 0)
{
var dateStart = tam.TimeLog.HasValue ? tam.TimeLog.Value.Date : dateFrom;
var dateEnd = tam.TimeLog.HasValue ? tam.TimeLog.Value.Date.AddDays(1) : dateTo;
var rec = ConvertToRecord(tam, listProfileByCode, listAllCardHistory, dateStart, dateEnd);
if (rec != null)
{
listTAMScanLog.Add(rec);
}
}
}
DeleteTAMLog(unitOfWork, dateFrom, dateTo, listTAMScanLog, userID);
unitOfWork.AddObject(listTAMScanLog.ToArray());
unitOfWork.SaveChanges(userID);
return listTAMScanLog;
}
}
示例4: UpdateUserMasterDataGroup
public void UpdateUserMasterDataGroup(Guid userID, List<Guid?> listMasterDataGroupID)
{
if (userID != Guid.Empty && listMasterDataGroupID != null)
{
using (var context = new VnrHrmDataContext())
{
IUnitOfWork unitOfWork = new UnitOfWork(context);
var listMasterDataGroupNumber = unitOfWork.CreateQueryable<Cat_MasterDataGroup>(d => d.OrderNumber.HasValue
&& listMasterDataGroupID.Contains(d.ID)).Select(d => d.OrderNumber.Value).ToList();
var userMasterDataGroup = unitOfWork.CreateQueryable<Sys_UserMasterData>(d =>
d.UserID == userID).FirstOrDefault();
if (userMasterDataGroup == null)
{
userMasterDataGroup = new Sys_UserMasterData
{
UserID = userID
};
unitOfWork.AddObject(typeof(Sys_UserMasterData), userMasterDataGroup);
}
userMasterDataGroup.MasterDataGroups = listMasterDataGroupNumber.ToBinary();
userMasterDataGroup.MasterDataGroup = string.Join(",", listMasterDataGroupNumber);
unitOfWork.SaveChanges(userID);
}
}
}
示例5: ComputeAttendance
//.........这里部分代码省略.........
List<Hre_WorkHistory> listWorkHistoryByProfile = listWorkHistory.Where(d => d.ProfileID == profileId).ToList();
var listRosterByProfile = listRoster.Where(d => d.ProfileID == profileId && d.DateStart <= attendanceTo && d.DateEnd >= attendanceFrom).ToList();
var listMonthShifts = Att_AttendanceLib.GetDailyShifts(attendanceFrom, attendanceTo, profile.ID, listRosterByProfile, listRosterGroup);
#endregion
attendanceTableCount += ComputeAttendance(unitOfWork, userID, monthYear, cutOffDurationID, attendanceFrom, attendanceTo, profile,
gradeCfgByProfile, listShift, listAnnualDetailByProfile, listHDTJobByProfile, listLeaveDayByProfile, listLeaveDayType,
listOvertimeByProfile, listOvertimeType, listPregnancyByProfile, listLateEarlyRule, listWorkDayByProfile,
listPreAttendanceTableByProfile, listTimeOffInLieuByProfile, notAutoRegHolidayLeave, otholidayscompute400,
missTAM_LeaveType, listMonthShifts, listHoliday);
#region Cập Nhật Dữ Liệu Cho Việc Tính TimeOffInLieuMonth and Year
double? balanceLeaves = (new Att_LeavedayServices()).CalculateTotalHourTimeOff(profileId, lstTimeOffInLieu_3Month.Where(m =>
m.ProfileID == profileId).ToList(), lstTimeOffInLieu_ByMonth_3Month.Where(m => m.ProfileID == profileId).ToList(), monthYear, 1);
double UnusualLeaves = lstTimeOffInLieu.Where(m => m.ProfileID == profileId).Sum(m => m.UnusualLeaves ?? 0);
double TakenLeaves = lstTimeOffInLieu.Where(m => m.ProfileID == profileId).Sum(m => m.TakenLeaves ?? 0);
double RemainLeaves = UnusualLeaves - TakenLeaves + (balanceLeaves ?? 0);
var timeOffInLieuMonth_ByProfile = lstTimeOffInLieuMonth.Where(m =>
m.ProfileID == profileId).FirstOrDefault();
if (timeOffInLieuMonth_ByProfile == null)
{
//tạo mới
timeOffInLieuMonth_ByProfile = new Att_TimeOffInLieuMonth();
timeOffInLieuMonth_ByProfile.ID = Guid.NewGuid();
timeOffInLieuMonth_ByProfile.ProfileID = profileId;
timeOffInLieuMonth_ByProfile.BalanceLeaves = balanceLeaves ?? 0;
timeOffInLieuMonth_ByProfile.UnusualLeaves = UnusualLeaves;
timeOffInLieuMonth_ByProfile.TakenLeaves = TakenLeaves;
timeOffInLieuMonth_ByProfile.RemainLeaves = RemainLeaves;
timeOffInLieuMonth_ByProfile.Month = new DateTime(attendanceTo.Year, attendanceTo.Month, 1);
unitOfWork.AddObject(typeof(Att_TimeOffInLieuMonth), timeOffInLieuMonth_ByProfile);
}
else
{
//chinh sua
timeOffInLieuMonth_ByProfile.BalanceLeaves = balanceLeaves ?? 0;
timeOffInLieuMonth_ByProfile.UnusualLeaves = UnusualLeaves;
timeOffInLieuMonth_ByProfile.TakenLeaves = TakenLeaves;
timeOffInLieuMonth_ByProfile.RemainLeaves = RemainLeaves;
}
#endregion
#region Chia thành nhiều giai đoạn lưu bảng công
if (asynTask != null)
{
totalComputedProfileForTask++;
double percent = (double)totalComputedProfileForTask / (double)totalProfile;
if (totalComputedProfileForTask >= totalComputedProfileMustSubmitTask)
{
asynTask.PercentComplete = asynTask.PercentComplete + percent;
dataErrorCode = taskUnitOfWork.SaveChanges(userID);
totalComputedProfileForTask = 0;
if (dataErrorCode == DataErrorCode.Locked)
{
break;
}
}
}
//Nên submit lần đầu tiên khi đã tính được 5 profile
bool firstSubmit = listProfileID.ToList().IndexOf(profileId) == 5;
firstSubmit = totalComputed >= 5 ? false : firstSubmit;//đã chạy 1 lần
totalComputedProfileForSubmit++;
if (firstSubmit || totalComputedProfileForSubmit >= totalComputedProfileMustSubmit)
{
totalComputedProfileForSubmit = firstSubmit ? totalComputedProfileForSubmit : 0;
dataErrorCode = unitOfWork.SaveChanges(userID);
if (dataErrorCode == DataErrorCode.Locked)
{
break;
}
}
#endregion
}
catch
{
throw new Exception(profileId.ToString());
}
}
}
#endregion
//Lưu tất cả kết quả tính công
dataErrorCode = unitOfWork.SaveChanges(userID);
return attendanceTableCount;
}
}
示例6: Save
/// <summary>
/// Convert và lưu dữ liệu import vào database.
/// </summary>
/// <param name="userID"></param>
/// <param name="listImportData"></param>
/// <returns></returns>
public bool Save(Guid userID, IList listImportData, string userLogin)
{
bool result = false;
if (!isDataSaved)
{
if (listImportData != null && listImportData.Count > 0)
{
using (var context = new VnrHrmDataContext())
{
IUnitOfWork unitOfWork = new UnitOfWork(context);
var objectType = listImportData[0].GetPropertyValue(Constant.ObjectType);
IList listObj = new ArrayList();
var status = DataErrorCode.Success;
if (objectType != null)
{
if (this.ImportMode == ImportDataMode.Update || this.ImportMode == ImportDataMode.Skip)
{
var listObjectID = listImportData.AsQueryable().Select(Constant.ID).GetList().OfType<Guid>().Distinct().ToArray();
listEntityResult = unitOfWork.CreateQueryable(Guid.Empty, (Type)objectType, "@0.Contains(outerIt." + Constant.ID + ")", listObjectID).GetList();
foreach (var importData in listImportData)
{
var objectID = importData.GetPropertyValue(Constant.ID).TryGetValue<Guid>();
var objectDuplicate = listEntityResult.AsQueryable().Where(Constant.ID + " = @0", objectID).FirstOrDefault();
if (objectDuplicate != null)
{
//Copy dữ liệu import vào dữ liệu trong database
importData.CopyData(objectDuplicate, Constant.ID);
}
else if (this.ImportMode == ImportDataMode.Skip)
{
objectDuplicate = ((Type)objectType).CreateInstance();
importData.CopyData(objectDuplicate, Constant.ID);
unitOfWork.AddObject((Type)objectType, objectDuplicate);
}
if (objectDuplicate != null)
{
listObj.Add(objectDuplicate);
}
var currentIndex = listImportData.IndexOf(importData);
if ((currentIndex + 1) == listImportData.Count || (currentIndex > 0
&& listImportData.IndexOf(importData) % 9999 == 0))
{
status = unitOfWork.SaveChanges(userID, true);
}
if (ProgressChanged != null)
{
double percent = ((double)listImportData.IndexOf(importData) / (double)listImportData.Count) * 100;
ProgressChanged(new ProgressEventArgs
{
ID = UserID,
Name = "SaveData",
Value = "SaveData".TranslateString(),
Percent = (int)percent
});
}
}
result = true;
}
else
{
listEntityResult = ((Type)objectType).CreateList();
foreach (var importData in listImportData)
{
var objectDuplicate = ((Type)objectType).CreateInstance();
importData.CopyData(objectDuplicate, Constant.ID);
unitOfWork.AddObject((Type)objectType, objectDuplicate);
var currentIndex = listImportData.IndexOf(importData);
if ((currentIndex + 1) == listImportData.Count || (currentIndex > 0
&& listImportData.IndexOf(importData) % 9999 == 0))
{
status = unitOfWork.SaveChanges(userID, true);
}
if (ProgressChanged != null)
{
double percent = ((double)listImportData.IndexOf(importData) / (double)listImportData.Count) * 100;
ProgressChanged(new ProgressEventArgs
{
ID = UserID,
Name = "SaveData",
Value = "SaveData".TranslateString(),
//.........这里部分代码省略.........
示例7: ComputeWorkday
//.........这里部分代码省略.........
//Nếu 2 dòng quẹt thẻ phía trước không thuộc một ca khác trong lịch của nhân viên
if (listTamScanLogByPreShift == null || listTamScanLogByPreShift.Count() < 2)
{
var preTamScanLog = listPreTamScanLog.Where(d => d.TimeLog < item.TimeLog).FirstOrDefault();
var currentShiftDuration = 12;//cho ca tối đa được 12 tiếng đồng hồ
if (preTamScanLog != null && listWorkday.Any(d => d.ProfileID == profile.ID && (d.InTime1 == preTamScanLog.TimeLog
|| d.InTime2 == preTamScanLog.TimeLog || d.InTime3 == preTamScanLog.TimeLog || d.InTime4 == preTamScanLog.TimeLog
|| d.OutTime1 == preTamScanLog.TimeLog || d.OutTime2 == preTamScanLog.TimeLog || d.OutTime3 == preTamScanLog.TimeLog
|| d.OutTime4 == preTamScanLog.TimeLog)))
{
//Trường hợp quẹt thẻ này đã sử dụng
preTamScanLog = null;
}
//Nếu quẹt thẻ hiện tại kết với quẹt thẻ trước đó mà phù hợp duration thì ghép sai ca
if (preTamScanLog != null && preTamScanLog.TimeLog.HasValue && item.TimeLog.Value
.Subtract(preTamScanLog.TimeLog.Value).TotalHours <= currentShiftDuration)
{
if (preTamScanLog.TimeLog < date)
{
if (preShiftValue.HasValue)
{
workday = listWorkday.Where(d => d.ProfileID == profile.ID
&& d.WorkDate == date.AddDays(-1)).FirstOrDefault();
if (workday == null)
{
if (preTamScanLog.TimeLog.Value.Date >= dateFrom.Date
&& preTamScanLog.TimeLog.Value.Date <= dateTo.Date)
{
workday = new Att_Workday();
unitOfWork.AddObject(typeof(Att_Workday), workday);
workday.WorkDate = preTamScanLog.TimeLog.Value.Date;
workday.FirstInTime = workday.InTime1 = preTamScanLog.TimeLog;
workday.LastOutTime = workday.OutTime1 = item.TimeLog;
workday.Type = WorkdayType.E_DETECTED_SHIFT.ToString();
isPreWorkday = true;
preTamScanLog.Checked = true;
isWrongShiftDetected = true;
break;//chỉ hỗ trợ 1 ca
}
}
else
{
listTimeLog.Add(item);
}
}
else
{
listTimeLog.Add(item);
}
}
else
{
if (workday == null)
{
workday = new Att_Workday();
unitOfWork.AddObject(typeof(Att_Workday), workday);
}
workday.FirstInTime = workday.InTime1 = preTamScanLog.TimeLog;
workday.LastOutTime = workday.OutTime1 = item.TimeLog;
workday.Type = WorkdayType.E_DETECTED_SHIFT.ToString();
示例8: SaveRoster
//.........这里部分代码省略.........
WedShiftID = d.WedShiftID,
ThuShiftID = d.ThuShiftID,
FriShiftID = d.FriShiftID,
SatShiftID = d.SatShiftID,
SunShiftID = d.SunShiftID,
Type = RosterType.E_DEFAULT.ToString(),
Status = RosterStatus.E_APPROVED.ToString()
}).ToArray();
if (ImportType == ImportRosterType.OverrideMonth)
{
var listProfileID = listRoster.Select(d => d.ProfileID).Distinct().ToList();
var dateStart = listRoster.Where(d => d.DateStart > SqlDateTime.MinValue.Value).Select(d => d.DateStart.Date).OrderBy(d => d).FirstOrDefault();
var dateEnd = dateStart.AddMonths(1).Date;//Sau này nếu nghiệp vụ thay đổi chỉ xóa những ngày khai báo thì lấy max của cột DateEnd trong danh sách
//Không xóa theo kiểu miền giao DateStart và DateEnd -> có thể sai trường hợp roster dài nhiều tháng
unitOfWork.Delete<Att_Roster>(unitOfWork.CreateQueryable<Att_Roster>(d => d.DateStart >= dateStart
&& d.DateEnd <= dateEnd && listProfileID.Contains(d.ProfileID)));
}
else if (ImportType == ImportRosterType.OverrideHasValue)
{
var listProfileID = listRoster.Select(d => d.ProfileID).Distinct().ToList();
var dateStart = listRoster.Where(d => d.DateStart > SqlDateTime.MinValue.Value).Select(d => d.DateStart.Date).OrderBy(d => d).FirstOrDefault();
var dateEnd = listRoster.Where(d => d.DateEnd > SqlDateTime.MinValue.Value).Select(d => d.DateEnd.Date).OrderBy(d => d).LastOrDefault();
var listOldRoster = unitOfWork.CreateQueryable<Att_Roster>(Guid.Empty, d => d.DateStart <= dateEnd
&& d.DateEnd >= dateStart && listProfileID.Contains(d.ProfileID)).ToList<Att_Roster>();
foreach (var roster in listRoster)
{
DateTime rosterStart = roster.DateStart.Date;
DateTime rosterEnd = roster.DateEnd.Date;
for (DateTime date = rosterStart; date <= rosterEnd; date = date.AddDays(1))
{
var oldRoster = listOldRoster.Where(d => d.DateStart.Date <= date &&
d.DateEnd.Date >= date && d.ProfileID == roster.ProfileID).FirstOrDefault();
if (oldRoster != null)
{
if (date.DayOfWeek == DayOfWeek.Monday && roster.MonShiftID.HasValue)
{
oldRoster.MonShiftID = roster.MonShiftID;
roster.MonShiftID = null;
}
else if (date.DayOfWeek == DayOfWeek.Tuesday && roster.TueShiftID.HasValue)
{
oldRoster.TueShiftID = roster.TueShiftID;
roster.TueShiftID = null;
}
else if (date.DayOfWeek == DayOfWeek.Wednesday && roster.WedShiftID.HasValue)
{
oldRoster.WedShiftID = roster.WedShiftID;
roster.WedShiftID = null;
}
else if (date.DayOfWeek == DayOfWeek.Thursday && roster.ThuShiftID.HasValue)
{
oldRoster.ThuShiftID = roster.ThuShiftID;
roster.ThuShiftID = null;
}
else if (date.DayOfWeek == DayOfWeek.Friday && roster.FriShiftID.HasValue)
{
oldRoster.FriShiftID = roster.FriShiftID;
roster.FriShiftID = null;
}
else if (date.DayOfWeek == DayOfWeek.Saturday && roster.SatShiftID.HasValue)
{
oldRoster.SatShiftID = roster.SatShiftID;
roster.SatShiftID = null;
}
else if (date.DayOfWeek == DayOfWeek.Sunday && roster.SunShiftID.HasValue)
{
oldRoster.SunShiftID = roster.SunShiftID;
roster.SunShiftID = null;
}
}
}
if ((!roster.MonShiftID.HasValue && !roster.TueShiftID.HasValue && !roster.WedShiftID.HasValue
&& !roster.ThuShiftID.HasValue && !roster.FriShiftID.HasValue && !roster.SatShiftID.HasValue
&& !roster.SunShiftID.HasValue) || roster.DateStart > roster.DateEnd)
{
listDuplicate.Add(roster);
}
}
}
var listImported = listRoster.Where(d => !listDuplicate.Contains(d));
unitOfWork.SetCorrectOrgStructureID(listImported.ToList());
unitOfWork.AddObject(listImported.ToArray());
dataErrorCode = unitOfWork.SaveChanges(LoginUserID);
RemoveImportObject();
RemoveInvalidObject();
}
}
return dataErrorCode;
}