/// <summary> /// Write Log For Employee /// </summary> /// <param name="oldInfo"></param> /// <param name="newInfo"></param> /// <param name="action"></param> public void WriteLogForWorkflowAdmin(UserAdmin_WFRole oldInfo, UserAdmin_WFRole newInfo, ELogAction action) { try { if (newInfo == null) { return; } MasterLog objMasterLog = new MasterLog(); string logId = commonDao.UniqueId; switch (action) { case ELogAction.Insert: // Insert to Master Log commonDao.InsertMasterLog(logId, newInfo.CreatedBy, ELogTable.WorkFlowAdmin.ToString(), action.ToString()); // Write Insert Log WriteInsertLogForWorkflowAdmin(newInfo, logId); break; case ELogAction.Update: // Insert to Master Log commonDao.InsertMasterLog(logId, newInfo.UpdatedBy, ELogTable.WorkFlowAdmin.ToString(), action.ToString()); // Write Update Log bool isUpdated = WriteUpdateLogForWorkflowAdmin(newInfo, logId); if (!isUpdated) { commonDao.DeleteMasterLog(logId); } break; case ELogAction.Delete: // Insert to Master Log commonDao.InsertMasterLog(logId, newInfo.UpdatedBy, ELogTable.Employee.ToString(), action.ToString()); // Write Delete Log string key = newInfo.ID + " [" + oldInfo.UserAdmin.UserName + "] with Role [" + oldInfo.WFRole.Name + "]"; commonDao.InsertLogDetail(logId, "ID", "Key for Delete", key, null); break; } } catch (Exception ex) { throw ex; } }
/// <summary> /// Write Insert Log Work Flow Admin /// </summary> /// <param name="objInfo"></param> /// <param name="logId"></param> private void WriteInsertLogForWorkflowAdmin(UserAdmin_WFRole objInfo, string logId) { try { if ((objInfo != null) && (logId != null)) { // Insert to Log Detail commonDao.InsertLogDetail(logId, "UserAdminId", "UserName", null, objInfo.UserAdmin.UserName); commonDao.InsertLogDetail(logId, "WFRoleID", "Role", null, objInfo.WFRole.Name); commonDao.InsertLogDetail(logId, "IsActive", "Active", null, objInfo.IsActive == Constants.IS_ACTIVE ? "Yes":"No"); } } catch (Exception ex) { throw ex; } }
private bool WriteUpdateLogForWorkflowAdmin(UserAdmin_WFRole newInfo, string logId) { bool isUpdated = false; try { // Get old info UserAdmin_WFRole oldInfo = new JRAdminDao().GetById(newInfo.ID); if ((oldInfo != null) && (newInfo != null) && (logId != null)) { if (newInfo.UserAdminId != oldInfo.UserAdminId) { UserAdmin objUserName = new UserAdminDao().GetById(newInfo.UserAdminId); if (objUserName != null) { commonDao.InsertLogDetail(logId, "UserAdminId", "User Name", oldInfo.UserAdmin.UserName, objUserName.UserName); isUpdated = true; } } if (newInfo.WFRoleID != oldInfo.WFRoleID) { WFRole obj = new RoleDao().GetByID(newInfo.WFRoleID); if (obj != null) { commonDao.InsertLogDetail(logId, "WFRoleID", "Role", oldInfo.WFRole.Name, obj.Name); isUpdated = true; } } if (newInfo.IsActive != oldInfo.IsActive) { commonDao.InsertLogDetail(logId, "IsActive", "Active", oldInfo.IsActive == Constants.IS_ACTIVE ? "Yes" : "No", newInfo.IsActive == Constants.IS_ACTIVE ? "Yes" : "No"); isUpdated = true; } if (isUpdated) { // Insert Key Name string key = newInfo.ID + " [" + oldInfo.UserAdmin.UserName + "] with Role [" + oldInfo.WFRole.Name + "]"; commonDao.InsertLogDetail(logId, "WorkFlowAdmin", "Key for Update", key, null); } } } catch (Exception ex) { throw ex; } return isUpdated; }
/// <summary> /// Check update date whether is valid /// </summary> /// <param name="objUI"></param> /// <param name="msg"></param> /// <returns></returns> private bool IsValidUpdateDate(UserAdmin_WFRole objUI, UserAdmin_WFRole objDb, out Message msg) { bool isValid = false; msg = null; try { if ((objUI != null) && (objUI.UpdateDate != null)) { if (objDb != null) { if (objDb.UpdateDate.ToString().Equals(objUI.UpdateDate.ToString())) { isValid = true; } else { msg = new Message(MessageConstants.E0025, MessageType.Error, "User name " + objDb.UserAdmin.UserName + " with role " + objDb.WFRole.Name); } } } } catch { throw; } return isValid; }
/// <summary> /// Check user name whether is duplicated /// </summary> /// <param name="objUI"></param> /// <param name="isUpdateMode"></param> /// <returns></returns> private bool IsUserNameDuplicated(UserAdmin_WFRole objUI) { bool isDuplicated = false; List<UserAdmin_WFRole> objList = new List<UserAdmin_WFRole>(); objList = dbContext.UserAdmin_WFRoles.Where(p => ( (p.UserAdminId == objUI.UserAdminId) && (p.WFRoleID == objUI.WFRoleID))).ToList<UserAdmin_WFRole>(); if (objList.Count > 0) { isDuplicated = true; } return isDuplicated; }
/// <summary> /// Delete /// </summary> /// <param name="objUI"></param> private void Delete(UserAdmin_WFRole objUI) { if (objUI != null) { // Get current info in dbContext UserAdmin_WFRole objDb = GetById(objUI.ID); if (objDb != null) { new JRAdminLogDao().WriteLogForWorkflowAdmin(objDb,null, ELogAction.Delete); dbContext.UserAdmin_WFRoles.DeleteOnSubmit(objUI); // Submit changes to dbContext dbContext.SubmitChanges(); } } }
/// <summary> /// Update /// </summary> /// <param name="objUI"></param> /// <returns></returns> public Message Update(UserAdmin_WFRole objUI) { Message msg = null; try { if (objUI != null) { // Get current group in dbContext UserAdmin_WFRole objDb = GetById(objUI.ID); if (objDb != null) { if (hasJRAssignTo(objUI.UserAdminId,objUI.WFRoleID)) { UserAdminDao adminDao = new UserAdminDao(); UserAdmin obj = adminDao.GetById(objUI.UserAdminId); if (obj != null) { msg = new Message(MessageConstants.E0023, MessageType.Error, "update " + obj.UserName, "Job Request"); } } else { // Check valid update date if (IsValidUpdateDate(objUI, objDb, out msg)) { new JRAdminLogDao().WriteLogForWorkflowAdmin(null, objUI, ELogAction.Update); // Update info by objUI objDb.UserAdminId = objUI.UserAdminId; objDb.WFRoleID = objUI.WFRoleID; objDb.UpdateDate = DateTime.Now; objDb.UpdatedBy = objUI.UpdatedBy; objDb.IsActive = objUI.IsActive; // Submit changes to dbContext dbContext.SubmitChanges(); // Show success message msg = new Message(MessageConstants.I0001, MessageType.Info, " User admin '" + objDb.UserAdmin.UserName + "'", "updated"); } } } } } catch (Exception) { // Show system error msg = new Message(MessageConstants.E0007, MessageType.Error); } return msg; }
/// <summary> /// Insert /// </summary> /// <param name="objUI"></param> /// <returns></returns> public Message Insert(UserAdmin_WFRole objUI) { Message msg = null; try { if (objUI != null) { UserAdmin_WFRole objDb = GetById(objUI.ID); if (IsUserNameDuplicated(objUI)) { // Show error message msg = new Message(MessageConstants.E0004, MessageType.Error, "Username " + objDb.UserAdmin.UserAdminId); } else { dbContext.UserAdmin_WFRoles.InsertOnSubmit(objUI); dbContext.SubmitChanges(); new JRAdminLogDao().WriteLogForWorkflowAdmin(null, objUI, ELogAction.Insert); // Show success message msg = new Message(MessageConstants.I0001, MessageType.Info, "User '" + objUI.UserAdmin.UserName+"'", "added in role '" + objUI.WFRole.Name+"'"); } } } catch (Exception) { // Show system error msg = new Message(MessageConstants.E0007, MessageType.Error); } return msg; }