private static bool GetUrlSeo <T>(T entity, PropertyInfo propertyInfo) { var seo = propertyInfo.GetCustomAttributes(typeof(SeoAttribute), true).Length > 0; if (seo) { var urlSeo = new UrlSeoController(); var seoName = entity.GetType() .GetProperties() .FirstOrDefault(p => p.GetCustomAttributes(typeof(ProcessedSeoName), true).Length > 0); if (seoName != null) { var value = urlSeo.GenerateSlug(seoName.GetValue(entity, null)); propertyInfo.SetValue(entity, Convert.ChangeType(value, propertyInfo.PropertyType), null); return(true); } } return(false); }
private static bool PropertyEtiketTable <T>(T entity, ParamValue property, PropertyInfo propertyInfo) { try { var paramValues = new List <ParamValue>(); //.Where(x => x.GetCustomAttributes(typeof (PrimaryKeyAttribute), true) //.FirstOrDefault(); var attr = propertyInfo.GetCustomAttributes(typeof(EtiketAttribute), true); var attrTable = propertyInfo.GetCustomAttributes(typeof(ForingnKeyTable), true); var attrsuccess = attr.Length > 0 && attrTable.Length > 0; if (attrsuccess) { object primarkey = null; foreach (var item in entity.GetType().GetProperties()) { var pkAttr = item.GetCustomAttributes(typeof(PrimaryKeyAttribute), true); if (pkAttr.Length > 0) { primarkey = item.GetValue(entity, null) == null?item.GetType().GetDefault() : item.GetValue(entity, null); } } var values = property.Value.ToString().Split(','); var foringnKeyTable = (ForingnKeyTable)attrTable.Select(x => x).FirstOrDefault(); if (foringnKeyTable != null) { try { var tablo = foringnKeyTable.tableName; var classtablo = SetValuetoClass <object>(tablo).FirstOrDefault(); foreach (var item in values) { if (classtablo != null) { foreach (var rRequst in classtablo.GetType().GetProperties()) { if (rRequst.GetCustomAttributes(typeof(EtiketAttribute), true).Length > 0) { rRequst.SetValue(classtablo, Convert.ChangeType(item, rRequst.PropertyType), null); } if (rRequst.GetCustomAttributes(typeof(ForingnKeyAttribute), true).Length > 0) { rRequst.SetValue(classtablo, Convert.ChangeType(primarkey, rRequst.PropertyType), null); } if (rRequst.GetCustomAttributes(typeof(EtiketSeoAttribute), true).Length > 0) { var urlSeo = new UrlSeoController(); var value = urlSeo.GenerateSlug(item); rRequst.SetValue(classtablo, Convert.ChangeType(value, rRequst.PropertyType), null); } } var result = DataProcessing <object> .Saves(classtablo); if (!result.success) { return(false); } } } return(true); } catch (Exception ex) { throw; } } } } catch (Exception ex) { throw; } return(false); }