public object PutArgsFormat([FromBody] IEnumerable <ArgsFormat> details) { if (details == null || !details.Any()) { return(Result.GenError <Result>(Error.ParamError)); } if (details.Any(x => x.Id == 0)) { return(Result.GenError <Result>(Error.ArgsFormatNotExist)); } if (details.Any(x => x.Name.IsNullOrEmpty())) { var ids = details.Select(x => x.Id); var cnt = ArgsFormatHelper.Instance.GetCountByIds(ids); if (cnt != details.Count()) { return(Result.GenError <Result>(Error.ArgsFormatNotExist)); } ArgsFormatHelper.Enable(details); } else { if (details.GroupBy(x => x.Name).Any(y => y.Count() > 1)) { return(Result.GenError <Result>(Error.ArgsFormatDuplicate)); } if (details.Any(x => x.MinRow > x.MaxRow)) { return(Result.GenError <Result>(Error.ArgsFormatRowError)); } var wId = details.FirstOrDefault()?.WorkshopId ?? 0; var sames = details.Select(x => x.Name); var ids = details.Select(x => x.Id); if (ArgsFormatHelper.GetHaveSame(wId, sames, ids)) { return(Result.GenError <Result>(Error.ArgsFormatIsExist)); } var olds = ArgsFormatHelper.Instance.GetByIds <ArgsFormat>(ids); if (olds.Count() != details.Count()) { return(Result.GenError <Result>(Error.ArgsFormatNotExist)); } var markedDateTime = DateTime.Now; foreach (var detail in details) { detail.MarkedDateTime = markedDateTime; detail.Remark = detail.Remark ?? ""; } ArgsFormatHelper.Instance.Update(details); } return(Result.GenError <Result>(Error.Success)); }
public object PostArgsFormat([FromBody] IEnumerable <ArgsFormat> details) { if (details == null || !details.Any()) { return(Result.GenError <Result>(Error.ParamError)); } if (details.Any(x => x.Name.IsNullOrEmpty())) { return(Result.GenError <Result>(Error.ArgsFormatNotEmpty)); } if (details.GroupBy(x => x.Name).Any(y => y.Count() > 1)) { return(Result.GenError <Result>(Error.ArgsFormatDuplicate)); } if (details.Any(x => x.MinRow > x.MaxRow)) { return(Result.GenError <Result>(Error.ArgsFormatRowError)); } var wId = details.FirstOrDefault()?.WorkshopId ?? 0; var sames = details.Select(x => x.Name); if (ArgsFormatHelper.GetHaveSame(wId, sames)) { return(Result.GenError <Result>(Error.ArgsFormatIsExist)); } var userId = Request.GetIdentityInformation(); var markedDateTime = DateTime.Now; foreach (var detail in details) { detail.CreateUserId = userId; detail.MarkedDateTime = markedDateTime; detail.Remark = detail.Remark ?? ""; detail.Col = detail.Cols.Count; } ArgsFormatHelper.Instance.Add(details); return(Result.GenError <Result>(Error.Success)); }