コード例 #1
0
        public Result PutSmartCapacityList([FromBody] IEnumerable <SmartCapacityList> capacityLists)
        {
            if (capacityLists == null || !capacityLists.Any())
            {
                return(Result.GenError <Result>(Error.ParamError));
            }

            if (capacityLists.Any(x => !x.IsSet()))
            {
                return(Result.GenError <Result>(Error.SmartCapacityListNotEmpty));
            }

            var capacityId = capacityLists.FirstOrDefault()?.CapacityId ?? 0;

            if (capacityId == 0)
            {
                return(Result.GenError <Result>(Error.ParamError));
            }

            var capacity = SmartCapacityHelper.Instance.Get <SmartCapacity>(capacityId);

            if (capacity == null)
            {
                return(Result.GenError <Result>(Error.SmartCapacityNotExist));
            }

            var processes = SmartProcessCodeCategoryProcessHelper.GetDetailByCategoryId(capacity.CategoryId);

            if (!processes.Any())
            {
                return(Result.GenError <Result>(Error.SmartProcessCodeCategoryProcessNotExist));
            }

            if (capacityLists.Count() != processes.Count())
            {
                return(Result.GenError <Result>(Error.SmartCapacityListCountError));
            }

            var capacityListIds = capacityLists.Select(x => x.Id);
            var data            = SmartCapacityListHelper.Instance.GetByIds <SmartCapacityList>(capacityListIds);

            if (data.Count() != capacityLists.Count())
            {
                return(Result.GenError <Result>(Error.SmartCapacityListNotExist));
            }

            if (capacityLists.Count() != processes.Count())
            {
                return(Result.GenError <Result>(Error.SmartCapacityListCountError));
            }

            var userId         = Request.GetIdentityInformation();
            var markedDateTime = DateTime.Now;

            foreach (var capacityList in capacityLists)
            {
                capacityList.CreateUserId   = userId;
                capacityList.MarkedDateTime = markedDateTime;
                capacityList.CapacityId     = capacityId;
            }
            var oldSmartCapacityLists = SmartCapacityListHelper.GetSmartCapacityLists(capacityId);
            //删除
            var delete = oldSmartCapacityLists.Where(z => capacityLists.Where(x => x.Id != 0).All(y => y.Id != z.Id));

            if (delete.Any())
            {
                SmartCapacityListHelper.Instance.Delete(delete.Select(x => x.Id));
            }
            //更新
            var update = capacityLists.Where(x => x.Id != 0);

            if (update.Any())
            {
                SmartCapacityListHelper.Instance.Update(update);
            }

            //新增
            var add = capacityLists.Where(x => x.Id == 0);

            if (add.Any())
            {
                SmartCapacityListHelper.Instance.Add(add);
            }

            OldWorkFlowHelper.Instance.OnSmartCapacityListChanged(capacityLists);
            return(Result.GenError <Result>(Error.Success));
        }
コード例 #2
0
        public object PutSmartCapacityList([FromBody] OpSmartCapacity capacity)
        {
            var capacityId  = capacity.Id;
            var oldCapacity = SmartCapacityHelper.Instance.Get <SmartCapacity>(capacityId);

            if (oldCapacity == null)
            {
                return(Result.GenError <Result>(Error.SmartCapacityNotExist));
            }

            var capacityLists = capacity.List;

            if (capacityLists == null)
            {
                return(Result.GenError <Result>(Error.SmartCapacityListNotSet));
            }

            var processes = SmartProcessCodeCategoryProcessHelper.GetDetailByCategoryId(capacity.CategoryId);

            if (!processes.Any())
            {
                return(Result.GenError <Result>(Error.SmartProcessCodeCategoryProcessNotExist));
            }

            if (capacityLists.Count() != processes.Count())
            {
                return(Result.GenError <Result>(Error.SmartCapacityListCountError));
            }

            if (capacityLists.Any(x => !x.IsSet()))
            {
                return(Result.GenError <Result>(Error.SmartCapacityListNotEmpty));
            }

            var smartCapacityListIds = capacityLists.Select(x => x.Id).Where(y => y != 0);

            if (smartCapacityListIds.Any())
            {
                var data = SmartCapacityListHelper.Instance.GetByIds <SmartCapacityList>(smartCapacityListIds);
                if (data.Count() != smartCapacityListIds.Count())
                {
                    return(Result.GenError <Result>(Error.SmartCapacityListNotExist));
                }
            }
            var createUserId   = Request.GetIdentityInformation();
            var markedDateTime = DateTime.Now;

            if (oldCapacity.CategoryId != capacity.CategoryId)
            {
                capacity.MarkedDateTime = markedDateTime;
                SmartCapacityHelper.UpdateCategoryId(capacity);
            }

            foreach (var smartCapacityList in capacityLists)
            {
                smartCapacityList.CreateUserId   = createUserId;
                smartCapacityList.MarkedDateTime = markedDateTime;
                smartCapacityList.CapacityId     = capacityId;
            }
            var oldSmartCapacityLists = SmartCapacityListHelper.GetSmartCapacityLists(capacityId);
            //删除
            var delete = oldSmartCapacityLists.Where(z => capacityLists.Where(x => x.Id != 0).All(y => y.Id != z.Id));

            if (delete.Any())
            {
                SmartCapacityListHelper.Instance.Delete(delete.Select(x => x.Id));
            }
            //更新
            var update = capacityLists.Where(x => x.Id != 0);

            if (update.Any())
            {
                SmartCapacityListHelper.Instance.Update(update);
            }

            //新增
            var add = capacityLists.Where(x => x.Id == 0);

            if (add.Any())
            {
                SmartCapacityListHelper.Instance.Add(add);
            }

            OldWorkFlowHelper.Instance.OnSmartCapacityListChanged(capacityLists);
            return(Result.GenError <Result>(Error.Success));
        }