Exemple #1
0
        public async Task <ActionResult <MedicineReadDto> > Get([FromRoute] Guid id)
        {
            MedicineReadDto medicine = _mapper.Map <MedicineReadDto>(await _medicineService.GetByIdAsync(id));

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

            return(Ok(medicine));
        }
Exemple #2
0
 public async Task <ActionResult <MedicineReadDto> > Post([FromBody] MedicineCreateDto medicine)
 {
     if (ModelState.IsValid)
     {
         try
         {
             MedicineReadDto newMedicine = _mapper.Map <MedicineReadDto>(await _medicineService.AddAsync(_mapper.Map <Medicine>(medicine)));
             return(CreatedAtAction("Get", new { id = newMedicine.Id }, newMedicine));
         }
         catch (ApiException ex)
         {
             return(StatusCode(ex.StatusCode, new { error = true, message = ex.Message }));
         }
     }
     return(BadRequest());
 }