Beispiel #1
0
        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;
            }
        }
Beispiel #2
0
        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());
        }