-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
I'd like to be able to map into an existing object.
Use-case: I get the entity from the database, I have the model posted into the action. I don't want to replace the entity, just update those properties I got from the model.
Proposed:
public void MapToExistingDestination(this Source source, Destionation destination)
{
destination.Name = source.Name;
destination.Reason = source.Reason;
}
Then in my controller action (or service) I can have code like this:
[HttpPut("{id}")]
public ActionResult<Model> Put(int id, [FromBody]CustomerModel model)
{
Customer customer = customerRepository.GetById(id);
if (customer == null)
{
return NotFound();
}
model.MapToExistingCustomer(customer);
customerRepository.Save(customer);
return model;
}
Metadata
Metadata
Assignees
Labels
No labels