Beispiel #1
0
 public OpResult SaveOrUpdate(Entity.ProductDictionaryVer obj)
 {
     if (obj.Id == 0)
     {
         obj.DictId    = CommonService.GUID;
         obj.CreateDT  = DateTime.Now;
         obj.UpdateDT  = obj.CreateDT;
         obj.UpdateUID = CurrentUser.UID;
         obj.CreateUID = obj.UpdateUID;
         ProductDictionaryVerRepository.Add(obj, false);
     }
     else
     {
         var product = ProductDictionaryVerRepository.Find(o => o.Id == obj.Id);
         product.UpdateUID = CurrentUser.UID;
         product.UpdateDT  = DateTime.Now;
     }
     ProductDictionaryVerRepository.SaveChanges();
     return(OpResult.Success());
 }
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());
        }