Пример #1
0
        public static void DeleteCustomer(NorthwindContext dbContext, string id)
        {
            try
            {
                Customer dataBaseCustomer = GetCustomerById(dbContext, id);

                dbContext.Customers.Remove(dataBaseCustomer);

                dbContext.SaveChanges();
            }
            catch (Exception ex) when(ExceptionTypes.IsSqlException(ex))
            {
                ex.SetMessage(DbExceptionMessages.FailedToDelete(InstanceName, id, ex.InnerException));
                throw;
            }
            catch (Exception ex) when(ExceptionTypes.IsDbException(ex))
            {
                ex.SetMessage(DbExceptionMessages.UnexpectedFailure(ex));
                throw;
            }
        }
Пример #2
0
        public static void DeleteProduct(NorthwindContext dbContext, int id)
        {
            try
            {
                Product dataBaseProduct = GetProductById(dbContext, id);

                dbContext.Products.Remove(dataBaseProduct);

                dbContext.SaveChanges();
            }
            catch (Exception ex) when(ExceptionTypes.IsSqlException(ex))
            {
                ex.SetMessage(DbExceptionMessages.FailedToDelete(InstanceName, id, ex.InnerException));
                throw;
            }
            catch (Exception ex) when(ExceptionTypes.IsDbException(ex))
            {
                ex.SetMessage(DbExceptionMessages.UnexpectedFailure(ex));
                throw;
            }
        }