示例#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);
        }
示例#2
0
        public PharmacyInventoryEntity GetFakePharmacyInventoryEntity_QuantityOnHandNonZero()
        {
            var fake = new PharmacyInventoryEntity()
            {
                Id                   = 1,
                QuantityOnHand       = 5,
                UnitPrice            = 15.62M,
                ReorderQuantity      = 12,
                SellingUnitOfMeasure = "KG",
                Item                 = new ItemEntity()
                {
                    Id         = 1,
                    ItemNumber = 24156,
                    Vendor     = new ItemVendorEntity()
                    {
                        Id      = 2,
                        Name    = "VENDOR2",
                        Address = "ADDRESSVENDOR2"
                    },
                    UPC                   = "125698652100",
                    ItemDescription       = "NewItem1",
                    MinimumOrderQuantity  = 10,
                    PurchaseUnitOfMeasure = "M3",
                    ItemCost              = 10.34M,
                },
                Pharmacy = new PharmacyEntity()
                {
                    Id       = 1,
                    Hospital = new HospitalEntity()
                    {
                        Id      = 1,
                        Name    = "HOSPITAL1",
                        Address = "HOSPITALADDRESS1"
                    },
                    Name    = "PHARMACY1",
                    Address = "PHARMACYADDRESS1"
                }
            };

            return(fake);
        }