public IActionResult Delete(string id)
        {
            Customer dataBaseCustomer = new CustomerSC().GetCustomerById(id);

            if (dataBaseCustomer == null)
            {
                return(NotFound());
            }

            try
            {
                new CustomerSC().DeleteCustomer(dataBaseCustomer);
            }
            catch (Exception ex) when(ExceptionTypes.IsSqlException(ex))
            {
                string message = SqlExceptionMessages.GetCustomSqlExceptionMessage(ex.InnerException as SqlException);

                if (message != null)
                {
                    return(Conflict(message));
                }

                throw;
            }

            return(NoContent());
        }
        public IActionResult Put(string id, [FromBody] CustomerContactInfoPutDTO modifiedCustomer)
        {
            Customer dataBaseCustomer = new CustomerSC().GetCustomerById(id);

            if (dataBaseCustomer == null)
            {
                return(NotFound());
            }

            try
            {
                //TODO: Check if it is possible to pass the dataBaseCustomer insted of the id.
                new CustomerSC().UpdateCustomer(id, modifiedCustomer);
            }
            catch (Exception ex) when(ExceptionTypes.IsSqlException(ex))
            {
                string message = SqlExceptionMessages.GetCustomSqlExceptionMessage(ex.InnerException as SqlException);

                if (message != null)
                {
                    return(Conflict(message));
                }

                throw;
            }

            return(NoContent());
        }
        public IActionResult Delete(int id)
        {
            Employee dataBaseEmployee = new EmployeeSC().GetEmployeeById(id);

            if (dataBaseEmployee == null)
            {
                return(NotFound());
            }

            try
            {
                new EmployeeSC().DeleteEmployee(dataBaseEmployee);
            }
            catch (Exception ex) when(ExceptionTypes.IsSqlException(ex))
            {
                string message = SqlExceptionMessages.GetCustomSqlExceptionMessage(ex.InnerException as SqlException);

                if (message != null)
                {
                    return(Conflict(message));
                }

                throw;
            }

            return(NoContent());
        }
        public IActionResult Put(int id, [FromBody] EmployePersonalInfoPutDTO modifiedEmployee)
        {
            Employee dataBaseEmployee = new EmployeeSC().GetEmployeeById(id);

            if (dataBaseEmployee == null)
            {
                return(NotFound());
            }

            try
            {
                //TODO: Check if it is possible to pass the dataBaseEmployee insted of the id.
                new EmployeeSC().UpdateEmployee(id, modifiedEmployee);
            }
            catch (Exception ex) when(ExceptionTypes.IsSqlException(ex.InnerException))
            {
                string message = SqlExceptionMessages.GetCustomSqlExceptionMessage(ex as SqlException);

                if (message != null)
                {
                    return(Conflict(message));
                }

                throw;
            }

            return(NoContent());
        }
Ejemplo n.º 5
0
        public IActionResult Delete(int id)
        {
            Product dataBaseProduct = new ProductSC().GetProductById(id);

            if (dataBaseProduct == null)
            {
                return(NotFound());
            }

            try
            {
                new ProductSC().DeleteProduct(dataBaseProduct);
            }
            catch (Exception ex) when(ExceptionTypes.IsSqlException(ex))
            {
                string message = SqlExceptionMessages.GetCustomSqlExceptionMessage(ex.InnerException as SqlException);

                if (message != null)
                {
                    return(Conflict(message));
                }

                throw;
            }

            return(NoContent());
        }
Ejemplo n.º 6
0
        public IActionResult Put(int id, [FromBody] ProductBasicInfoPutDTO modifiedProduct)
        {
            Product dataBaseProduct = new ProductSC().GetProductById(id);

            if (dataBaseProduct == null)
            {
                return(NotFound());
            }

            try
            {
                //TODO: Check if it is possible to pass the dataBaseProduct insted of the id.
                new ProductSC().UpdateProduct(id, modifiedProduct);
            }
            catch (Exception ex) when(ExceptionTypes.IsSqlException(ex))
            {
                string message = SqlExceptionMessages.GetCustomSqlExceptionMessage(ex.InnerException as SqlException);

                if (message != null)
                {
                    return(Conflict(message));
                }

                throw;
            }

            return(NoContent());
        }
        public IActionResult Post([FromBody] CustomerContactInfoPostDTO newCustomer)
        {
            string id;

            try
            {
                id = new CustomerSC().AddNewCustomer(newCustomer);
            }
            catch (Exception ex) when(ExceptionTypes.IsSqlException(ex))
            {
                string message = SqlExceptionMessages.GetCustomSqlExceptionMessage(ex.InnerException as SqlException);

                if (message != null)
                {
                    return(Conflict(message));
                }

                throw;
            }

            return(Created("GET " + Request.Path.Value + "/" + id, id));
        }