/** * Update multiple entities */ public List <ResultSingleSerialData> UpdateItems(string entityTypeName, IEnumerable <Dto> dtos) { var resultSerialDataOriginal = this.dataAdapterRead.FetchMany(entityTypeName, dtos, null); if (resultSerialDataOriginal.Items.Count() == 0) { throw new DtosException(code: 404, message: "Not Found"); } else if (resultSerialDataOriginal.Items.Count() != dtos.Count()) { throw new DtosException(code: 400, message: "Bad Request"); } else { var keyNames = this.metadataSrv.EntityTypes[entityTypeName].Key; var resultSerialDataList = DalUtils.LeftJoin(resultSerialDataOriginal.Items, dtos, (ent, dto) => Utils.CompareByKey(JObject.FromObject(ent).ToObject <Dto>(), dto, keyNames), (ent, dto) => this.dataAdapterCud.UpdateEntity(entityTypeName, JObject.FromObject(ent), dto) ); var resultSingleSerialDataList = new List <ResultSingleSerialData>(); foreach (var resultSerialData in resultSerialDataList) { if (resultSerialData.Items.Count() > 0) { resultSingleSerialDataList.Add(resultSerialData.ToSingle()); } } if (resultSingleSerialDataList.Count > 0) { return(resultSingleSerialDataList); } else { var total = 0; foreach (var resultSerialData in resultSerialDataList) { total += resultSerialData.Items.Count(); } if (total > 0) { throw new DtosException(code: 204, message: "No Content"); } else { throw new DtosException(code: 304, message: "Not Modified"); } } } }
public ResultSingleSerialData HandleUpdateEntity(string entitySetName, QueryParams queryParams, Dto dto) { entitySetName = ApiProviderDtoUtils.FixEntitySetNameCase(entitySetName, this.metadataSrv); var queryObject = QueryUtils.RenderQueryObject(queryParams); var entityTypeName = ApiProviderDtoUtils.GetEntityTypeName(entitySetName, this.metadataSrv); if (queryObject.Keys == null || queryObject.Keys.Count() != 1 || !ApiProviderDtoUtils.ValidKeys(entityTypeName, queryObject.Keys, this.metadataSrv)) { throw new DtosException(code: 400, message: "Bad Request"); } if (!ApiProviderDtoUtils.ValidDto(entityTypeName, queryObject.Keys.FirstOrDefault(), dto, this.metadataSrv)) { throw new DtosException(code: 400, message: "Bad Request"); } var resultSingleSerialData = this.dataViewDto.UpdateItem(entityTypeName, DalUtils.Extend(dto, queryObject.Keys.FirstOrDefault())); return(resultSingleSerialData); }