Esempio n. 1
0
        public static bool EditStroymat(StroymatDTO order)
        {
            //List<ProductDTO> ProductsList = new List<ProductDTO>();
            using (SqlConnection conn = new SqlConnection(cs))
            {
                SqlCommand cmd = new SqlCommand("sp_update_kraska", conn);

                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@id", order.Id);
                cmd.Parameters.AddWithValue("@name", order.Name);
                cmd.Parameters.AddWithValue("@desc", order.Description);
                cmd.Parameters.AddWithValue("@price", order.Price);
                cmd.Parameters.AddWithValue("@country", order.Country);
                cmd.Parameters.AddWithValue("@man", order.Manufacturer);
                cmd.Parameters.AddWithValue("@type", order.Type);
                cmd.Parameters.AddWithValue("@discount", order.Discount);



                conn.Open();
                //dt.Load(cmd.ExecuteReader());
                cmd.ExecuteNonQuery();


                return(true);
            }
        }
Esempio n. 2
0
        public static bool AddStroymat(StroymatDTO order, out int id)
        {
            int cnt = 0;

            if (order.Img1 != null)
            {
                cnt++;
            }
            if (order.Img2 != null)
            {
                cnt++;
            }
            if (order.Img3 != null)
            {
                cnt++;
            }
            //DataTable dt = new DataTable();

            //List<ProductDTO> ProductsList = new List<ProductDTO>();
            using (SqlConnection conn = new SqlConnection(cs))
            {
                SqlCommand cmd = new SqlCommand("sp_insert_stroymateryal", conn);

                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@name", order.Name);
                cmd.Parameters.AddWithValue("@desc", order.Description);
                cmd.Parameters.AddWithValue("@price", order.Price);
                cmd.Parameters.AddWithValue("@country", order.Country);
                cmd.Parameters.AddWithValue("@man", order.Manufacturer);
                cmd.Parameters.AddWithValue("@type", order.Type);
                cmd.Parameters.AddWithValue("@discount", order.Discount);
                cmd.Parameters.AddWithValue("@imgscount", cnt);



                SqlParameter outParameter = new SqlParameter("@id", SqlDbType.Int);
                outParameter.Direction = ParameterDirection.Output;
                cmd.Parameters.Add(outParameter);
                //cmd.Parameters.Add("@items", SqlDbType.Structured);
                //cmd.Parameters.Add("@items", SqlDbType.Structured);
                //cmd.Parameters.Add("@items", SqlDbType.Structured);


                //cmd.Parameters["@items"].Value = order.Items;
                //cmd.Parameters.AddWithValue("@items", order.Items);


                conn.Open();
                //dt.Load(cmd.ExecuteReader());
                cmd.ExecuteNonQuery();
                id = Convert.ToInt32(outParameter.Value);

                //foreach (DataRow dr in dt.Rows)
                //{
                //	ProductsList.Add(dr.ConvertToProductDTO());
                //}

                return(true);
            }
        }
Esempio n. 3
0
        public bool EditStroymat(StroymatDTO str)
        {
            bool isAdded = false;

            isAdded = DataProvider.EditStroymat(str);

            return(isAdded);
        }
Esempio n. 4
0
        public string CreateStroymat([FromForm] StroymatDTO str)
        {
            bool isAdded = false;


            isAdded = DataProvider.AddStroymat(str, out var id);
            try
            {
                string path = @"imgs\stroymateryali\" + id;

                Directory.CreateDirectory(path);
                if (str.Img1?.Length > 0)
                {
                    var filePath = path + @"\1.jpg";
                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        str.Img1.CopyTo(fileStream);
                    }
                }
                if (str.Img2?.Length > 0)
                {
                    var filePath = path + @"\2.jpg";
                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        str.Img2.CopyTo(fileStream);
                    }
                }
                if (str.Img3?.Length > 0)
                {
                    var filePath = path + @"\3.jpg";
                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        str.Img3.CopyTo(fileStream);
                    }
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            return(id.ToString());
        }