public int AddMedicine(Medicine request)
        {
            if (string.IsNullOrWhiteSpace(request.FullName))
            {
                throw new InvalidOperationException("Medicine Full name is a required field.");
            }
            if (string.IsNullOrWhiteSpace(request.Brand))
            {
                throw new InvalidOperationException("Medicine Brand is a required field.");
            }
            if (request.ExpiryDate <= DateTime.Today.AddDays(15))
            {
                throw new InvalidOperationException("Medicines with expiry date of 15 days or less can not be added.");
            }
            if (request.Quantity <= 0)
            {
                throw new InvalidOperationException("Medicines with quantity less than zero can not be added");
            }
            if (request.Price < 0)
            {
                throw new InvalidOperationException("Medicine price should be non-negative number.");
            }

            request.Id = m_MedicineRepository.GetMaxId() + 1;
            m_MedicineRepository.AddMedicine(request);

            return(request.Id);
        }
        public async Task <MedicineDTO> Handle(MedicineAddCommand request, CancellationToken cancellationToken)
        {
            try
            {
                Medicine medicine =
                    await _medicineRepository.AddMedicine(_mapper.Map <Medicine>(request));

                return(this._mapper.Map <MedicineDTO>(medicine));
            }
            catch (System.Exception ex)
            {
                throw;
            }
        }
        /// <summary>
        /// create new medicine
        /// </summary>
        /// <param name="medicine"></param>
        /// <returns></returns>
        public async Task <ServiceResponse> AddMedicine(MedicineEditDto medicine)
        {
            try
            {
                Medicine medicineEntity = _mapper.Map <Medicine>(medicine);

                await _medicineRepository.AddMedicine(medicineEntity);

                medicine.MedicineGuid = medicineEntity.MedicineGuid;
                return(ServiceResponse.Success(medicine, ResponseCodes.Created));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error Occured in {this.GetType().Name}. Error: {ex.Message}");
                throw;
            }
        }
        public async Task <IActionResult> AddEditPharmacy([FromBody] MedicineAddEditDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            //edit
            if (model.medicineId == 0)
            {
                var medicineResult = new Medicine()
                {
                    Name        = model.name,
                    Description = model.description,
                    Manufacture = model.manufacture,
                    Supplier    = model.supplier
                };

                _medicineRepository.AddMedicine(medicineResult);
            }
            else
            {
                var medicinResult = await _medicineRepository.GetMedicine(model.medicineId);

                if (medicinResult == null)
                {
                    return(BadRequest());
                }

                medicinResult.Name        = model.name;
                medicinResult.Description = model.description;
                medicinResult.Manufacture = model.manufacture;
                medicinResult.Supplier    = model.supplier;

                _medicineRepository.UpdateMedicine(medicinResult);
            }


            if (_medicineRepository.SaveChanges() > 0)
            {
                return(Ok());
            }

            return(BadRequest());
        }
Exemple #5
0
        public async Task <bool> AddMedicine(MedicineDomain medicine)
        {
            var med = _mapper.Map <Medicine>(medicine);

            return(await _medicineRepository.AddMedicine(med));
        }
Exemple #6
0
 public Medicine SaveNewMedicine(Medicine request)
 {
     return(_repository.AddMedicine(request));
 }