public async Task <ActionResult> UpdateMedcine(int id, [FromBody] UpdateMedicineRequest request) { try { if (id < 0) { return(BadRequest("Invalid id")); } if (request == null) { return(BadRequest("Invalid request")); } var medicine = await _pharmacyService.GetMedicineById(id); if (medicine == null) { return(NotFound()); } _mapper.Map(request, medicine); await _pharmacyService.UpdateMedicine(medicine); return(Ok(request)); } catch (Exception e) { throw e; } }
public async Task <UpdateMedicineResponse> UpdateMedicinesAsync(UpdateMedicineRequest request) { var response = new UpdateMedicineResponse(); MedicineEntity entity = await _medicineRepository.GetMedicineById(request.Id); if (entity == null) { response.StatusCode = (int)HttpStatusCode.NotFound; return(response); } entity.Description = request.Description; entity.Title = request.Title; var result = await _medicineRepository.UpdateMedicinesAsync(entity); if (result) { response.StatusCode = (int)HttpStatusCode.OK; } else { response.StatusCode = (int)HttpStatusCode.InternalServerError; _logger.LogError("An error occurred"); } return(response); }
public async Task <IActionResult> UpdateMedicine([FromRoute] int id, [FromBody] UpdateMedicineRequest request) { request = request ?? new UpdateMedicineRequest(); request.Id = id; var response = await _medicineService.UpdateMedicinesAsync(request); return(GenerateResponse(response)); }