예제 #1
0
        public async Task <IActionResult> Post([FromBody] DTOs.Person person, ApiVersion version = null)
        {
            if (version == null)
            {
                version = ApiVersion.Default;
            }

            var newEntity = new v1.Person(person.Firstname, person.LastName, person.Email, person.Phone);
            await _repository.AddAsync(newEntity);

            await _repository.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetById), new { id = newEntity.Id, version = $"{version}" }, _mapper.Map <DTOs.Person>(newEntity)));
        }
예제 #2
0
        public async Task <IActionResult> Put(int id, [FromBody] DTOs.Person person, ApiVersion version = null)
        {
            if (version == null)
            {
                version = ApiVersion.Default;
            }

            var entityFound = await _repository.ReadAsync(id);

            if (entityFound == null)
            {
                return(NotFound());
            }

            var updateCommand = new v1.Person(person.Firstname, person.LastName, person.Email, person.Phone);

            entityFound.Update(updateCommand);
            _repository.Edit(entityFound);

            return(AcceptedAtAction(nameof(GetById), new { id = entityFound.Id, version = $"{version}" }, _mapper.Map <DTOs.Person>(entityFound)));
            //return Ok(_mapper.Map<DTOs.Person>(entityFound));
        }