Пример #1
0
        public ProductProject Insert(ProductProject productProject)
        {
            var sql = @"Insert Into ProductProject (ProjectId, ProductId)
	                    Values (@ProjectId, @ProductId)"    ;

            using (var connection =
                       new SqlConnection(
                           "Data Source=.;Initial Catalog=Capstone;Integrated Security=False;MultipleActiveResultSets=True;User Id=capstoneUser;Password=hadleigh77")
                   )
            {
                using (var command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;

                    this.GetParameters(command, productProject);
                    command.Parameters["@ProjectId"].Direction = ParameterDirection.InputOutput;
                    command.Parameters["@ProductId"].Direction = ParameterDirection.InputOutput;

                    connection.Open();

                    command.ExecuteNonQuery();

                    productProject.ProjectId = (int)command.Parameters["@ProjectId"].Value;
                    productProject.ProductId = (int)command.Parameters["@ProductId"].Value;
                }
            }

            return(productProject);
        }
Пример #2
0
        private SqlCommand GetParameters(SqlCommand command, ProductProject productProject)
        {
            command.Parameters.AddWithValue("@ProjectId", productProject.ProjectId);
            command.Parameters.AddWithValue("@ProductId", productProject.ProductId);

            return(command);
        }
Пример #3
0
        public List <ProductProject> Save(List <Product> products, int projectId)
        {
            this.Delete(projectId);
            var productProjects = new List <ProductProject>();

            foreach (var product in products)
            {
                if (product.Selected)
                {
                    var productProject = new ProductProject()
                    {
                        ProjectId = projectId,
                        ProductId = product.ProductId
                    };

                    this._productProjectRepository.Insert(productProject);

                    productProjects.Add(productProject);
                }
            }


            return(productProjects);
        }