コード例 #1
0
        public async Task <Country> UpdateCountryAsync(int id, string name, bool save = true)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException($"Country name could not be null or empty!");
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException($"Country name could not be WhiteSpace!");
            }

            var country = await FindCountryByIDAsync(id);

            if (country == null)
            {
                throw new ArgumentException($"Country with ID {id} does not exist!");
            }
            else
            {
                country.Name = name;
                try
                {
                    context.Update(country);
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
            }
            return(country);
        }
コード例 #2
0
        public async Task <Address> UpdateAddressAsync(int id, string addressString, bool save = true)
        {
            if (string.IsNullOrEmpty(addressString))
            {
                throw new ArgumentNullException($"Address could not be null or empty!");
            }

            if (string.IsNullOrWhiteSpace(addressString))
            {
                throw new ArgumentException($"Address could not be WhiteSpace!");
            }

            var address = await FindAddressByIDAsync(id);

            if (address == null)
            {
                throw new ArgumentException($"Address with ID {id} does not exist!");
            }
            else
            {
                address.Name = addressString;
                try
                {
                    context.Update(address);
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
            }
            return(address);
        }
コード例 #3
0
        public async Task <Purchase> UpdatePurchaseAsync(
            int purchaseId,
            int supplierId,
            int warehouseId,
            DateTime purchaseDate,
            DateTime deliveryDate,
            DateTime deadlineDate,
            bool save = true)
        {
            var purchase = await FindPurchaseByIDAsync(purchaseId);

            if (purchase == null)
            {
                throw new ArgumentException($"Purchase with ID {purchaseId} does not exist!");
            }
            else
            {
                purchase.SupplierID   = supplierId;
                purchase.WarehouseID  = warehouseId;
                purchase.PurchaseDate = purchaseDate;
                purchase.DeliveryDate = deliveryDate;
                purchase.DeadlineDate = deadlineDate;
                try
                {
                    context.Update(purchase);
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
            }
            return(purchase);
        }
コード例 #4
0
        public async Task <Warehouse> UpdateWarehouseAsync(
            int id,
            string warehouseName,
            int countryID,
            int cityID,
            int addressID,
            bool save = true)
        {
            if (string.IsNullOrEmpty(warehouseName))
            {
                throw new ArgumentException($"WarehouseName could not be null or empty!");
            }

            if (string.IsNullOrWhiteSpace(warehouseName))
            {
                throw new ArgumentException($"WarehouseName could not be WhiteSpace!");
            }

            if (this.context.Cities.Find(cityID) == null)
            {
                throw new ArgumentException($"City with ID {cityID} does not exist!");
            }

            if (this.context.Countries.Find(countryID) == null)
            {
                throw new ArgumentException($"Country with ID {cityID} does not exist!");
            }

            if (this.context.Addresses.Find(addressID) == null)
            {
                throw new ArgumentException($"Address with ID {cityID} does not exist!");
            }

            var warehouse = await FindWarehouseByIDAsync(id);

            if (warehouse == null)
            {
                throw new ArgumentException($"Warehouse with ID {id} does not exist!");
            }
            else
            {
                warehouse.Name      = warehouseName;
                warehouse.CountryID = countryID;
                warehouse.CityID    = cityID;
                warehouse.AddressID = addressID;
                try
                {
                    context.Update(warehouse);
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
            }
            return(warehouse);
        }
コード例 #5
0
        public async Task <Supplier> UpdateSupplierAsync(
            int id,
            string supplierName,
            string uin,
            int countryId,
            int cityId,
            int addressId,
            string userId,
            bool isDeleted,
            bool save = true)
        {
            if (string.IsNullOrEmpty(supplierName))
            {
                throw new ArgumentNullException($"supplierName could not be null or empty!");
            }

            if (string.IsNullOrWhiteSpace(supplierName))
            {
                throw new ArgumentException($"supplierName could not be WhiteSpace!");
            }

            var supplier = await FindSupplierByIDAsync(id);

            if (supplier == null)
            {
                throw new ArgumentException($"Supplier with ID {id} does not exist!");
            }
            else
            {
                supplier.Name        = supplierName;
                supplier.UIN         = uin;
                supplier.CountryID   = countryId;
                supplier.CityID      = cityId;
                supplier.AddressID   = addressId;
                supplier.StoreUserId = userId;
                supplier.IsDeleted   = isDeleted;
                try
                {
                    context.Update(supplier);
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
            }

            return(supplier);
        }