コード例 #1
0
        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;
            }
        }
コード例 #2
0
        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());
        }