public int UpdateCategoryBrands(IEnumerable <CategoryBrandRankModel> models) { using (var db = Tuhu.Component.Common.DbHelper.CreateDefaultDbHelper()) { try { db.BeginTransaction(); foreach (var model in models) { if (model.PKID > 0) { DalCategoryBrandRank.UpdateCategoryBrand(model, db); } else { DalCategoryBrandRank.InsertCategoryBrand(model, db); } } db.Commit(); return(models.Count()); } catch (Exception e) { db.Rollback(); return(0); } } }
public long InsertCategoryBrand(CategoryBrandRankModel model) { using (var db = Tuhu.Component.Common.DbHelper.CreateDefaultDbHelper()) { return(DalCategoryBrandRank.InsertCategoryBrand(model, db)); } }
public CategoryBrandRankModel FetchCategoryBrand(long pkid) { using (var db = Tuhu.Component.Common.DbHelper.CreateDefaultDbHelper()) { return(DalCategoryBrandRank.FetchCategoryBrand(pkid, db)); } }
public IEnumerable <CategoryBrandRankModel> SelectCategoryBrand(long pkid, DateTime?date) { using (var db = Tuhu.Component.Common.DbHelper.CreateDefaultDbHelper()) { return(DalCategoryBrandRank.SelectCategoryBrand(pkid, date, db)); } }
public static async Task <IEnumerable <CategoryBrandRankModel> > SelectCategoryBrandRankAsync(DateTime date) { var list = await DalCategoryBrandRank.SelectCategoryBrandRankAsync(date); var dic = list.GroupBy(x => x.ParentPkid).ToDictionary(x => x.Key, x => x.ToList()); var result = new List <CategoryBrandRankModel>(); if (dic.ContainsKey(0)) { result = dic[0].OrderBy(x => int.Parse(x.NameIndex ?? "0")).ToList(); foreach (var item in result) { if (dic.ContainsKey(item.PKID)) { item.Branks = dic[item.PKID].GroupBy(x => new { x.ParentPkid, x.Date, x.Name }).Select(m => { var x = m.FirstOrDefault(); return(new CategoryBrandModel() { Name = x.Name, PKID = x.PKID, NameIndex = x.NameIndex, ParentPkid = x.ParentPkid }); } ).OrderBy(x => int.Parse(x.NameIndex ?? "0")).Take(10).ToList(); } } } return(result); }
public int DeleteCategoryBrand(long id) { using (var db = Tuhu.Component.Common.DbHelper.CreateDefaultDbHelper()) { var children = DalCategoryBrandRank.SelectCategoryBrand(id, null, db); foreach (var c in children) { DalCategoryBrandRank.DeleteCategoryBrand(c.PKID, db); } return(DalCategoryBrandRank.DeleteCategoryBrand(id, db)); } }