コード例 #1
0
        public static void UpdateProduct(NorthwindContext dbContext, int id, ProductDTO modifiedProduct)
        {
            try
            {
                Product dataBaseProduct = GetProductById(dbContext, id);

                modifiedProduct.ModifyDataBaseProduct(dataBaseProduct);

                dbContext.SaveChanges();
            }
            catch (Exception ex) when(ExceptionTypes.IsSqlException(ex))
            {
                ex.SetMessage(DbExceptionMessages.FailedToUpdate(InstanceName, id, ex.InnerException));
                throw;
            }
            catch (Exception ex) when(ExceptionTypes.IsDbException(ex))
            {
                ex.SetMessage(DbExceptionMessages.UnexpectedFailure(ex));
                throw;
            }
        }
コード例 #2
0
        public static void UpdateCustomer(NorthwindContext dbContext, string id, CustomerDTO modifiedCustomer)
        {
            try
            {
                Customer dataBaseCustomer = GetCustomerById(dbContext, id);

                modifiedCustomer.ModifyDataBaseCustomer(dataBaseCustomer);

                dbContext.SaveChanges();
            }
            catch (Exception ex) when(ExceptionTypes.IsSqlException(ex))
            {
                ex.SetMessage(DbExceptionMessages.FailedToUpdate(InstanceName, id, ex.InnerException));
                throw;
            }
            catch (Exception ex) when(ExceptionTypes.IsDbException(ex))
            {
                ex.SetMessage(DbExceptionMessages.UnexpectedFailure(ex));
                throw;
            }
        }
コード例 #3
0
        public static void UpdateEmployee(NorthwindContext dbContext, int id, EmployeeDTO modifiedEmployee)
        {
            try
            {
                Employee dataBaseEmployee = GetEmployeeById(dbContext, id);

                modifiedEmployee.ModifyDataBaseEmployee(dataBaseEmployee);

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