public OpResult Publish(string verId, short state) { var obj = Get(verId); if (obj != null) { if (!obj.ProductDictionaryDatas.Any()) { return(OpResult.Fail("请先配置字典!")); } obj.VerStatus = state; var list = ProductDictionaryVerRepository.GetQuery(o => o.ProductId == obj.ProductId && o.DictId != obj.DictId).ToList(); list.Where(o => o.VerStatus == obj.VerStatus).Each(o => o.Status = 2); if (state == 1)//测试 { obj.PublishDT = DateTime.Now; obj.PublishUID = CurrentUser.UID; obj.Status = 1; var source = list.OrderByDescending(o => o.VerCode).FirstOrDefault(o => o.VerCode > 0); if (source == null) { obj.VerCode = 1; } else { obj.VerCode = source.VerCode + 0.1m; } } ProductDictionaryDataRepository.SaveChanges(); return(OpResult.Success()); } return(OpResult.Fail()); }
public void SetState(int sn, short state, string verId) { var obj = ProductDictionaryDataRepository.Find(o => o.DictId == verId && o.DicSN == sn); obj.Status = state; ProductDictionaryDataRepository.SaveChanges(); }
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 OpResult SaveData(Entity.ProductDictionaryData obj, int productId) { if (obj.Id == 0) { if (ProductDictionaryVerRepository.IsExists(o => o.ProductId == productId && o.Status == 0 && o.DictId != obj.DictId)) { return(OpResult.Fail("已存在未发布的版本")); } obj.DictId = obj.DictId ?? CommonService.GUID; obj.DicSN = ProductDictionaryDataRepository.GetMaxInt(o => (int?)o.DicSN, whereLambda: o => o.DictId == obj.DictId); if (obj.DicPSN > 0) { var parent = ProductDictionaryDataRepository.Find(o => o.DictId == obj.DictId && o.DicSN == obj.DicPSN); if (parent != null) { parent.HasChild = true; } } obj.CreateDT = DateTime.Now; obj.CreateUID = CurrentUser.UID; obj.SortOrder = ProductDictionaryDataRepository.GetMaxInt(o => (int?)o.SortOrder, whereLambda: o => o.DictId == obj.DictId); ProductDictionaryDataRepository.Add(obj, false); } else { var menu = ProductDictionaryDataRepository.Get(obj.Id); if (ProductDictionaryDataRepository.IsExists(o => o.Title == obj.Title && o.DictId == menu.DictId && o.DicPSN == menu.DicPSN && o.Id != obj.Id)) { return(OpResult.Fail("该分类名称已存在")); } if (menu.HasChild != obj.HasChild && ProductDictionaryDataRepository.IsExists(o => o.DictId == menu.DictId && o.DicPSN == menu.DicSN)) { return(OpResult.Fail("存在下级不允许修改!")); } //obj.ToCopyProperty(menu, new List<string>() { "CreateDT", "CreateUID", "MenuId", "SortOrder" }); menu.Title = obj.Title; menu.HasChild = obj.HasChild; obj.DictId = menu.DictId; } var model = ProductDictionaryVerRepository.Find(o => o.DictId == obj.DictId); if (model != null) { model.UpdateDT = DateTime.Now; model.UpdateUID = CurrentUser.UID; } else { ProductDictionaryVerRepository.Add(new Entity.ProductDictionaryVer() { DictId = obj.DictId, ProductId = productId, CreateDT = obj.CreateDT, UpdateDT = obj.CreateDT, UpdateUID = obj.CreateUID, CreateUID = obj.CreateUID, }, false); } ProductDictionaryDataRepository.SaveChanges(); return(OpResult.Success()); }