/// <summary> /// 编辑分类对象 /// </summary> /// <param name="cf"></param> /// <returns></returns> public bool EditClassiFication(ClassiFication cf) { using (ShopEntities db = new ShopEntities()) { ClassiFication cfs = db.ClassiFication.SingleOrDefault(u => u.ID == cf.ID); if (cf.Status == null) { cfs.ClassName = cf.ClassName; return(db.SaveChanges() > 0); } else { if (cf.ClassName != null) { cfs.Status = cf.Status; cfs.ClassName = cf.ClassName; return(db.SaveChanges() > 0); } else { cfs.Status = cf.Status; return(db.SaveChanges() > 0); } } } }
/// <summary> /// 添加分类对象 /// </summary> /// <param name="cf"></param> /// <returns></returns> public bool AddClassiFication(ClassiFication cf) { using (ShopEntities db = new ShopEntities()) { db.ClassiFication.Add(cf); return(db.SaveChanges() > 0); } }
/// <summary> /// 删除分类 /// </summary> /// <param name="cf"></param> /// <returns></returns> public bool RemoveClassiFication(ClassiFication cf) { using (ShopEntities db = new ShopEntities()) { bool flag = false; List <ClassiFication> list = db.ClassiFication.Where(o => o.PID == cf.ID).ToList(); if (list.Count != 0) { using (var transaction = db.Database.BeginTransaction()) { try { db.Set <ClassiFication>().Attach(cf); db.Entry <ClassiFication>(cf).Property("Shape").IsModified = true; //关闭实体有效验证 db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); foreach (var item in list) { item.Shape = 0; db.Set <ClassiFication>().Attach(item); db.Entry <ClassiFication>(item).Property("Shape").IsModified = true; db.SaveChanges(); } transaction.Commit(); //恢复验证实体有效性(ValidateOnSaveEnabled)这个开关【如果后续有其他操作,记得恢复】 db.Configuration.ValidateOnSaveEnabled = true; flag = true; } catch (Exception ex) { transaction.Rollback(); } return(flag); } } else { db.Set <ClassiFication>().Attach(cf); db.Entry <ClassiFication>(cf).Property("Shape").IsModified = true; //关闭实体有效验证 db.Configuration.ValidateOnSaveEnabled = false; if (db.SaveChanges() > 0) { //恢复验证实体有效性(ValidateOnSaveEnabled)这个开关【如果后续有其他操作,记得恢复】 db.Configuration.ValidateOnSaveEnabled = true; flag = true; return(flag); } else { //恢复验证实体有效性(ValidateOnSaveEnabled)这个开关【如果后续有其他操作,记得恢复】 db.Configuration.ValidateOnSaveEnabled = true; return(flag); } } } }
public HttpResponseMessage GetClassiFicationNewsList(GetClassiFicationNewsList arg) { BaseJson <ClassiFication> resultMsg = new BaseJson <ClassiFication> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null }; Logger(typeof(ZxNewsController), arg.TryToJson(), "彩种下面的分类名称和文章列表-GetClassiFicationNewsList", () => { if (!string.IsNullOrEmpty(arg.Category)) { //获取分类信息 List <DataItemModel> data = dataItemCache.GetDataItemList(arg.Category); List <ItemList> res = data.Select(d => new ItemList { ItemId = d.ItemDetailId, SimpleSpelling = d.SimpleSpelling.ToUpper(), ItemName = d.ItemName }).ToList(); //文章Ids string firstId = res[0].ItemId; List <NewsEntity> news = newsBll.GetList(t => t.CategoryId.Equals(firstId)).Take(GlobalStaticConstant.SYSTEM_DEFAULT_PAGE_SIZE).ToList(); List <NewsPreviewItem> newsPreviewItem = new List <NewsPreviewItem>(); if (news.Count > 0) { foreach (NewsEntity n in news) { NewsPreviewItem preItem = new NewsPreviewItem { AddTime = n.CreateDate.TryToDateTimeToString("yyyy-MM-dd"), NewsId = n.NewsId, Title = n.FullHead }; newsPreviewItem.Add(preItem); } } ClassiFication result = new ClassiFication { ItemList = res, NewsList = newsPreviewItem }; resultMsg = new BaseJson <ClassiFication> { Status = (int)JsonObjectStatus.Success, Data = result, Message = JsonObjectStatus.Success.GetEnumText(), BackUrl = null }; } else { resultMsg = new BaseJson <ClassiFication> { Status = (int)JsonObjectStatus.Fail, Data = null, Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数Category为空。", BackUrl = null }; } }, e => { resultMsg = new BaseJson <ClassiFication> { Status = (int)JsonObjectStatus.Exception, Data = null, Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message, BackUrl = null }; }); return(resultMsg.TryToJson().ToHttpResponseMessage()); }
/// <summary> /// 删除分类 /// </summary> /// <param name="cf"></param> /// <returns></returns> public bool RemoveClassiFication(ClassiFication cf) { return(ICFM.RemoveClassiFication(cf)); }
/// <summary> /// 编辑分类对象 /// </summary> /// <param name="cf"></param> /// <returns></returns> public bool EditClassiFication(ClassiFication cf) { return(ICFM.EditClassiFication(cf)); }
/// <summary> /// 添加分类对象 /// </summary> /// <param name="cf"></param> /// <returns></returns> public bool AddClassiFication(ClassiFication cf) { return(ICFM.AddClassiFication(cf)); }