示例#1
0
        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());
        }
示例#2
0
        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();
        }
示例#3
0
        public OpResult Deletes(int[] ids)
        {
            var list = ProductDictionaryVerRepository.GetQuery(o => ids.Contains(o.Id)).Include(o => o.ProductDictionaryDatas).ToList();

            if (list.Any(o => o.VerStatus > 0))
            {
                return(OpResult.Fail("该状态不允许删除!"));
            }
            ProductDictionaryDataRepository.RemoveRange(list.SelectMany(o => o.ProductDictionaryDatas).ToList(), false);
            ProductDictionaryVerRepository.RemoveRange(list);
            return(OpResult.Success());
        }
示例#4
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;
            }
        }
示例#5
0
        public List <Models.DictionaryModel> DataList(string verId, int?psn)
        {
            var queryMenu = ProductDictionaryDataRepository.GetQuery(o => o.DictId == verId);
            var q         = from x in queryMenu
                            //where x.HasChild || x.DicPSN<=0
                            //orderby x.SortOrder
                            select x;

            var childs = new List <Entity.ProductDictionaryData>();

            if (psn.HasValue)
            {
                q = q.Where(o => o.DicPSN == psn.Value);
            }
            else
            {
                q      = q.Where(o => o.HasChild || o.DicPSN <= 0);
                childs = queryMenu.Where(o => !(o.HasChild || o.DicPSN <= 0)).ToList();
            }
            var ms    = q.OrderBy(o => o.SortOrder).ToList();
            var menus = new List <Models.DictionaryModel>();
            int i     = 0;

            foreach (var m in ms)
            {
                var pm = new Models.DictionaryModel();
                m.ToCopyProperty(pm);
                pm.ChildTitle = string.Join("、", childs.Where(o => o.DicPSN == m.DicSN).OrderBy(o => o.SortOrder).Select(o => o.Title));
                pm.Index      = i;
                i++;
                pm.Count = ms.Count;
                menus.Add(pm);
            }
            if (psn.HasValue)
            {
                return(menus);
            }
            var list = new List <Models.DictionaryModel>();

            foreach (var menu in menus.Where(o => o.DicPSN <= 0))
            {
                SetChilds(menu, menus);
                menu.Index = list.Count;
                list.Add(menu);
            }
            return(list);
        }
示例#6
0
 public Entity.ProductDictionaryData GetData(string verId, int sn)
 {
     return(ProductDictionaryDataRepository.GetQuery(o => o.DictId == verId && o.DicSN == sn).FirstOrDefault());
 }
示例#7
0
        public void RemoveData(int sn, string verId)
        {
            var obj = ProductDictionaryDataRepository.Find(o => o.DictId == verId && o.DicSN == sn);

            ProductDictionaryDataRepository.Remove(obj);
        }
示例#8
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());
        }