예제 #1
0
        public static OpResult Delete(int[] ids)
        {
            var list = CurrentRepository.QueryEntity.Include(o => o.ProductList).Where(o => ids.Contains(o.Id)).ToList();

            #region 操作日志
            foreach (var item in list)
            {
                var msg = Sys.LogEngine.CompareModelToLog <MemberIntegralSet>(Sys.LogModule.消费积分, null, item);
                new Sys.LogEngine().WriteDelete(msg, Sys.LogModule.消费积分);
            }
            #endregion
            var op = Delete(list);
            if (op.Successed)
            {
                var stores = string.Join(",", WarehouseService.GetList().Select(o => o.StoreId));
                Pharos.Infrastructure.Data.Redis.RedisManager.Publish("SyncDatabase", new Pharos.ObjectModels.DTOs.DatabaseChanged()
                {
                    CompanyId = Sys.SysCommonRules.CompanyId, StoreId = stores, Target = "MemberIntegralSetPackage"
                });
            }
            return(op);
        }
예제 #2
0
        public static OpResult SaveOrUpdate(MemberIntegralSet obj)
        {
            if (!obj.EndDate.HasValue)
            {
                obj.EndDate = DateTime.Now.AddYears(20);
            }
            var Inserted     = HttpContext.Current.Request["Inserted"];
            var InsertedType = HttpContext.Current.Request["Inserted2"];
            var Deleted      = HttpContext.Current.Request["Deleted"];
            var DeletedType  = HttpContext.Current.Request["Deleted2"];
            var Updated      = HttpContext.Current.Request["Updated"];
            var UpdatedType  = HttpContext.Current.Request["Updated2"];

            obj.CustomerObj = HttpContext.Current.Request["CustomerObj"];
            var insertList = new List <MemberIntegralSetList>();
            var deleteList = new List <MemberIntegralSetList>();
            var updateList = new List <MemberIntegralSetList>();

            if (!Inserted.IsNullOrEmpty())
            {
                var list = Inserted.ToObject <List <MemberIntegralSetList> >();
                list.Each(o => { o.SetType = 1; });
                insertList.AddRange(list);
            }
            if (!InsertedType.IsNullOrEmpty())
            {
                var list = InsertedType.ToObject <List <MemberIntegralSetList> >();
                list.Each(o => { o.SetType = 2; });
                insertList.AddRange(list);
            }
            if (!Updated.IsNullOrEmpty())
            {
                updateList.AddRange(Updated.ToObject <List <MemberIntegralSetList> >());
            }
            if (!UpdatedType.IsNullOrEmpty())
            {
                updateList.AddRange(UpdatedType.ToObject <List <MemberIntegralSetList> >());
            }
            if (!Deleted.IsNullOrEmpty())
            {
                deleteList.AddRange(Deleted.ToObject <List <MemberIntegralSetList> >());
            }
            if (!DeletedType.IsNullOrEmpty())
            {
                deleteList.AddRange(DeletedType.ToObject <List <MemberIntegralSetList> >());
            }
            obj.OperatorUID  = Sys.CurrentUser.UID;
            obj.OperatorTime = DateTime.Now;
            obj.CompanyId    = CommonService.CompanyId;
            var op = new OpResult();

            if (obj.Id == 0)
            {
                obj.ProductList = insertList;
                #region 操作日志
                var msg = Sys.LogEngine.CompareModelToLog <MemberIntegralSet>(Sys.LogModule.消费积分, obj);
                new Sys.LogEngine().WriteInsert(msg, Sys.LogModule.消费积分);
                #endregion
                op = Add(obj);
            }
            else
            {
                var res = CurrentRepository.QueryEntity.Include(o => o.ProductList).FirstOrDefault(o => o.Id == obj.Id);
                obj.ToCopyProperty(res);
                updateList.Each(o =>
                {
                    var pro = res.ProductList.FirstOrDefault(i => i.Id == o.Id);
                    if (pro != null)
                    {
                        o.ToCopyProperty(pro);
                    }
                });
                deleteList.Each(o =>
                {
                    var pro = res.ProductList.FirstOrDefault(i => i.Id == o.Id);
                    if (pro != null)
                    {
                        BaseService <MemberIntegralSetList> .CurrentRepository.Remove(pro, false);
                    }
                });
                res.ProductList.AddRange(insertList);
                op = Update(res);
            }
            if (op.Successed)
            {
                var stores = string.Join(",", WarehouseService.GetList().Select(o => o.StoreId));
                Pharos.Infrastructure.Data.Redis.RedisManager.Publish("SyncDatabase", new Pharos.ObjectModels.DTOs.DatabaseChanged()
                {
                    CompanyId = Sys.SysCommonRules.CompanyId, StoreId = stores, Target = "MemberIntegralSetPackage"
                });
            }
            return(op);
        }