public object PostFlowStep([FromBody] IEnumerable <FlowStep> details) { if (details == null || !details.Any()) { return(Result.GenError <Result>(Error.ParamError)); } if (details.Any(x => x.Name.IsNullOrEmpty())) { return(Result.GenError <Result>(Error.FlowStepNotEmpty)); } if (details.GroupBy(x => x.Name).Any(y => y.Count() > 1)) { return(Result.GenError <Result>(Error.FlowStepDuplicate)); } var ids = details.Where(x => x.CategoryId != 0).Select(x => x.CategoryId).Distinct(); var cnt = DeviceCategoryHelper.Instance.GetCountByIds(ids); if (cnt != ids.Count()) { return(Result.GenError <Result>(Error.DeviceCategoryNotExist)); } ids = details.Where(x => x.FormatId != 0).Select(x => x.FormatId).Distinct(); cnt = DeviceCategoryHelper.Instance.GetCountByIds(ids); if (cnt != ids.Count()) { return(Result.GenError <Result>(Error.ArgsFormatNotExist)); } ids = details.SelectMany(x => x.DefectIds).Distinct(); cnt = DefectHelper.Instance.GetCountByIds(ids); if (cnt != ids.Count()) { return(Result.GenError <Result>(Error.DefectNotExist)); } var wId = details.FirstOrDefault()?.WorkshopId ?? 0; var sames = details.Select(x => x.Name); if (FlowStepHelper.GetHaveSame(wId, sames)) { return(Result.GenError <Result>(Error.FlowStepIsExist)); } var userId = Request.GetIdentityInformation(); var markedDateTime = DateTime.Now; foreach (var detail in details) { detail.CreateUserId = userId; detail.MarkedDateTime = markedDateTime; detail.List = detail.List ?? ""; detail.Remark = detail.Remark ?? ""; } FlowStepHelper.Instance.Add(details); return(Result.GenError <Result>(Error.Success)); }
public object PutFlowStep([FromBody] IEnumerable <FlowStep> details) { if (details == null || !details.Any()) { return(Result.GenError <Result>(Error.ParamError)); } if (details.Any(x => x.Id == 0)) { return(Result.GenError <Result>(Error.FlowStepNotExist)); } var markedDateTime = DateTime.Now; foreach (var detail in details) { detail.MarkedDateTime = markedDateTime; detail.Remark = detail.Remark ?? ""; } if (details.Any(x => x.Name.IsNullOrEmpty())) { if (details.Any(x => !x.List.IsNullOrEmpty())) { var eIds = details.SelectMany(x => x.DefectIds).Distinct(); var cnt = DefectHelper.Instance.GetCountByIds(eIds); if (cnt != eIds.Count()) { return(Result.GenError <Result>(Error.DefectNotExist)); } foreach (var detail in details) { detail.MarkedDateTime = markedDateTime; } FlowStepHelper.Defect(details); } else { var ids = details.Select(x => x.Id); var cnt = FlowStepHelper.Instance.GetCountByIds(ids); if (cnt != details.Count()) { return(Result.GenError <Result>(Error.FlowStepNotExist)); } FlowStepHelper.Enable(details); } } else { if (details.GroupBy(x => x.Name).Any(y => y.Count() > 1)) { return(Result.GenError <Result>(Error.FlowStepDuplicate)); } var ids = details.Where(x => x.CategoryId != 0).Select(x => x.CategoryId).Distinct(); var cnt = DeviceCategoryHelper.Instance.GetCountByIds(ids); if (cnt != ids.Count()) { return(Result.GenError <Result>(Error.DeviceCategoryNotExist)); } ids = details.Where(x => x.FormatId != 0).Select(x => x.FormatId).Distinct(); cnt = ArgsFormatHelper.Instance.GetCountByIds(ids); if (cnt != ids.Count()) { return(Result.GenError <Result>(Error.ArgsFormatNotExist)); } ids = details.SelectMany(x => x.DefectIds).Distinct(); cnt = DefectHelper.Instance.GetCountByIds(ids); if (cnt != ids.Count()) { return(Result.GenError <Result>(Error.DefectNotExist)); } var wId = details.FirstOrDefault()?.WorkshopId ?? 0; var sames = details.Select(x => x.Name); ids = details.Select(x => x.Id); if (FlowStepHelper.GetHaveSame(wId, sames, ids)) { return(Result.GenError <Result>(Error.FlowStepIsExist)); } var olds = FlowStepHelper.Instance.GetByIds <FlowStep>(ids); if (olds.Count() != details.Count()) { return(Result.GenError <Result>(Error.FlowStepNotExist)); } FlowStepHelper.Instance.Update(details); } return(Result.GenError <Result>(Error.Success)); }