public async Task <IActionResult> UpdateDrug([FromBody] DrugDTO drugDTO) { if (drugDTO == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var itExists = await _drugRepository.ItExists(drugDTO.Id); if (!itExists) { return(NotFound()); } var drug = _mapper.Map <Drug>(drugDTO); var isSuccess = await _drugRepository.Update(drug); if (!isSuccess) { return(InternalError($"Update operation failed")); } return(NoContent()); //success }
public static DrugDTO DrugToDrugDTO(Drug drug) { DrugDTO drugDTO = new DrugDTO(); drugDTO.Name = drug.Name; drugDTO.Quantity = drug.Quantity; drugDTO.ExpirationDate = drug.ExpirationDate; drugDTO.Producer = drug.Producer; drugDTO.DrugTypeDTO = DrugTypeMapper.DrugTypeTODrugTypeDTO(drug.DrugType); return(drugDTO); }
private DrugDTO getDrugInfo(Drug drug) { var category = _context.Categories.SingleOrDefault(category => category.Id == drug.CategoryId); var drugDTO = new DrugDTO(); drugDTO.Id = drug.Id; drugDTO.Name = drug.Name; drugDTO.Price = drug.Price; drugDTO.ExpirationDate = drug.ExpirationDate; drugDTO.Category = category; return(drugDTO); }
public async Task <IActionResult> AddDrugs([FromBody] DrugDTO drugDTO) { if (!ModelState.IsValid) { return(BadRequest()); } if (drugDTO == null) { return(BadRequest("Wrong data supplied")); } var drug = mapper.Map <DrugDTO, Drug>(drugDTO); if (await drugRepository.AddDrugAsync(drug)) { return(Ok("Success")); } return(BadRequest("Drug already exist !!!!")); }
public async Task <IActionResult> UpdateDrug([FromBody] DrugDTO drugDTO) { if (!ModelState.IsValid) { return(null); } if (drugDTO == null) { return(BadRequest("Not Successful")); } var drug = mapper.Map <DrugDTO, Drug>(drugDTO); await drugRepository.UpdateDrug(drug); if (drug.Quantity <= 3) { } if (drug.Quantity == 0) { } return(Ok("Success")); }
public static Drug DrugDTOToDrug(DrugDTO drugDTO) { return(new Drug(DrugTypeMapper.DrugTypeDTOToDrugType(drugDTO.DrugTypeDTO), drugDTO.Name, drugDTO.Quantity, drugDTO.ExpirationDate, drugDTO.Producer)); }