string GetOldValue(string columname)
        {
            if (DestionationProperties == null || Parm.Destination == null)
            {
                return("");
            }

            var    listcolumn = Parm.Options.OldValues == null ? null : Parm.Options.OldValues.Where(a => a.ColumnName == columname).FirstOrDefault();
            string value      = "";

            if (listcolumn != null)
            {
                value = listcolumn.Text;
            }
            else
            {
                var column = DestionationProperties.Where(s => s.Name == columname).FirstOrDefault();
                if (column != null)
                {
                    value = column.GetValue(Parm.Destination).ToString();
                }
            }

            return(value);
        }
        public void Map()
        {
            string source, dest;

            // get record Id: each record must have field Id & Get EmpId if exist
            int    EmpId    = 0;
            var    property = SourceProperties.Where(s => s.Name == "EmpId").FirstOrDefault();
            object value    = "";

            if (property != null)
            {
                value = property.GetValue(Parm.Source);
                int.TryParse(value?.ToString(), out EmpId);
            }

            string Id = "";

            property = SourceProperties.Where(s => s.Name == "Id").FirstOrDefault();
            if (property != null)
            {
                value = property.GetValue(Parm.Source);
                //if (value != null) int.TryParse(value.ToString(), out Id);
                if (value != null)
                {
                    Id = value.ToString();
                }
            }

            // Delete
            if (Parm.Transtype == Model.Domain.TransType.Delete)
            {
                // log once with no details
                HrUnitOfWork.CompanyRepository.Add(new Model.Domain.AudiTrail
                {
                    ColumnName   = "Id=" + value.ToString(),
                    CompanyId    = company,
                    ModifiedTime = DateTime.Now,
                    ModifiedUser = Identity.Name,
                    ObjectName   = Parm.ObjectName,
                    Transtype    = (byte)Model.Domain.TransType.Delete,
                    SourceId     = Id,
                    Version      = Parm.Version
                });

                CheckNotifications(EmpId == 0 ? null : (int?)EmpId);
                return;
            }

            // Update & Insert
            if (Parm.Transtype == Model.Domain.TransType.Insert)
            {
                ResolveId++;
            }

            var commonproperties = Parm.Options == null || Parm.Options.VisibleColumns == null ? (from sp in SourceProperties
                                                                                                  join dp in DestionationProperties on new { p1 = sp.Name, p2 = sp.PropertyType.ToString() } equals
                                                                                                  new { p1 = dp.Name, p2 = dp.PropertyType.ToString() }
                                                                                                  select new { sp, dp }) :
                                   (from sp in SourceProperties
                                    where Parm.Options.VisibleColumns.Contains(sp.Name)
                                    join dp in DestionationProperties on new { p1 = sp.Name, p2 = sp.PropertyType.ToString() } equals
                                    new { p1 = dp.Name, p2 = dp.PropertyType.ToString() }
                                    select new { sp, dp });

            commonproperties = commonproperties.Union(from sp in SourceProperties.Where(a => a.PropertyType.ToString() == "System.Collections.Generic.IList`1[System.Int32]")
                                                      where Parm.Options.VisibleColumns.Contains(sp.Name)
                                                      join dp in DestionationProperties.Where(a => a.PropertyType.ToString() == "System.String") on sp.Name equals dp.Name
                                                      select new { sp, dp });

            foreach (var match in commonproperties)
            {
                var soureValue = match.sp.GetValue(Parm.Source, null);
                var destValue  = match.dp.GetValue(Parm.Destination, null);

                CheckNotifications(EmpId == 0 ? null : (int?)EmpId, match.sp.Name, match.sp.PropertyType, soureValue, destValue, Id);

                if (Parm.ObjectName != null &&
                    match.sp.Name != "CreatedUser" &&
                    match.sp.Name != "CreatedTime" &&
                    match.sp.Name != "ModifiedTime" &&
                    match.sp.Name != "ModifiedUser" &&
                    (soureValue != null || destValue != null) &&
                    !Object.Equals(soureValue, destValue))
                {
                    var listcolumn = Parm.Options?.NewValues == null ? null : Parm.Options.NewValues.Where(a => a.ColumnName == match.sp.Name).FirstOrDefault();
                    source     = listcolumn != null ? listcolumn.Text : soureValue == null ? null : soureValue.ToString();
                    listcolumn = Parm.Options?.OldValues == null ? null : Parm.Options.OldValues.Where(a => a.ColumnName == match.sp.Name).FirstOrDefault();
                    dest       = listcolumn != null ? listcolumn.Text : destValue == null ? null : destValue.ToString();

                    HrUnitOfWork.CompanyRepository.Add(new Model.Domain.AudiTrail
                    {
                        ColumnName   = match.sp.Name,
                        CompanyId    = company,
                        ModifiedTime = DateTime.Now,
                        ModifiedUser = Identity.Name,
                        ObjectName   = Parm.ObjectName,
                        SourceId     = Id,
                        ValueBefore  = CheckValue(Parm.Transtype == Model.Domain.TransType.Insert ? ResolveId.ToString() : dest),
                        ValueAfter   = CheckValue(source),
                        Version      = Parm.Version,
                        Transtype    = (byte)Parm.Transtype
                    });
                }

                if (soureValue != null && match.sp.PropertyType.ToString() == "System.Collections.Generic.IList`1[System.Int32]" && match.dp.PropertyType.ToString() == "System.String")
                {
                    match.dp.SetValue(Parm.Destination, string.Join(",", ((IList <int>)soureValue).ToArray()), null);
                }
                else
                {
                    match.dp.SetValue(Parm.Destination, soureValue, null);
                }


                if (Parm.Transtype == Model.Domain.TransType.Insert)
                {
                    var p = DestionationProperties.Where(d => d.Name == "ModifiedUser").FirstOrDefault();
                    if (p != null)
                    {
                        p.SetValue(Parm.Destination, ResolveId.ToString(), null);
                    }
                }
            }
        }