I'm creating a web application which on the client side consists of a Single Page Application (with Durandal) and on the server side an ASP.NET MVC site with a Domain Driven Design. The two are connected with a REST Api (Web API).
I have a relation between two entities, which on the database level is many-to-many. (Hotels <=> RoomTypes). Since in DDD a best practice is not to have many-to-many relationships I built it so that it can only be navigated from the roomtype to the hotel (since a hotel can exist without roomtypes, but a roomtype should always be associated with a hotel). The relation itself also has attributes (availability for example).
My current issue is how to associate a hotel with a roomtype however. Following DDD practices I would add a method
AddHotel to the RoomType-class.
The problem is that in the SPA, you can edit all the attributes of a roomtype (pictures, description, ...) and associated hotels in a single view. After editing these attributes, an update is submitted via the rest api. This means that everything gets submitted in one call to the server.
How would you structure the server and the rest based API so that:
- the domain stays in place and there's correct validation inside the RoomType-class
- you can post atomic updates from the single page application through the rest
- there's no code duplication on the server and the single page application