Exemple #1
0
        public async Task <ActionResult <V1DTO.ExampleDTO> > PostExample(V1DTO.ExampleDTO exampleDTO)
        {
            // Create example
            var bllEntity = _mapper.Map(exampleDTO);

            _bll.Example.Add(bllEntity, User.UserGuidId());
            await _bll.SaveChangesAsync();

            exampleDTO.Id = bllEntity.Id;
            return(CreatedAtAction(
                       "GetExample",
                       new { id = exampleDTO.Id, version = HttpContext.GetRequestedApiVersion()?.ToString() ?? "0" },
                       exampleDTO
                       ));
        }
Exemple #2
0
        public async Task <IActionResult> PutExample(Guid id, V1DTO.ExampleDTO exampleDTO)
        {
            // Don't allow wrong data
            if (id != exampleDTO.Id)
            {
                return(BadRequest(new V1DTO.MessageDTO("id and example.id do not match")));
            }
            // Only allow editing own Examples
            var example = await _bll.Example.GetPersonalAsync(exampleDTO.Id, User.UserGuidId());

            if (example == null)
            {
                _logger.LogError($"EDIT. No such example: {exampleDTO.Id}, user: {User.UserGuidId()}");
                return(NotFound(new V1DTO.MessageDTO($"No Example found for id {id.ToString()}")));
            }
            // Update existing example
            await _bll.Example.UpdateAsync(_mapper.Map(exampleDTO), User.UserGuidId());

            await _bll.SaveChangesAsync();

            return(NoContent());
        }