public GeneralContents <T> GetContent <T>(AdminTables table, string langCode, int offset, int limit, List <string> fields, bool isAll, long?LookUpId) { GeneralContents <T> contents = new GeneralContents <T>(); LookUpAttributes main = new LookUpAttributes(); Language lang = new Language(); List <LookUpAttributes> attributes = new List <LookUpAttributes>(); try { string XMLPath = ConfigurationManager.AppSettings["XMLPath"]; // @"~\LookUp.xml"; lang = _LanguageAccessor.Get(langCode); //Get class's attributes attributes = Tools.GetAttributes(table.ToString(), XMLPath); //Get main attribute main = attributes .Where(e => e.isMain == true) .FirstOrDefault(); int total = 0; if (main == null) { main = new LookUpAttributes(); main.Code = "This is any text"; } /* contents = GetMono<T>(table, lang.Id, main.Code);*/ if (attributes.Count != 0) { contents.Contents = ReturnListOf <T>(table, lang.Id, offset, limit, attributes, main, fields, isAll, out total, LookUpId); } contents.TotalContent = total; } catch (Exception ex) { throw; } return(contents); }
public List <LookUpAttributes> GetAttributes(AdminTables table, string langCode) { LookUpAttributes main = new LookUpAttributes(); Language lang = new Language(); List <LookUpAttributes> attributes = new List <LookUpAttributes>(); try { string XMLPath = ConfigurationManager.AppSettings["XMLPath"]; // @"~\LookUp.xml"; lang = _LanguageAccessor.Get(langCode); //Get class's attributes attributes = Tools.GetAttributes(table.ToString(), XMLPath); return(attributes); } catch (Exception ex) { throw; } }
private void OnAdminTables_Click(object sender, RoutedEventArgs e) { AdminTables win1 = new AdminTables(); win1.Show(); }
public List <T> ReturnListOf <T>(AdminTables table, long langId, int offset, int limit, List <LookUpAttributes> attributes, LookUpAttributes main, List <string> fields, bool isAll, out int total, long?lookUpId) { try { LookUpMultiLanguage lookupMulti = new LookUpMultiLanguage(); LookUp lookUp = new LookUp(); long tableId; List <LookUp> allRowsThatHaveCodeOfMainChild = new List <LookUp>(); List <LookUp> selectedRowsThatHaveCodeOfMainChild = new List <LookUp>(); List <LookUp> contents = new List <LookUp>(); System.Type UsedClass = __SharedClassesForeachTable[table]; var UsedObject = Activator.CreateInstance(UsedClass); List <string> images = new List <string>(); dynamic dynamic = (dynamic)UsedObject; tableId = __SharedTableIds[table]; List <dynamic> allDynamic = new List <dynamic>(); var accessor = FastMember.TypeAccessor.Create(typeof(T)); if (lookUpId == null) { allRowsThatHaveCodeOfMainChild = GetRowsOfTableByCode(tableId, main.Code); total = allRowsThatHaveCodeOfMainChild.Count(); selectedRowsThatHaveCodeOfMainChild = allRowsThatHaveCodeOfMainChild.OrderByDescending(s => s.Id).Skip(offset).Take(limit).ToList(); } else { selectedRowsThatHaveCodeOfMainChild.Add(_LookUpAccessor.Get((long)lookUpId)); total = 1; } foreach (LookUp row in selectedRowsThatHaveCodeOfMainChild) { contents = new List <LookUp>(); contents = _LookUpAccessor.GetChildren(row.Id); dynamic = (dynamic)Activator.CreateInstance(UsedClass); accessor[dynamic, "Id"] = row.Id; // main if (main.isLangNull) { lookupMulti = _LookUpMultiAccessor.Get(row.Id, null); } else { lookupMulti = _LookUpMultiAccessor.Get(row.Id, langId); } if (lookupMulti != null) { accessor[dynamic, main.Name] = lookupMulti.Description; } //TO DO set id foreach (LookUpAttributes obj in attributes) { if (obj.Code == main.Code) { continue; } if (!isAll) { if (fields.Contains(obj.Name) == false) { continue; } } lookUp = new LookUp(); lookUp = contents.Where(e => e.Code == obj.Code).FirstOrDefault(); if (lookUp == null) { continue; } if (obj.Name == "Date") { accessor[dynamic, obj.Name] = (row.SysDate).Value.Date; //new continue; } if (obj.isMedia) { try { if (obj.isList) { //get list images = new List <string>(); images = _MediaAccessor.Get(lookUp.Id, obj.isVideo) .Select(e => e.Name).ToList(); if (images.Count != 0) { accessor[dynamic, obj.Name] = images; } } else { LookUpMedia media = new LookUpMedia(); media = _MediaAccessor.Get(lookUp.Id, obj.isVideo).FirstOrDefault(); if (media == null) { continue; } // get one image accessor[dynamic, obj.Name] = media.Name; } } catch (Exception ex) { throw new Exception("exception in media id=" + lookUp.Id); } } else { try { if (obj.isLangNull) { lookupMulti = _LookUpMultiAccessor.Get(lookUp.Id, null); } else { lookupMulti = _LookUpMultiAccessor.Get(lookUp.Id, langId); } accessor[dynamic, obj.Name] = lookupMulti.Description; } catch (Exception ex) { throw new Exception("exception in lookup multi id=" + lookUp.Id); } } } allDynamic.Add(dynamic); } List <T> list = new List <T>(); foreach (dynamic d in allDynamic) { list.Add((T)d); } return(list); } catch (Exception ex) { throw; } }
public long AddContent <T>(T obj, AdminTables table) { string XMLPath = ConfigurationManager.AppSettings["XMLPath"]; //string xmlPath = @"C:\Users\huda\Desktop\Anzimaty\Anz.LMJ\Anz.LMJ.StartUp\LookUp.xml"; string multiLangValue; string imageValue; LookUpMedia img = new LookUpMedia(); List <string> imageValues = new List <string>(); List <LookUpAttributes> attributes = Tools.GetAttributes(table.ToString(), XMLPath); var t = typeof(T); LookUp lk = new LookUp(); LookUpMultiLanguage ml = new LookUpMultiLanguage(); long parentId = 0; bool isFirst = true; foreach (LookUpAttributes att in attributes) { lk = new LookUp(); lk.TableId = (int)__SharedTableIds[table]; lk.SysDate = DateTime.Now; lk.UserId = 1; lk.IsDeleted = false; lk.Code = att.Code; lk.isPublished = true; if (isFirst) { lk.ParentId = null; } else { lk.ParentId = parentId; } lk = _LookUpAccessor.Add(lk); if (isFirst) { isFirst = false; parentId = lk.Id; } if (att.isMedia) { //check if the property is list if (att.isList) { imageValues = (List <string>)(t.GetProperty(att.Name).GetValue(obj)); foreach (string s in imageValues) { // add media img = new LookUpMedia(); img.isActive = true; img.isDeleted = false; img.isVideo = att.isVideo; img.LookUpId = lk.Id;; img.SysDate = DateTime.Now; img.Name = s; _MediaAccessor.Add(img); } } else { imageValue = (string)(t.GetProperty(att.Name).GetValue(obj)); img = new LookUpMedia(); img.isActive = true; img.isDeleted = false; img.isVideo = att.isVideo; img.LookUpId = lk.Id; img.SysDate = DateTime.Now; img.Name = imageValue; _MediaAccessor.Add(img); } } else { // add lookupmulti multiLangValue = (t.GetProperty(att.Name).GetValue(obj)).ToString(); ml = new LookUpMultiLanguage(); ml.LookUpId = lk.Id; if (att.isLangNull) { ml.LangId = null; } else { ml.LangId = 1; } ml.SysDate = DateTime.Now; ml.isDeleted = false; //ml.UserId = 1; ml.Description = multiLangValue; // ml.isPublished = true; _LookUpMultiAccessor.Add(ml); } } return(parentId); }