Пример #1
0
        public static int AddNewProduct(NorthwindContext dbContext, ProductDTO newProduct)
        {
            try
            {
                Product dataBaseProduct = newProduct.GetDataBaseProductObject();

                dbContext.Products.Add(dataBaseProduct);
                dbContext.SaveChanges();

                return(dataBaseProduct.ProductId);
            }
            catch (Exception ex) when(ExceptionTypes.IsSqlException(ex))
            {
                ex.SetMessage(DbExceptionMessages.FailedToAdd(InstanceName, ex.InnerException));
                throw;
            }
            catch (Exception ex) when(ExceptionTypes.IsDbException(ex))
            {
                ex.SetMessage(DbExceptionMessages.UnexpectedFailure(ex));
                throw;
            }
        }
Пример #2
0
        public static string AddNewCustomer(NorthwindContext dbContext, CustomerDTO newCustomer)
        {
            try
            {
                Customer dataBaseCustomer = newCustomer.GetDataBaseCustomerObject();

                dbContext.Customers.Add(dataBaseCustomer);
                dbContext.SaveChanges();

                return(dataBaseCustomer.CustomerId);
            }
            catch (Exception ex) when(ExceptionTypes.IsSqlException(ex))
            {
                ex.SetMessage(DbExceptionMessages.FailedToAdd(InstanceName, ex.InnerException));
                throw;
            }
            catch (Exception ex) when(ExceptionTypes.IsDbException(ex))
            {
                ex.SetMessage(DbExceptionMessages.UnexpectedFailure(ex));
                throw;
            }
        }
Пример #3
0
        public static int AddNewEmployee(NorthwindContext dbContext, EmployeeDTO newEmployee)
        {
            try
            {
                Employee dataBaseEmployee = newEmployee.GetDataBaseEmployeeObject();

                dbContext.Employees.Add(dataBaseEmployee);
                dbContext.SaveChanges();

                return(dataBaseEmployee.EmployeeId);
            }
            catch (Exception ex) when(ExceptionTypes.IsSqlException(ex))
            {
                ex.SetMessage(DbExceptionMessages.FailedToAdd(InstanceName, ex.InnerException));
                throw;
            }
            catch (Exception ex) when(ExceptionTypes.IsDbException(ex))
            {
                ex.SetMessage(DbExceptionMessages.UnexpectedFailure(ex));
                throw;
            }
        }