public bool EditChangesLog(BusinessObject.POA data, int formType, int actionType, int role, string user) { using (var context = new EMSDataModel()) { using (var transaction = context.Database.BeginTransaction()) { try { var old = GetById(data.POA_ID); Dictionary <string, string[]> changes = GetAllChanges(old, data); context.Entry(old).CurrentValues.SetValues(data); context.SaveChanges(); LogsActivity(context, data, changes, formType, actionType, role, user); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw; } } } return(true); }
/// <summary> Part of Changes Log Step which Mark All Available Changes </summary> /// <param name="old"></param> /// <param name="updated"></param> /// <returns></returns> private Dictionary <string, string[]> GetAllChanges(BusinessObject.POA old, BusinessObject.POA updated) { try { var changes = new Dictionary <string, string[]>(); var columns = new string[] { "ID_CARD", "POA_PHONE", "POA_ADDRESS", "POA_EMAIL", "PRINTED_NAME", "TITLE", "LOGIN_AS", "MANAGER_ID", "IS_ACTIVE" }; var oldProps = new Dictionary <string, object>(); var props = new Dictionary <string, object>(); foreach (var prop in updated.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { props.Add(prop.Name, prop.GetValue(updated, null)); if (old != null) { oldProps.Add(prop.Name, prop.GetValue(old, null)); } else { oldProps.Add(prop.Name, null); } } foreach (var item in props) { var oldValue = (oldProps[item.Key] != null) ? oldProps[item.Key].ToString() : "N/A"; var newValue = (props[item.Key] != null) ? props[item.Key].ToString() : "N/A"; // updated value // var newValue = (item.Value != null) ? item.ToString() : "N/A"; // updated field and value if (!columns.Contains(item.Key)) { continue; } if (oldValue.Trim().ToUpper() != newValue.Trim().ToUpper()) { changes.Add(item.Key, new string[] { oldValue, newValue }); } } return(changes); } catch (Exception ex) { throw; } }
public void Update(BusinessObject.POA poa) { try { _repository.Update(poa); _uow.SaveChanges(); } catch (Exception ex) { _uow.RevertChanges(); throw; } }
public void Save(BusinessObject.POA poa) { try { //Insert _repository.InsertOrUpdate(poa); _uow.SaveChanges(); } catch (Exception exception) { _uow.RevertChanges(); _logger.Error(exception); } }
/// <summary> Part of Changes Log Step which Set All Changed Field into Table Changes Log </summary> /// <param name="context"></param> /// <param name="data"></param> /// <param name="changes"></param> /// <param name="formType"></param> /// <param name="actionType"></param> /// <param name="role"></param> /// <param name="actor"></param> /// <param name="comment"></param> private void LogsActivity(EMSDataModel context, BusinessObject.POA data, Dictionary <string, string[]> changes, int formType, int actionType, int role, string actor, string comment = null) { try { foreach (var map in changes) { refService.AddChangeLog(context, formType, data.POA_ID.ToString(), map.Key, map.Value[0], map.Value[1], actor, DateTime.Now); } context.SaveChanges(); } catch (Exception ex) { throw; } }
public BusinessObject.POA InsertChangesLog(BusinessObject.POA data, int formType, int actionType, int role, string user) { using (var context = new EMSDataModel()) { using (var transaction = context.Database.BeginTransaction()) { try { var changes = GetAllChanges(null, data); LogsActivity(context, data, changes, formType, actionType, role, user); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw; } } } return(data); }
private void SetChanges(POAViewDetailModel origin, BusinessObject.POA poa, POAViewDetailModel detail) { var convertBooltoString = poa.IS_ACTIVE == true ? "Yes" : "No"; // For Exciser var ExciserData = _poaExciserService.GetByPoaID(poa.POA_ID); var originExciserState = ExciserData.IS_ACTIVE_EXCISER == true ? "Yes" : "No"; var editExciserState = detail.IsExciser == true ? "Yes" : "No"; var changesData = new Dictionary <string, bool>(); changesData.Add("TITLE", origin.Title == poa.TITLE); changesData.Add("LOGIN_AS", origin.UserId == poa.LOGIN_AS); changesData.Add("MANAGER_ID", origin.ManagerId == poa.MANAGER_ID); changesData.Add("POA_PHONE", origin.PoaPhone == poa.POA_PHONE); changesData.Add("POA_EMAIL", origin.Email == poa.POA_EMAIL); changesData.Add("POA_ADDRESS", origin.PoaAddress == poa.POA_ADDRESS); changesData.Add("ID_CARD", origin.PoaIdCard == poa.ID_CARD); changesData.Add("PRINTED_NAME", origin.PoaPrintedName == poa.PRINTED_NAME); changesData.Add("IS_ACTIVE", origin.Is_Active.Equals(convertBooltoString)); // changesData.Add("IS_ACTIVE_EXCISER", originExciserState == editExciserState); foreach (var listChange in changesData) { if (listChange.Value == false) { var changes = new BusinessObject.CHANGES_HISTORY(); changes.FORM_TYPE_ID = Enums.MenuList.POA; changes.FORM_ID = poa.POA_ID.ToString(); changes.FIELD_NAME = listChange.Key; changes.MODIFIED_BY = CurrentUser.USER_ID; changes.MODIFIED_DATE = DateTime.Now; switch (listChange.Key) { case "TITLE": changes.OLD_VALUE = origin.Title; changes.NEW_VALUE = poa.TITLE; break; case "LOGIN_AS": changes.OLD_VALUE = origin.UserId == null ? null : _userBll.GetUserById(origin.UserId).USER_ID; changes.NEW_VALUE = string.IsNullOrEmpty(poa.LOGIN_AS) == true ? null : poa.LOGIN_AS; break; case "MANAGER_ID": changes.OLD_VALUE = origin.ManagerId; changes.NEW_VALUE = poa.MANAGER_ID; break; case "POA_PHONE": changes.OLD_VALUE = origin.PoaPhone; changes.NEW_VALUE = poa.POA_PHONE; break; case "POA_EMAIL": changes.OLD_VALUE = origin.Email; changes.NEW_VALUE = poa.POA_EMAIL; break; case "POA_ADDRESS": changes.OLD_VALUE = origin.PoaAddress; changes.NEW_VALUE = poa.POA_ADDRESS; break; case "ID_CARD": changes.OLD_VALUE = origin.PoaIdCard; changes.NEW_VALUE = poa.ID_CARD; break; case "PRINTED_NAME": changes.OLD_VALUE = origin.PoaPrintedName; changes.NEW_VALUE = poa.PRINTED_NAME; break; case "IS_ACTIVE": changes.OLD_VALUE = origin.Is_Active; changes.NEW_VALUE = convertBooltoString; break; //case "IS_ACTIVE_EXCISER": // changes.OLD_VALUE = originExciserState; // changes.NEW_VALUE = editExciserState; // break; } _changesHistoryBll.AddHistory(changes); } } }