Exemplo n.º 1
0
        public object PutCapacity([FromBody] IEnumerable <Capacity> details)
        {
            if (details == null || !details.Any())
            {
                return(Result.GenError <Result>(Error.ParamError));
            }
            var markedDateTime = DateTime.Now;

            foreach (var detail in details)
            {
                detail.MarkedDateTime = markedDateTime;
                detail.Remark         = detail.Remark ?? "";
            }
            if (details.Any(x => x.Name.IsNullOrEmpty()))
            {
                var ids = details.Select(x => x.Id);
                var cnt = CapacityHelper.Instance.GetCountByIds(ids);
                if (cnt != details.Count())
                {
                    return(Result.GenError <Result>(Error.CapacityNotExist));
                }
                CapacityHelper.Enable(details);
            }
            else
            {
                if (details.GroupBy(x => x.Name).Any(y => y.Count() > 1))
                {
                    return(Result.GenError <Result>(Error.CapacityDuplicate));
                }
                var wId  = details.FirstOrDefault()?.WorkshopId ?? 0;
                var cIds = details.Select(x => x.TypeId).Distinct();
                if (cIds.Any(x => x == 0))
                {
                    return(Result.GenError <Result>(Error.FlowTypeNotExist));
                }
                var sames = details.Select(x => x.Name);
                var ids   = details.Select(x => x.Id);
                if (CapacityHelper.GetHaveSame(wId, cIds, sames, ids))
                {
                    return(Result.GenError <Result>(Error.CapacityIsExist));
                }
                var cnt = FlowTypeHelper.Instance.GetCountByIds(cIds);
                if (cnt != details.Count())
                {
                    return(Result.GenError <Result>(Error.FlowTypeNotExist));
                }
                if (details.Any(x => x.StepIds.Count != x.StepVs.Count))
                {
                    return(Result.GenError <Result>(Error.CapacityListError));
                }
                cnt = CapacityHelper.Instance.GetCountByIds(ids);
                if (cnt != details.Count())
                {
                    return(Result.GenError <Result>(Error.CapacityNotExist));
                }
                CapacityHelper.Instance.Update(details);
            }
            return(Result.GenError <Result>(Error.Success));
        }
Exemplo n.º 2
0
        public object PostCapacity([FromBody] IEnumerable <Capacity> details)
        {
            if (details == null || !details.Any())
            {
                return(Result.GenError <Result>(Error.ParamError));
            }
            if (details.Any(x => x.Name.IsNullOrEmpty()))
            {
                return(Result.GenError <Result>(Error.CapacityNotEmpty));
            }
            if (details.GroupBy(x => x.Name).Any(y => y.Count() > 1))
            {
                return(Result.GenError <Result>(Error.CapacityDuplicate));
            }

            var wId  = details.FirstOrDefault()?.WorkshopId ?? 0;
            var cIds = details.Select(x => x.TypeId).Distinct();

            if (cIds.Any(x => x == 0))
            {
                return(Result.GenError <Result>(Error.FlowTypeNotExist));
            }
            var sames = details.Select(x => x.Name);

            if (CapacityHelper.GetHaveSame(wId, cIds, sames))
            {
                return(Result.GenError <Result>(Error.CapacityIsExist));
            }
            var cnt = FlowTypeHelper.Instance.GetCountByIds(cIds);

            if (cnt != details.Count())
            {
                return(Result.GenError <Result>(Error.FlowTypeNotExist));
            }
            if (details.Any(x => x.StepIds.Count != x.StepVs.Count))
            {
                return(Result.GenError <Result>(Error.CapacityListError));
            }

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

            foreach (var capacity in details)
            {
                capacity.CreateUserId   = userId;
                capacity.MarkedDateTime = markedDateTime;
                capacity.Remark         = capacity.Remark ?? "";
            }
            CapacityHelper.Instance.Add(details);
            return(Result.GenError <Result>(Error.Success));
        }