Esempio n. 1
0
        public async Task <Sale> InsertSaleAsync(Sale sale)
        {
            _Context.Add(sale);
            try
            {
                await _Context.SaveChangesAsync();
            }
            catch (System.Exception exp)
            {
                _Logger.LogError($"Error in {nameof(InsertSaleAsync)}: " + exp.Message);
            }

            return(sale);
        }
 public async Task <bool> UpdateProductAsync(Product product)
 {
     //Will update all properties of the Customer
     _Context.Products.Attach(product);
     _Context.Entry(product).State = EntityState.Modified;
     try
     {
         return(await _Context.SaveChangesAsync() > 0 ? true : false);
     }
     catch (Exception exp)
     {
         _Logger.LogError($"Error in {nameof(UpdateProductAsync)}: " + exp.Message);
     }
     return(false);
 }
Esempio n. 3
0
        public async Task InsertCustomersSampleData(BikesDBContext db)
        {
            var customers = GetCustomers();

            db.Customers.AddRange(customers);

            try
            {
                int numAffected = await db.SaveChangesAsync();

                _Logger.LogInformation($"Saved {numAffected} customers");
            }
            catch (Exception exp)
            {
                _Logger.LogError($"Error in {nameof(BikesDBSeeder)}: " + exp.Message);
                throw;
            }

            var products = GetProducts();

            db.Products.AddRange(products);

            try
            {
                int numAffected = await db.SaveChangesAsync();

                _Logger.LogInformation($"Saved {numAffected} products");
            }
            catch (Exception exp)
            {
                _Logger.LogError($"Error in {nameof(BikesDBSeeder)}: " + exp.Message);
                throw;
            }

            var salePersons = GetSalePersons();

            db.Salespersons.AddRange(salePersons);

            try
            {
                int numAffected = await db.SaveChangesAsync();

                _Logger.LogInformation($"Saved {numAffected} SalePersons");
            }
            catch (Exception exp)
            {
                _Logger.LogError($"Error in {nameof(BikesDBSeeder)}: " + exp.Message);
                throw;
            }

            var discounts = GetDiscounts();

            db.Discounts.AddRange(discounts);

            try
            {
                int numAffected = await db.SaveChangesAsync();

                _Logger.LogInformation($"Saved {numAffected} Discount");
            }
            catch (Exception exp)
            {
                _Logger.LogError($"Error in {nameof(BikesDBSeeder)}: " + exp.Message);
                throw;
            }

            var sales = GetSales();

            db.Sales.AddRange(sales);

            try
            {
                int numAffected = await db.SaveChangesAsync();

                _Logger.LogInformation($"Saved {numAffected} Sale");
            }
            catch (Exception exp)
            {
                _Logger.LogError($"Error in {nameof(BikesDBSeeder)}: " + exp.Message);
                throw;
            }
        }