示例#1
0
        /// <summary> Change Exciser Flag with True or False </summary>
        /// <param name="data"></param>
        public POA_EXCISER SetActive(POA_EXCISER data, int formType, int actionType, int role, string user)
        {
            using (var context = new EMSDataModel())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var old = context.POA_EXCISER.SingleOrDefault(m => m.EXCISER_ID == data.EXCISER_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 this.HandleException("Exception occured on POA Service Service. See Inner Exception property to see details", ex);
                    }
                }
            }
            return(data);
        }
示例#2
0
 /// <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, POA_EXCISER 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 this.HandleException("Exception occured on POA Exciser Service. See Inner Exception property to see details", ex);
     }
 }
示例#3
0
        /// <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(POA_EXCISER old, POA_EXCISER updated)
        {
            try
            {
                var changes = new Dictionary <string, string[]>();
                var columns = new string[]
                {
                    "IS_ACTIVE_EXCISER"
                };
                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 this.HandleException("Exception occured on POA Exciser Service. See Inner Exception property to see details", ex);
            }
        }
示例#4
0
 /// <summary> Create Exciser Flag - Default: True </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public POA_EXCISER CreateExciser(POA_EXCISER data, int formType, int actionType, int role, string user)
 {
     using (var context = new EMSDataModel())
     {
         using (var transaction = context.Database.BeginTransaction())
         {
             try
             {
                 context.POA_EXCISER.Add(data);
                 context.SaveChanges();
                 var changes = GetAllChanges(null, data);
                 LogsActivity(context, data, changes, formType, actionType, role, user);
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 transaction.Rollback();
                 throw this.HandleException("Exception occured on POA EXCISER Service. See Inner Exception property to see details", ex);
             }
         }
     }
     return(data);
 }