Esempio n. 1
0
        public async Task <PharmacyInventoryEntity> CreatePharmacyInventory(CreatePharmacyInventoryRequest createPharmacyInventoryRequest)
        {
            PharmacyInventoryEntity pharmacyInventoryReturn = null;

            try
            {
                var itemExists = await CheckIfItemExists(createPharmacyInventoryRequest.IdItem);

                if (itemExists)
                {
                    var pharmacyExists = await CheckIfPharmacyExists(createPharmacyInventoryRequest.IdPharmacy);

                    if (pharmacyExists)
                    {
                        var pharmacyInventoryTable = _mapper.Map <PharmacyInventoryTable>(createPharmacyInventoryRequest);

                        var id = await CreatePharmacyInventoryTable(pharmacyInventoryTable);

                        if (id > 0)
                        {
                            var pharmacyInventoryTableRecovered = await GetPharmacyInventoryTableById(id);

                            var itemTableRecovered = await GetItemTableById(pharmacyInventoryTableRecovered.IdItem);

                            var vendorTableRecovered = await GetVendorTableById(itemTableRecovered.IdVendor);

                            var pharmacyTableRecovered = await GetPharmacyTableById(pharmacyInventoryTableRecovered.IdPharmacy);

                            var hospitalTableRecovered = await GetHospitalTableById(pharmacyTableRecovered.IdHospital);

                            var pharmacyInventory = _mapper.Map <PharmacyInventoryEntity>(pharmacyInventoryTableRecovered);
                            var item     = _mapper.Map <ItemEntity>(itemTableRecovered);
                            var vendor   = _mapper.Map <ItemVendorEntity>(vendorTableRecovered);
                            var pharmacy = _mapper.Map <PharmacyEntity>(pharmacyTableRecovered);
                            var hospital = _mapper.Map <HospitalEntity>(hospitalTableRecovered);
                            item.Vendor                = vendor;
                            pharmacy.Hospital          = hospital;
                            pharmacyInventory.Item     = item;
                            pharmacyInventory.Pharmacy = pharmacy;

                            pharmacyInventoryReturn = pharmacyInventory;
                        }
                    }
                    else
                    {
                        throw new Exception("Pharmacy doesn't exists.");
                    }
                }
                else
                {
                    throw new Exception("Item doesn't exists.");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(pharmacyInventoryReturn);
        }
Esempio n. 2
0
        public async Task <CreatePharmacyInventoryResponse> Post([FromBody] CreatePharmacyInventoryRequest request)
        {
            CreatePharmacyInventoryResponse createPharmacyInventoryResponse = null;

            try
            {
                if (request.QuantityOnHand <= 0)
                {
                    throw new Exception($"QuantityOnHand must be non zero.");
                }

                var item = await _domainService.CreatePharmacyInventory(request);

                if (item != null)
                {
                    createPharmacyInventoryResponse = _mapper.Map <CreatePharmacyInventoryResponse>(item);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(createPharmacyInventoryResponse);
        }
Esempio n. 3
0
        public CreatePharmacyInventoryRequest GetFakeCreatePharmacyInventoryRequest_OnlyIf_Item_And_Pharmacy_Exists_Success()
        {
            var fake = new CreatePharmacyInventoryRequest()
            {
                IdItem               = 1,
                IdPharmacy           = 1,
                QuantityOnHand       = 2,
                UnitPrice            = 15.62M,
                ReorderQuantity      = 12,
                SellingUnitOfMeasure = "KG"
            };

            return(fake);
        }
Esempio n. 4
0
        public CreatePharmacyInventoryRequest GetFakeCreatePharmacyInventoryRequest_QuantityOnHandNonZero()
        {
            var fake = new CreatePharmacyInventoryRequest()
            {
                IdItem               = 1,
                IdPharmacy           = 1,
                QuantityOnHand       = 5,
                UnitPrice            = 15.62M,
                ReorderQuantity      = 12,
                SellingUnitOfMeasure = "KG"
            };

            return(fake);
        }
Esempio n. 5
0
 public async Task <PharmacyInventoryEntity> CreatePharmacyInventory(CreatePharmacyInventoryRequest createPharmacyInventoryRequest)
 {
     return(await Task.FromResult(DataSetTest.GetFakePharmacyInventoryEntity_QuantityOnHandNonZero()));
 }