예제 #1
0
        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
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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 !!!!"));
        }
예제 #5
0
        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"));
        }
예제 #6
0
 public static Drug DrugDTOToDrug(DrugDTO drugDTO)
 {
     return(new Drug(DrugTypeMapper.DrugTypeDTOToDrugType(drugDTO.DrugTypeDTO), drugDTO.Name, drugDTO.Quantity, drugDTO.ExpirationDate, drugDTO.Producer));
 }