private Model.Shop CreateEntityFromDTO(DTO.Shop dto) { var shop = new Model.Shop(dto.Name, dto.OwnerId); if (dto.RowVersion != null) { shop.RowVersion = dto.RowVersion; } return(shop); }
public async Task <IActionResult> Post([FromBody] DTO.Shop dto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Model.Shop entity = CreateEntityFromDTO(dto); _context.Shops.Add(entity); await _context.SaveChangesAsync(); return(Created($"api/Shops/{entity.Id}", CreateDTOFromEntity(entity))); }
public async Task <IActionResult> Put(int id, [FromBody] DTO.Shop dto) { //fixme: comment valider que le client envoie toujours quelque chose de valide? Model.Shop entity = await FindShopById(id); if (entity == null) { return(NotFound()); } //fixme: améliorer cette implémentation entity.Name = dto.Name; entity.OwnerId = dto.OwnerId; //fixme: le premier RowVersion n'a pas d'impact. // Attardez-vous à comprendre pour quelle raison. // entity.RowVersion = dto.RowVersion; _context.Entry(entity).OriginalValues["RowVersion"] = dto.RowVersion; //pas de gestion des opening periods (voir autre controller). await _context.SaveChangesAsync(); return(Ok(CreateDTOFromEntity(entity))); }