Beispiel #1
0
        public static bool UpdateAdProduct(AdProduct product)
        {
            const string query = "update dbo.AdProducts set Name=@Name, AdId=@AdId, ProductCategoryId=@ProductCategoryId, " +
                                 "Weight=@Weight, PricePerWeight=@PricePerWeight, CurrencyId=@Currency where Id = @Id";

            var connect    = new SqlConnection(connStr);
            var sqlCommand = new SqlCommand(query, connect);

            sqlCommand.Parameters.AddWithValue("Id", product.Id);
            AddAddOrUpdateSqlParameters(sqlCommand.Parameters, product);

            int result = 0;

            try
            {
                connect.Open();
                result = sqlCommand.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                string methodName = MethodBase.GetCurrentMethod().Name;
                throw new Exception("in AdProductsDAL." + methodName + "(): " + ex);
            }
            finally
            {
                connect.Close();
            }

            return(result > 0);
        }
Beispiel #2
0
        public static AdProduct GetAdProduct(int id)
        {
            AdProduct    result     = null;
            const string query      = @"select * from dbo.AdProducts where Id=@Id";
            var          connection = new SqlConnection(connStr);
            var          sqlCommand = new SqlCommand(query, connection);

            sqlCommand.Parameters.AddWithValue("Id", id);

            try
            {
                connection.Open();
                var reader = sqlCommand.ExecuteReader();
                if (reader.Read())
                {
                    result = ReadAdProductInfo(reader);
                }

                reader.Close();
            }
            catch (Exception ex)
            {
                string methodName = MethodBase.GetCurrentMethod().Name;
                throw new Exception("in AdProductsDAL." + methodName + "(): " + ex);
            }
            finally
            {
                connection.Close();
            }

            return(result);
        }
Beispiel #3
0
        public static int AddAdProduct(AdProduct product)
        {
            int          newAdProductId = 0;
            const string query          = @"insert into dbo.AdProducts (Name, AdId, ProductCategoryId, Weight, PricePerWeight, CurrencyId) 
values (@Name, @AdId, @ProductCategoryId, @Weight, @PricePerWeight, @CurrencyId);
DECLARE @newAdProductID int;
   SELECT @newAdProductID = SCOPE_IDENTITY();
   SELECT @newAdProductID";

            var connect    = new SqlConnection(connStr);
            var sqlCommand = new SqlCommand(query, connect);
            var parameters = sqlCommand.Parameters;

            AddAddOrUpdateSqlParameters(parameters, product);

            try
            {
                connect.Open();
                newAdProductId = (int)sqlCommand.ExecuteScalar();
            }
            catch (Exception ex)
            {
                string methodName = MethodBase.GetCurrentMethod().Name;
                throw new Exception("in AdProductsDAL." + methodName + "(): " + ex);
            }
            finally
            {
                connect.Close();
            }

            return(newAdProductId);
        }
 public static AdProductViewModel ToViewModel(this AdProduct product)
 {
     return(new AdProductViewModel()
     {
         Name = product.Name,
         Description = product.Description,
         Retailers = product.AdRetailers.Select(retailer => retailer.ToViewModel()).ToList()
     });
 }
Beispiel #5
0
        public void ShowProductDetails(LinearLayout parentView, AdProduct product, int id)
        {
            var layout = new LinearLayout(this);

            layout.Orientation = Orientation.Vertical;

            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent,
                                                                                   ViewGroup.LayoutParams.WrapContent);
            layout.LayoutParameters = layoutParams;

            var innerLayout = new LinearLayout(this);

            innerLayout.Orientation      = Orientation.Vertical;
            innerLayout.LayoutParameters = layoutParams;
            innerLayout.Id         = id;
            innerLayout.Visibility = ViewStates.Gone;

            var productTitle = new TextView(this);

            productTitle.SetTextSize(ComplexUnitType.Sp, 20);
            productTitle.SetPadding(16, 26, 16, 26);
            productTitle.SetText(product.Name, TextView.BufferType.Normal);
            productTitle.Click += (e, args) => OnProductExpand(productTitle, innerLayout);
            layout.AddView(productTitle);

            var productDescription = new TextView(this);

            productDescription.SetTextSize(ComplexUnitType.Sp, 15);
            productDescription.SetPadding(10, 10, 10, 10);
            productDescription.SetText(product.Description, TextView.BufferType.Normal);
            innerLayout.AddView(productDescription);

            foreach (var item in product.Retailers)
            {
                var button = new Button(this);
                button.SetText(item.Name, TextView.BufferType.Normal);
                button.SetPadding(16, 16, 16, 16);
                button.SetTextSize(ComplexUnitType.Sp, 20);
                button.Click += (e, args) => OpenRetailerUrl(item.Url);
                innerLayout.AddView(button);
            }

            layout.AddView(innerLayout);
            parentView.AddView(layout);
        }
Beispiel #6
0
        private static AdProduct ReadAdProductInfo(SqlDataReader reader)
        {
            var result = new AdProduct
            {
                Id   = (int)reader["Id"],
                AdId = (int)reader["AdId"],
                ProductCategoryId = (int)reader["ProductCategoryId"],
                Currency          = (Currencies)(int)reader["CurrencyId"]
            };

            if (reader["Weight"] != DBNull.Value)
            {
                result.Weight = Convert.ToSingle(reader["Weight"].ToString());
            }
            if (reader["PricePerWeight"] != DBNull.Value)
            {
                result.PricePerWeight = Convert.ToSingle(reader["PricePerWeight"].ToString());
            }
            if (reader["Name"] != DBNull.Value)
            {
                result.Name = ((string)reader["Name"]).Trim();
            }
            return(result);
        }
Beispiel #7
0
        private static void AddAddOrUpdateSqlParameters(SqlParameterCollection parameters, AdProduct product)
        {
            if (product.Name != null)
            {
                parameters.AddWithValue("Name", product.Name);
            }
            else
            {
                parameters.AddWithValue("Name", DBNull.Value);
            }

            parameters.AddWithValue("AdId", product.AdId);
            parameters.AddWithValue("ProductCategoryId", product.ProductCategoryId);
            parameters.AddWithValue("Weight", product.Weight);
            parameters.AddWithValue("PricePerWeight", product.PricePerWeight);
            parameters.AddWithValue("CurrencyId", product.Currency);
        }