Beispiel #1
0
        public async Task <CoreValuesKRA> UpdateCoreValue(ObjectId objId, CoreValueForUpdateDto updateDto)
        {
            if (updateDto != null)
            {
                var filter = Builders <CoreValuesKRA> .Filter.Where(r => r.Id == objId);

                var update = Builders <CoreValuesKRA> .Update.Set("Name", updateDto.Name);

                var result = await Collection.FindOneAndUpdateAsync(filter, update, options : new FindOneAndUpdateOptions <CoreValuesKRA> {
                    ReturnDocument = ReturnDocument.After
                });

                return(result);
            }

            return(null);
        }
        public async Task <IActionResult> Update(string id, JsonPatchDocument <CoreValueForUpdateDto> updateDto)
        {
            ObjectId Id = new ObjectId(id);

            var entityToUpdate = new CoreValueForUpdateDto();

            updateDto.ApplyTo(entityToUpdate);

            var res = await coreValueRepo.UpdateCoreValue(Id, entityToUpdate);

            if (res != null)
            {
                var entityReturn = mapper.Map <CoreValueKRAForViewDto>(res);

                return(CreatedAtRoute("CoreValue", new { Id = Id }, entityReturn));
            }

            return(NotFound());
        }