public ResultDTO AddExt(Jinher.AMP.BTP.Deploy.CategoryInnerBrandDTO model) { try { var categoryInnerBrand = CategoryInnerBrand.CreateCategoryInnerBrand(); categoryInnerBrand.BrandId = model.BrandId; categoryInnerBrand.Brandname = model.Brandname; categoryInnerBrand.CategoryId = model.CategoryId; categoryInnerBrand.CategoryName = model.CategoryName; categoryInnerBrand.SubId = model.SubId; categoryInnerBrand.SubName = model.SubName; categoryInnerBrand.SubTime = DateTime.Now; categoryInnerBrand.EntityState = System.Data.EntityState.Added; ContextSession contextSession = ContextFactory.CurrentThreadContext; contextSession.SaveObject(categoryInnerBrand); contextSession.SaveChanges(); return(new ResultDTO { ResultCode = 0, Message = "", isSuccess = true }); } catch (Exception ex) { LogHelper.Error(string.Format("添加添加品牌分类关系发生错误。参数:{0}", JsonHelper.JsonSerializer(model)), ex); return(new ResultDTO { ResultCode = 1, Message = "Error", isSuccess = false }); } }
/// <summary> /// 添加多个分类品牌 /// </summary> /// <param name="models"></param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO AddListExt(System.Collections.Generic.List <Jinher.AMP.BTP.Deploy.CategoryInnerBrandDTO> models) { ResultDTO dto = null; try { foreach (var model in models) { var item = CategoryInnerBrand.CreateCategoryInnerBrand(); item.BrandId = model.BrandId; item.Brandname = model.Brandname; item.CategoryId = model.CategoryId; item.CategoryName = model.CategoryName; item.SubTime = model.SubTime; item.ModifiedOn = model.ModifiedOn; item.EntityState = EntityState.Added; ContextFactory.CurrentThreadContext.SaveObject(item); } ContextFactory.CurrentThreadContext.SaveChanges(); dto = new ResultDTO() { ResultCode = 0, Message = "添加分类品牌成功", isSuccess = true }; } catch (Exception ex) { dto = new ResultDTO() { ResultCode = 1, Message = ex.Message, isSuccess = false }; } return(dto); }
/// <summary> /// 根据一级分类ID获取品牌墙信息(热门品牌) /// </summary> /// <param name="CategoryID"></param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <IList <Jinher.AMP.BTP.Deploy.BrandwallDTO> > getBrandByCateIDExt(System.Guid CategoryID) { ResultDTO <IList <BrandwallDTO> > dto = null; try { var list = (from c in Category.ObjectSet() join cib in CategoryInnerBrand.ObjectSet() on c.Id equals cib.CategoryId into c_join from category in c_join.DefaultIfEmpty() join b in Brandwall.ObjectSet() on category.BrandId equals b.Id into b_join from cb in b_join.DefaultIfEmpty() where c.Id.Equals(CategoryID) && cb.Brandstatu.Equals(1) select new BrandwallDTO() { Id = cb.Id, Brandname = cb.Brandname, BrandLogo = cb.BrandLogo, Brandstatu = cb.Brandstatu }).ToList(); dto = new ResultDTO <IList <BrandwallDTO> >() { Data = list.ToList(), isSuccess = true, Message = "Sucess", ResultCode = 0 }; return(dto); } catch (Exception ex) { LogHelper.Error(string.Format("获取一级分类下的品牌墙信息错误getBrandByCateIDExt-CategoryID", CategoryID), ex); dto = new ResultDTO <IList <BrandwallDTO> >() { Data = null, isSuccess = false, Message = "fail", ResultCode = 1 }; return(dto); } }
/// <summary> /// 删除多个分类品牌 /// </summary> /// <param name="CategoryId"></param> /// <returns></returns> public ResultDTO DeleteCateBrandsByCategoryIdExt(System.Guid CategoryId) { ResultDTO dto = null; try { ContextSession contextSession = ContextFactory.CurrentThreadContext; var categoryInnerBrand = CategoryInnerBrand.ObjectSet().Where(p => p.CategoryId.Equals(CategoryId)).AsQueryable(); if (categoryInnerBrand.Count() > 0) { foreach (var item in categoryInnerBrand) { item.EntityState = EntityState.Deleted; contextSession.Delete(item); } contextSession.SaveChanges(); dto = new ResultDTO() { ResultCode = 0, Message = "删除分类品牌成功", isSuccess = true }; } else { //第一次添加时,分类品牌不存在 dto = new ResultDTO() { ResultCode = 0, Message = "分类品牌信息不存在", isSuccess = true }; } } catch (Exception ex) { dto = new ResultDTO() { ResultCode = 1, Message = ex.Message, isSuccess = false }; } return(dto); }
public Deploy.CustomDTO.ResultDTO <IList <CategoryInnerBrandDTO> > GetBrandWallListExt(System.Guid CategoryId) { try { var list = CategoryInnerBrand.ObjectSet().Where(_ => _.CategoryId == CategoryId); var listDto = from n in list select new CategoryInnerBrandDTO { Id = n.Id, BrandId = n.BrandId, Brandname = n.Brandname, CategoryId = n.CategoryId, CategoryName = n.CategoryName }; var dto = new ResultDTO <IList <CategoryInnerBrandDTO> >() { Data = listDto.ToList(), isSuccess = true, Message = "Sucess", ResultCode = 0 }; return(dto); } catch (Exception ex) { var dto = new ResultDTO <IList <CategoryInnerBrandDTO> >() { Data = null, isSuccess = false, Message = "fail", ResultCode = 1 }; return(dto); } }