public void MoveItem(short mode, int sn, string verId) { var obj = ProductDictionaryDataRepository.Find(o => o.DictId == verId && o.DicSN == sn); var list = ProductDictionaryDataRepository.GetQuery(o => o.DictId == verId && o.DicPSN == obj.DicPSN).OrderBy(o => o.SortOrder).ToList(); switch (mode) { case 2: //下移 var obj1 = list.LastOrDefault(); if (obj.Id != obj1.Id) { Entity.ProductDictionaryData next = null; for (var i = 0; i < list.Count; i++) { if (obj.Id == list[i].Id) { next = list[i + 1]; break; } } if (next != null) { var sort = obj.SortOrder; obj.SortOrder = next.SortOrder; next.SortOrder = sort; ProductDictionaryDataRepository.SaveChanges(); } } break; default: //上移 var obj2 = list.FirstOrDefault(); if (obj.Id != obj2.Id) { Entity.ProductDictionaryData prev = null; for (var i = 0; i < list.Count; i++) { if (obj.Id == list[i].Id) { prev = list[i - 1]; break; } } if (prev != null) { var sort = obj.SortOrder; obj.SortOrder = prev.SortOrder; prev.SortOrder = sort; ProductDictionaryDataRepository.SaveChanges(); } } break; } }
public List <Models.DictionaryModel> DataList(string verId, int?psn) { var queryMenu = ProductDictionaryDataRepository.GetQuery(o => o.DictId == verId); var q = from x in queryMenu //where x.HasChild || x.DicPSN<=0 //orderby x.SortOrder select x; var childs = new List <Entity.ProductDictionaryData>(); if (psn.HasValue) { q = q.Where(o => o.DicPSN == psn.Value); } else { q = q.Where(o => o.HasChild || o.DicPSN <= 0); childs = queryMenu.Where(o => !(o.HasChild || o.DicPSN <= 0)).ToList(); } var ms = q.OrderBy(o => o.SortOrder).ToList(); var menus = new List <Models.DictionaryModel>(); int i = 0; foreach (var m in ms) { var pm = new Models.DictionaryModel(); m.ToCopyProperty(pm); pm.ChildTitle = string.Join("、", childs.Where(o => o.DicPSN == m.DicSN).OrderBy(o => o.SortOrder).Select(o => o.Title)); pm.Index = i; i++; pm.Count = ms.Count; menus.Add(pm); } if (psn.HasValue) { return(menus); } var list = new List <Models.DictionaryModel>(); foreach (var menu in menus.Where(o => o.DicPSN <= 0)) { SetChilds(menu, menus); menu.Index = list.Count; list.Add(menu); } return(list); }
public Entity.ProductDictionaryData GetData(string verId, int sn) { return(ProductDictionaryDataRepository.GetQuery(o => o.DictId == verId && o.DicSN == sn).FirstOrDefault()); }