public DataResult GetDefectType([FromQuery] int qId, int wId, bool menu)
        {
            var result = new DataResult();

            result.datas.AddRange(menu
                ? DefectTypeHelper.GetMenu(wId, qId)
                : DefectTypeHelper.GetDetails(wId, qId));
            if (qId != 0 && !result.datas.Any())
            {
                result.errno = Error.DefectTypeNotExist;
                return(result);
            }
            return(result);
        }
        public object PutDefectType([FromBody] IEnumerable <DefectType> details)
        {
            if (details == null || !details.Any())
            {
                return(Result.GenError <Result>(Error.ParamError));
            }
            if (details.Any(x => x.Id == 0))
            {
                return(Result.GenError <Result>(Error.DefectTypeNotExist));
            }
            var markedDateTime = DateTime.Now;

            foreach (var detail in details)
            {
                detail.MarkedDateTime = markedDateTime;
                detail.Remark         = detail.Remark ?? "";
            }
            if (details.Any(x => x.Type.IsNullOrEmpty()))
            {
                var ids = details.Select(x => x.Id);
                var cnt = DefectTypeHelper.Instance.GetCountByIds(ids);
                if (cnt != details.Count())
                {
                    return(Result.GenError <Result>(Error.DefectTypeNotExist));
                }
                DefectTypeHelper.Enable(details);
            }
            else
            {
                if (details.GroupBy(x => x.Type).Any(y => y.Count() > 1))
                {
                    return(Result.GenError <Result>(Error.DefectTypeDuplicate));
                }
                var wId   = details.FirstOrDefault()?.WorkshopId ?? 0;
                var sames = details.Select(x => x.Type);
                var ids   = details.Select(x => x.Id);
                if (DefectTypeHelper.GetHaveSame(wId, sames, ids))
                {
                    return(Result.GenError <Result>(Error.DefectTypeIsExist));
                }
                var cnt = DefectTypeHelper.Instance.GetCountByIds(ids);
                if (cnt != details.Count())
                {
                    return(Result.GenError <Result>(Error.DefectTypeNotExist));
                }
                DefectTypeHelper.Instance.Update(details);
            }
            return(Result.GenError <Result>(Error.Success));
        }
        public object PostDefectType([FromBody] IEnumerable <DefectType> details)
        {
            if (details == null || !details.Any())
            {
                return(Result.GenError <Result>(Error.ParamError));
            }
            if (details.Any(x => x.Type.IsNullOrEmpty()))
            {
                return(Result.GenError <Result>(Error.DefectTypeNotEmpty));
            }
            if (details.GroupBy(x => x.Type).Any(y => y.Count() > 1))
            {
                return(Result.GenError <Result>(Error.DefectTypeDuplicate));
            }

            var wId   = details.FirstOrDefault()?.WorkshopId ?? 0;
            var sames = details.Select(x => x.Type);

            if (DefectTypeHelper.GetHaveSame(wId, sames))
            {
                return(Result.GenError <Result>(Error.DefectTypeIsExist));
            }

            if (details.Any(x => x.Type.IsNullOrEmpty()))
            {
                return(Result.GenError <Result>(Error.DefectTypeNotEmpty));
            }

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

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