public Result PutDeviceCategory([FromBody] IEnumerable <DeviceCategory> details) { if (details == null || !details.Any()) { return(Result.GenError <Result>(Error.ParamError)); } if (details.Any(x => x.Name.IsNullOrEmpty())) { return(Result.GenError <Result>(Error.DeviceCategoryNotEmpty)); } if (details.GroupBy(x => x.Name).Any(y => y.Count() > 1)) { return(Result.GenError <Result>(Error.DeviceCategoryDuplicate)); } var wId = details.FirstOrDefault()?.WorkshopId ?? 0; var sames = details.Select(x => x.Name); var ids = details.Select(x => x.Id); if (DeviceCategoryHelper.GetHaveSame(wId, sames, ids)) { return(Result.GenError <Result>(Error.DeviceCategoryIsExist)); } var cnt = DeviceCategoryHelper.Instance.GetCountByIds(ids); if (cnt != details.Count()) { return(Result.GenError <Result>(Error.DeviceCategoryNotExist)); } var markedDateTime = DateTime.Now; foreach (var process in details) { process.MarkedDateTime = markedDateTime; process.Remark = process.Remark ?? ""; } DeviceCategoryHelper.Instance.Update(details); return(Result.GenError <Result>(Error.Success)); }
public Result PostDeviceCategory([FromBody] IEnumerable <DeviceCategory> details) { if (details == null || !details.Any()) { return(Result.GenError <Result>(Error.ParamError)); } if (details.Any(x => x.Name.IsNullOrEmpty())) { return(Result.GenError <Result>(Error.DeviceCategoryNotEmpty)); } if (details.GroupBy(x => x.Name).Any(y => y.Count() > 1)) { return(Result.GenError <Result>(Error.DeviceCategoryDuplicate)); } var wId = details.FirstOrDefault()?.WorkshopId ?? 0; var sames = details.Select(x => x.Name); if (DeviceCategoryHelper.GetHaveSame(wId, sames)) { return(Result.GenError <Result>(Error.DeviceCategoryIsExist)); } var userId = Request.GetIdentityInformation(); var markedDateTime = DateTime.Now; foreach (var process in details) { process.CreateUserId = userId; process.MarkedDateTime = markedDateTime; process.Remark = process.Remark ?? ""; } DeviceCategoryHelper.Instance.Add(details); return(Result.GenError <Result>(Error.Success)); }