public OpResult Publish(string verId, short state) { var obj = Get(verId); if (obj != null) { if (!obj.ProductDataSqls.Any()) { return(OpResult.Fail("请先配置初始数据!")); } obj.VerStatus = state; var list = ProductDataVerRepository.GetQuery(o => o.ProductId == obj.ProductId && o.DataId != obj.DataId).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; } } ProductDataSqlRepository.SaveChanges(); return(OpResult.Success()); } return(OpResult.Fail()); }
public void MoveItem(short mode, int sn, string verId) { var list = ProductDataSqlRepository.GetQuery(o => o.DataId == verId).OrderBy(o => o.RunSort).ToList(); var obj = list.FirstOrDefault(o => o.MenuId == sn); switch (mode) { case 2: //下移 var obj1 = list.LastOrDefault(); if (obj.Id != obj1.Id) { Entity.ProductDataSql 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.RunSort; obj.RunSort = next.RunSort; next.RunSort = sort; ProductDataSqlRepository.SaveChanges(); } } break; default: //上移 var obj2 = list.FirstOrDefault(); if (obj.Id != obj2.Id) { Entity.ProductDataSql 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.RunSort; obj.RunSort = prev.RunSort; prev.RunSort = sort; ProductDataSqlRepository.SaveChanges(); } } break; } }
public OpResult SaveData(Entity.ProductDataSql obj, int productId) { if (obj.Id == 0) { if (ProductDataVerRepository.IsExists(o => o.ProductId == productId && o.Status == 0 && o.DataId != obj.DataId)) { return(OpResult.Fail("已存在未发布的版本")); } obj.DataId = obj.DataId ?? CommonService.GUID; obj.CreateDT = DateTime.Now; obj.CreateUID = CurrentUser.UID; obj.RunSort = ProductDataSqlRepository.GetMaxInt(o => (int?)o.RunSort, whereLambda: o => o.DataId == obj.DataId); ProductDataSqlRepository.Add(obj, false); } else { var menu = ProductDataSqlRepository.Get(obj.Id); if (ProductDataSqlRepository.IsExists(o => o.MenuId == obj.MenuId && o.DataId == menu.DataId && o.Id != obj.Id)) { return(OpResult.Fail("该菜单模块已存在")); } menu.RunSql = obj.RunSql; obj.DataId = menu.DataId; } var model = ProductDataVerRepository.Find(o => o.DataId == obj.DataId); if (model != null) { model.UpdateDT = DateTime.Now; model.UpdateUID = CurrentUser.UID; } else { ProductDataVerRepository.Add(new Entity.ProductDataVer() { DataId = obj.DataId, ProductId = productId, ModuleId = System.Web.HttpContext.Current.Request["modelId"], CreateDT = obj.CreateDT, UpdateDT = obj.CreateDT, UpdateUID = obj.CreateUID, CreateUID = obj.CreateUID, }, false); } ProductDataSqlRepository.SaveChanges(); return(OpResult.Success()); }