Пример #1
0
        /// <summary>
        /// Button Click Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ButtonClick(object sender, EventArgs e)
        {
            using (var ts = new TransactionScope())
            {
                var product = new Product
                {
                    Title = txt_title.Text,
                    Description = txt_description.Text,
                    Price = (decimal)TextHelper.ToDecimal(txt_price.Text),
                    Image = "",
                };

                //Update
                int id;
                if (!_objProduct.Insert(product, out id))
                    return;

                Id = id;

                foreach (var productCategoryTable in from ListItem item
                                                         in cbl_category.Items
                                                     where item.Selected
                                                     select new ProductCategoryTable
                                                     {
                                                         ProductId = Id,
                                                         ProductCategoryId = (int)TextHelper.ToInteger(item.Value)
                                                     })
                {
                    _objProductCategoryTable.Insert(productCategoryTable);
                }

                //Add image
                var fileUrl = UploadFile();

                //if upload file success
                if (!string.IsNullOrEmpty(fileUrl))
                    product.Image = fileUrl;

                if (!_objProduct.Update(product))
                    return;

                ts.Complete();

                Redirect("~/Admin/Gift/");
            }
        }
Пример #2
0
        /// <summary>
        /// Button Click Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ButtonClick(object sender, EventArgs e)
        {
            //create volunteering model and assign values to it
            var fileUrl = string.IsNullOrEmpty(fu_productImage.FileName) ? img_productImage.ImageUrl : UploadFile();

            //if failed to upload file
            if (string.IsNullOrEmpty(fileUrl))
                return;

            using (var ts = new TransactionScope())
            {
                var volunteer = new Product
                {
                    ProductId = Id,
                    Title = txt_title.Text,
                    Description = txt_description.Text,
                    Price = (decimal)TextHelper.ToDecimal(txt_price.Text),
                    Image = fileUrl,
                };

                //Update
                if (!_objProduct.Update(volunteer))
                    return;

                //Delete current Product Category
                if (!_objProductCategoryTable.DeleteByProductId(Id))
                    return;

                foreach (var productCategoryTable in from ListItem item
                                                         in cbl_category.Items
                                                     where item.Selected
                                                     select new ProductCategoryTable
                                                     {
                                                         ProductId = Id,
                                                         ProductCategoryId = (int)TextHelper.ToInteger(item.Value)
                                                     })
                {
                    _objProductCategoryTable.Insert(productCategoryTable);
                }

                ts.Complete();

                Redirect("~/Admin/Gift/");
            }
        }
Пример #3
0
 partial void DeleteProduct(Product instance);
Пример #4
0
 partial void UpdateProduct(Product instance);
Пример #5
0
 partial void InsertProduct(Product instance);