public List <UIResource> GetResources(long langID) { try { return(TypedListConverter <UIResource> .ToTypedList(_resDao.FindForLanguage(langID))); } catch (Exception ex) { throw new LoadException(ex); } }
public virtual List <long> GetIDList() { try { //2think: it should be enough here to select only id's from table IList list = _dao.GetIDList(); if ((list == null) || (list.Count == 0)) { return(null); } return(TypedListConverter <long> .ToTypedList(list)); } catch (Exception ex) { throw new LoadException(ex); } }
protected List <T> GetTypedListFromIList(IList list) { return(TypedListConverter <T> .ToTypedList(list)); }
private void MergeResourceListWithSavedResources(ICollection <UIResource> list) { if ((list == null) || (list.Count == 0)) { return; } // prepare dictionary for selecting from DB Dictionary <long, List <int> > curResDictionary = new Dictionary <long, List <int> >(2); foreach (UIResource entity in list) { if (curResDictionary.ContainsKey(entity.LanguageID)) { long langId = entity.LanguageID; if (curResDictionary[langId] == null) { curResDictionary[langId] = new List <int>(); } curResDictionary[langId].Add(entity.ResourceID); } else { curResDictionary.Add(entity.LanguageID, new List <int>(new int[] { entity.ResourceID })); } } // select current resources for merge // 2think: should we implement reading in the one "SELECT" with big condition string and many parameters? StringBuilder condition = new StringBuilder(); List <string> pNames = new List <string>(); List <object> pValues = new List <object>(); List <UIResource> savedResources = new List <UIResource>(); foreach (long langId in curResDictionary.Keys) { condition.Length = 0; pNames.Clear(); pValues.Clear(); pNames.Add("langid"); pValues.Add(langId); condition.AppendFormat("entity.LanguageID = :langid AND entity.ResourceID IN ({0})", QueryUtils.GenIDList( curResDictionary[langId].ConvertAll <long>( delegate(int value) { return(value); }), pNames, pValues)); List <UIResource> curLanguageResources = TypedListConverter <UIResource> .ToTypedList( _resDao.FindByNamedParam(condition.ToString(), pNames.ToArray(), pValues.ToArray())); if ((curLanguageResources != null) && (curLanguageResources.Count > 0)) { savedResources.AddRange(curLanguageResources); } } // merge IDs if (savedResources.Count > 0) { foreach (UIResource entity in list) { if (entity.ID <= 0) { if (curResDictionary.ContainsKey(entity.LanguageID)) { long langId = entity.LanguageID; UIResource savedResource = savedResources.Find( delegate(UIResource res) { return((res.LanguageID == langId) && (res.ResourceID == entity.ResourceID)); }); if (savedResource != null) { entity.ID = savedResource.ID; } } } } } }