public object PutSmartCapacity([FromBody] IEnumerable <SmartCapacityDetail> capacities) { if (capacities == null || !capacities.Any()) { return(Result.GenError <Result>(Error.ParamError)); } if (capacities.Any(x => x.Capacity.IsNullOrEmpty())) { return(Result.GenError <Result>(Error.SmartCapacityNotEmpty)); } if (capacities.GroupBy(x => x.Category).Any(y => y.Count() > 1)) { return(Result.GenError <Result>(Error.SmartCapacityDuplicate)); } var wId = capacities.FirstOrDefault()?.WorkshopId ?? 0; var cId = capacities.FirstOrDefault()?.CategoryId ?? 0; var sames = capacities.Select(x => x.Capacity); var ids = capacities.Select(x => x.Id); if (SmartCapacityHelper.GetHaveSame(wId, cId, sames, ids)) { return(Result.GenError <Result>(Error.SmartCapacityIsExist)); } var cnt = SmartCapacityHelper.Instance.GetCountByIds(ids); if (cnt != capacities.Count()) { return(Result.GenError <Result>(Error.SmartCapacityNotExist)); } var markedDateTime = DateTime.Now; foreach (var capacity in capacities) { capacity.MarkedDateTime = markedDateTime; capacity.Remark = capacity.Remark ?? ""; } SmartCapacityHelper.Instance.Update(capacities); return(Result.GenError <Result>(Error.Success)); }
public object PostSmartCapacity([FromBody] IEnumerable <OpSmartCapacity> capacities) { if (capacities == null || !capacities.Any()) { return(Result.GenError <Result>(Error.ParamError)); } if (capacities.Any(x => x.Capacity.IsNullOrEmpty())) { return(Result.GenError <Result>(Error.SmartCapacityNotEmpty)); } if (capacities.GroupBy(x => x.Capacity).Any(y => y.Count() > 1)) { return(Result.GenError <Result>(Error.SmartCapacityDuplicate)); } var wId = capacities.FirstOrDefault()?.WorkshopId ?? 0; var cId = capacities.FirstOrDefault()?.CategoryId ?? 0; var sames = capacities.Select(x => x.Capacity); if (SmartCapacityHelper.GetHaveSame(wId, cId, sames)) { return(Result.GenError <Result>(Error.SmartCapacityIsExist)); } var categoryIds = capacities.Select(x => x.CategoryId); if (categoryIds.Any(x => x == 0)) { return(Result.GenError <Result>(Error.SmartProcessCodeCategoryNotExist)); } if (capacities.Any(x => !x.List.Any() || x.List.Any(y => !y.IsSet()))) { return(Result.GenError <Result>(Error.SmartCapacityListNotEmpty)); } var userId = Request.GetIdentityInformation(); var markedDateTime = DateTime.Now; foreach (var capacity in capacities) { capacity.CreateUserId = userId; capacity.MarkedDateTime = markedDateTime; capacity.Remark = capacity.Remark ?? ""; } SmartCapacityHelper.Instance.Add(capacities); var capacityList = SmartCapacityHelper.GetSmartCapacities(capacities.Select(x => x.Capacity)); foreach (var smartCapacity in capacities) { var capacity = capacityList.FirstOrDefault(x => x.Capacity == smartCapacity.Capacity); if (capacity != null) { foreach (var l in smartCapacity.List) { l.CapacityId = capacity.Id; l.CreateUserId = userId; l.MarkedDateTime = markedDateTime; } } } var add = capacities.SelectMany(x => x.List).Where(y => y.CapacityId != 0); SmartCapacityListHelper.Instance.Add(add); OldWorkFlowHelper.Instance.OnSmartCapacityListChanged(add); return(Result.GenError <Result>(Error.Success)); }