/// <summary> /// Write Update Log For Employee /// </summary> /// <param name="newInfo"></param> /// <param name="logId"></param> /// <returns></returns> private bool WriteUpdateLogForContract(Contract newInfo, string logId) { bool isUpdated = false; try { // Get old info Contract oldInfo = new ContractRenewalDao().GetById(newInfo.ContractId); if ((oldInfo != null) && (newInfo != null) && (logId != null)) { if (newInfo.StartDate != oldInfo.StartDate) { commonDao.InsertLogDetail(logId, "StartDate", "Start Date", oldInfo.StartDate.ToString(Constants.DATETIME_FORMAT_VIEW), newInfo.StartDate.ToString(Constants.DATETIME_FORMAT_VIEW)); isUpdated = true; } if (newInfo.EndDate != oldInfo.EndDate) { commonDao.InsertLogDetail(logId, "EndDate", "End Date",oldInfo.EndDate.HasValue?oldInfo.EndDate.Value.ToString(Constants.DATETIME_FORMAT_VIEW):"",newInfo.EndDate.HasValue?newInfo.EndDate.Value.ToString(Constants.DATETIME_FORMAT_VIEW):""); isUpdated = true; } if (newInfo.ContractType != oldInfo.ContractType) { ContractType obj = new ContractRenewalDao().GetContractTypeById(newInfo.ContractType); if (obj != null) { commonDao.InsertLogDetail(logId, "ContractType", "Contract Type", oldInfo.ContractType1.ContractTypeName, obj.ContractTypeName); isUpdated = true; } } if (newInfo.ContractFile != oldInfo.ContractFile) { if (!string.IsNullOrEmpty(newInfo.ContractFile)) { string[] arrayNew = newInfo.ContractFile.TrimEnd(Constants.FILE_CHAR_PREFIX).Split(Constants.FILE_CHAR_PREFIX); if (!string.IsNullOrEmpty(oldInfo.ContractFile)) { foreach (string item in oldInfo.ContractFile.TrimEnd(Constants.FILE_CHAR_PREFIX).Split(Constants.FILE_CHAR_PREFIX))//case delete file { if (!newInfo.ContractFile.TrimEnd(Constants.FILE_CHAR_PREFIX).Split(Constants.FILE_CHAR_PREFIX).Contains(item)) { commonDao.InsertLogDetail(logId, "AttachFile", "Attach File", item, ""); isUpdated = true; } } } foreach (string fileNew in arrayNew) //case add new file { if (!oldInfo.ContractFile.Contains(fileNew)) { commonDao.InsertLogDetail(logId, "AttachFile", "Attach File", "", fileNew); isUpdated = true; } } } } if (newInfo.Comment != oldInfo.Comment) { commonDao.InsertLogDetail(logId, "Comment", "Comment", oldInfo.Comment, newInfo.Comment); isUpdated = true; } if (isUpdated) { // Insert Key Name string key = "Contract on " +oldInfo.StartDate.ToString(Constants.DATETIME_FORMAT_VIEW)+ " of " + oldInfo.EmployeeId + " [" + oldInfo.Employee.FirstName + " " + oldInfo.Employee.LastName + "]"; commonDao.InsertLogDetail(logId, "EmployeeId", "Key for Update", key, null); } } } catch (Exception ex) { throw ex; } return isUpdated; }
public void WriteLogForRemoveContractCV(Contract newInfo, ELogAction action) { try { bool isUpdated = false; if (newInfo == null) { return; } MasterLog objMasterLog = new MasterLog(); string logId = commonDao.UniqueId; commonDao.InsertMasterLog(logId, newInfo.UpdatedBy, ELogTable.Contract.ToString(), action.ToString()); Contract oldInfo = new ContractRenewalDao().GetById(newInfo.ContractId); if ((oldInfo != null) && (newInfo != null) && (logId != null)) { foreach (string item in oldInfo.ContractFile.TrimEnd(Constants.FILE_CHAR_PREFIX).Split(Constants.FILE_CHAR_PREFIX)) { if (!newInfo.ContractFile.TrimEnd(Constants.FILE_CHAR_PREFIX).Split(Constants.FILE_CHAR_PREFIX).Contains(item)) { commonDao.InsertLogDetail(logId, "AttachFile", "Attach File", item, ""); isUpdated = true; } } if (isUpdated) { // Insert Key Name string key ="Contract on Start Date " + oldInfo.StartDate.ToString(Constants.DATETIME_FORMAT_VIEW) + (oldInfo.EndDate.HasValue?" to " +oldInfo.EndDate.Value.ToString(Constants.DATETIME_FORMAT_VIEW):"") + " of " + oldInfo.EmployeeId + " [" + oldInfo.Employee.FirstName + " " + oldInfo.Employee.LastName + "]"; commonDao.InsertLogDetail(logId, "EmployeeId", "Key for Delete", key, null); } else { commonDao.DeleteMasterLog(logId); } } } catch (Exception ex) { throw ex; } }
public Message UpdateForResign(Employee objUI) { Message msg = null; try { if (objUI != null) { // Get current group in dbContext Employee objDb = GetById(objUI.ID); if (objDb != null) { // Check valid update date if (IsValidUpdateDate(objUI, objDb, out msg)) { new EmployeeLogDao().WriteLogForEmployee(null, objUI, ELogAction.Delete); // Update info by objUI objDb.ResignedDate = objUI.ResignedDate; objDb.ResignedAllowance = objUI.ResignedAllowance; objDb.ResignedReason = objUI.ResignedReason; objDb.UpdateDate = DateTime.Now; objDb.UpdatedBy = objUI.UpdatedBy; objDb.EmpStatusId = objUI.EmpStatusId; #region Update Contract bool isComplete = true; ContractRenewalDao contractDao = new ContractRenewalDao(); List<Contract> contractList = contractDao.GetList(objDb.ID); if (contractList.Count > 0) { foreach (Contract item in contractList) { if (item.EndDate.HasValue) { if ((item.StartDate < objUI.ResignedDate) && (item.EndDate.Value < objUI.ResignedDate)) { msg = contractDao.UpdateNotification(item.ContractId); } else if ((item.StartDate <= objUI.ResignedDate) && (item.EndDate.Value >= objUI.ResignedDate)) { msg = contractDao.UpdateNotificationCurrent(item.ContractId, objUI.ResignedDate.Value); } else if ((item.StartDate > objUI.ResignedDate)) { contractDao.Delete(item); } } else { if (item.StartDate <= objUI.ResignedDate) { msg = contractDao.UpdateNotificationCurrent(item.ContractId, objUI.ResignedDate.Value); } else { contractDao.Delete(item); } } if (msg != null) { if (msg.MsgType == MessageType.Error) { isComplete = false; } } } } #endregion // Submit changes to dbContext if (isComplete != false) { dbContext.SubmitChanges(); // Show success message msg = new Message(MessageConstants.I0001, MessageType.Info, "Employee '" + objDb.FirstName + " " + objDb.MiddleName + " " + objDb.LastName + "'", "resigned"); } else { msg = new Message(MessageConstants.E0007, MessageType.Error); } } } } } catch { // Show system error msg = new Message(MessageConstants.E0007, MessageType.Error); } return msg; }