public List <ProductData> ListMatchingProducts(string match)
        {
            // Create a list of products
            List <ProductData> productsList = new List <ProductData>();

            try {
                // Connect to the ProductsModel database
                using (ProductsModel database = new ProductsModel()) {
                    // Fetch the products in the database
                    List <Product> products = (from product in database.Products
                                               where product.Name.Contains(match)
                                               select product).ToList();
                    foreach (Product product in products)
                    {
                        ProductData productData = new ProductData()
                        {
                            Name  = product.Name,
                            Code  = product.Code,
                            Price = product.Price
                        };
                        productsList.Add(productData);
                    }
                }
            } catch {
                // Ignore exceptions in this implementation
            }
            // Return the list of products
            return(productsList);
        }
        public ProductData GetProduct(string productCode)
        {
            ProductData productData = null;

            try {
                // Connect to the ProductsModel database
                using (ProductsModel database = new ProductsModel()) {
                    // Find the first product that matches the specified product code
                    if (ProductExists(productCode, database))
                    {
                        Product matchingProduct = database.Products.First(p =>
                                                                          String.Compare(p.Code, productCode) == 0);
                        productData = new ProductData()
                        {
                            Name  = matchingProduct.Name,
                            Code  = matchingProduct.Code,
                            Price = matchingProduct.Price
                        };
                    }
                }
            } catch {
                // Ignore exceptions in this implementation
            }
            // Return the product
            return(productData);
        }
        // GET: Store/Products/Bikes
        public ActionResult Bikes(int subcategory)
        {
            ProductsModel model = new ProductsModel()
            {
                SubcategoryID = subcategory
            };

            switch (subcategory)
            {
            case 1:
                model.ViewTitle = "Mountain Bikes";
                break;

            case 2:
                model.ViewTitle = "Road Bikes";
                break;

            case 3:
                model.ViewTitle = "Touring Bikes";
                break;

            default:
                throw new ArgumentException();
            }

            return(View("Bikes", model));
        }
Exemplo n.º 4
0
        public void OnGet()
        {
            //Get the products from the list for the table.
            ProductsModel productModel = new ProductsModel();

            Products = productModel.FindAll();
        }
Exemplo n.º 5
0
        public long SaveProducts(ProductsModel _ProductsModel)
        {
            long flg = 0;

            try
            {
                ArrayList al = new ArrayList();


                al.Add(_ProductsModel.ProductID);
                al.Add(_ProductsModel.Code);
                al.Add(_ProductsModel.Name);
                al.Add(_ProductsModel.ProductCategory);
                al.Add(_ProductsModel.Status);
                al.Add(_ProductsModel.efDate);
                al.Add(_ProductsModel.Spec);

                _General.Set(al, "sp_InsertUpdateProducts", out flg);
                ///flg = DAL.ExecuteSP("sp_InsertUpdateProducts", Params, al);
            }
            catch (Exception ex)
            {
                PLog.Error("Error::Class > OutwardDocument, Method >SaveProducts()", ex);
            }
            return(flg);
        }
Exemplo n.º 6
0
        public ProductsModel EditProdcut(int ID)
        {
            ProductsModel objProductsModel = new ProductsModel();

            try
            {
                DataTable dt = GetGridData(ID);

                if (dt != null && dt.Rows.Count > 0)
                {
                    objProductsModel.ProductID       = Convert.ToInt32(dt.Rows[0]["ID"].ToString());
                    objProductsModel.Code            = dt.Rows[0]["Code"].ToString();
                    objProductsModel.Name            = dt.Rows[0]["Name"].ToString();
                    objProductsModel.ProductCategory = Convert.ToInt32(dt.Rows[0]["ProductCategoryID"].ToString());
                    objProductsModel.Status          = Convert.ToInt32(dt.Rows[0]["Status"].ToString());
                    if (dt.Rows[0]["eDate"] == DBNull.Value)
                    {
                        objProductsModel.efDate = ConverDate(DateTime.Now);
                    }
                    else
                    {
                        objProductsModel.efDate = ConverDate(Convert.ToDateTime(dt.Rows[0]["eDate"]));
                    }

                    objProductsModel.Spec = dt.Rows[0]["Spec"].ToString();

                    objProductsModel.Price = Convert.ToDecimal(dt.Rows[0]["Price"].ToString());
                }
            }
            catch (Exception ex)
            {
                PLog.Error("Error::Class > Products, Method >EditProdcut(int ID)", ex);
            }
            return(objProductsModel);
        }
Exemplo n.º 7
0
        public async Task <IActionResult> PutProductsModel([FromRoute] int id, [FromBody] ProductsModel productsModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != productsModel.Product_id)
            {
                return(BadRequest());
            }

            _context.Entry(productsModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductsModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 8
0
        public IActionResult Index()
        {
            var products = new List <ProductModel>();

            products.Add(new ProductModel()
            {
                Id = 1, Name = "HP 15-af122nd ", ImageUrl = "http://tinyurl.com/z2ukhl7", Price = 699.0M
            });
            products.Add(new ProductModel()
            {
                Id = 2, Name = "Acer Aspire ES1-521-83ZG ", ImageUrl = "http://tinyurl.com/hczk5hq", Price = 899.0M
            });
            products.Add(new ProductModel()
            {
                Id = 3, Name = "Apple MacBook Pro Retina 13,3'' 256 GB - 2,7 GHZ  ", ImageUrl = "http://tinyurl.com/jeqkw4w", Price = 1539.0M
            });
            products.Add(new ProductModel()
            {
                Id = 4, Name = "Microsoft Surface Pro 4 - i5 - 8 GB - 256 GB ", ImageUrl = "http://tinyurl.com/gtwtle6", Price = 1449.0M
            });

            var productsModel = new ProductsModel()
            {
                Products = products
            };

            return(View(productsModel));
        }
Exemplo n.º 9
0
        public ActionResult List()
        {
            InitData();

            var           guid = Convert.ToString(Session[PRODUCT_LIST_GUID_KEY]);
            ProductsModel model;
            var           useDb = Convert.ToBoolean(Session[USE_PERSISTENT_STORAGE_KEY]);

            if (useDb)
            {
                var service = new ProductService();
                model = service.GetProductsModel(Convert.ToString(Session[LOGGED_USER_NAME_KEY]));
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(guid))
                {
                    model = CacheManager.RetrieveObjectById(guid) as ProductsModel;
                }
                else
                {
                    model = new ProductsModel();
                }
            }


            return(View(model));
        }
Exemplo n.º 10
0
        private static Product MockProductAndProductModelWithNoData(out ProductsModel productsModel)
        {
            var responseMock = Mock.Of <Product>();

            productsModel = Mock.Of <ProductsModel>();
            return(responseMock);
        }
Exemplo n.º 11
0
 public ActionResult Index(ProductsModel productModel)
 {
     sessionUserIdCookie = Request.Cookies["UserId"];
     if (Request.IsAjaxRequest() && sessionUserIdCookie != null)
     {
         try
         {
             if (productModel.ProductId > 0)
             {
                 _productLogic.Update(productModel);
                 return(Json("Producto modificado correctamente"));
             }
             else
             {
                 _productLogic.Add(productModel);
                 return(Json("Producto creado correctamente"));
             }
         }
         catch (PersonalizedException personalizedException)
         {
             return(Json(personalizedException.Message));
         }
     }
     else
     {
         return(RedirectToAction("AccessDenied", "Users"));
     }
 }
Exemplo n.º 12
0
        public static ProductsModel GetProduct(ProductsModel product)
        {
            try
            {
                ApplicationDbContext context = new ApplicationDbContext();

                Product prod = context.products.FirstOrDefault(pd => pd.ID == product.ID);

                ProductsModel pm = new ProductsModel
                {
                    ID            = prod.ID,
                    Name          = prod.Name,
                    Image         = prod.Image,
                    Price         = prod.Price,
                    SubCategoryID = int.Parse(prod.subCategoryID.ToString()),
                    Quantity      = prod.Quantity,
                    SupplierID    = prod.SupplierID,
                    SupplierName  = prod.Supplier.UserName
                    , CategoryID  = int.Parse(prod.subCategory.CategoryID.ToString())
                }
                ;

                return(pm);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 13
0
 public static List <ProductsModel> GetAllProduct(int catid)
 {
     try
     {
         ApplicationDbContext context = new ApplicationDbContext();
         var productlist = context.products.Where(ps => ps.subCategoryID == catid).ToList();
         List <ProductsModel> prodlist = new List <ProductsModel>();
         foreach (var item in productlist)
         {
             ProductsModel pm = new ProductsModel
             {
                 ID            = item.ID,
                 Name          = item.Name,
                 Image         = item.Image,
                 Price         = item.Price,
                 SubCategoryID = int.Parse(item.subCategoryID.ToString()),
                 Quantity      = item.Quantity,
                 SupplierID    = item.SupplierID,
                 SupplierName  = item.Supplier.UserName
                 ,
                 CategoryID = int.Parse(item.subCategory.CategoryID.ToString())
             }
             ;
             prodlist.Add(pm);
         }
         return(prodlist);
     }
     catch
     {
         return(null);
     }
 }
Exemplo n.º 14
0
        public void When_Get_Product_With_Id_2_Then_Show_Only_This_Product()
        {
            var _productOptions = new DbContextOptionsBuilder <ProductsContext>().UseInMemoryDatabase("products_detail").Options;
            var _productContext = new ProductsContext(_productOptions);

            ProductsModel productData = new ProductsModel {
                id                = 2,
                name              = "43 Piece dinner Set",
                price             = (Decimal)12.95,
                availability      = "InStock",
                stockAvailability = 10,
                age               = "3_to_5",
                gender            = "FEMALE",
                brand             = "CoolKidz"
            };

            _productContext.Products.Add(productData);
            _productContext.SaveChanges();

            ProductsService productsService = new ProductsService(_productContext);
            var             actualResult    = productsService.getProductDetail(2);

            var expectedResult = _productContext.Products.First();

            Assert.Equal(expectedResult, actualResult);
        }
Exemplo n.º 15
0
        public async Task <ActionResult <ProductsModel> > PostProductsModel(ProductsModel ProductsModel)
        {
            _context.ProductsModel.Add(ProductsModel);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetProductsModel", new { id = ProductsModel.IdProduct }, ProductsModel));
        }
Exemplo n.º 16
0
        private void xemChiTiếtToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int id = TextUtils.ToInt(grvData.GetFocusedRowCellValue(colObjectID));

            if (id == 0)
            {
                return;
            }

            if (BaiThucHanh.ID > 0)
            {
                BaiThucHanhModel model = (BaiThucHanhModel)BaiThucHanhBO.Instance.FindByPK(id);
                int version            = TextUtils.ToInt(grvData.GetFocusedRowCellValue(colVersion));

                frmBaiTHDetail frm = new frmBaiTHDetail();
                frm.BaiThucHanh   = model;
                frm.IsShowVersion = true;
                frm.Version       = version;
                TextUtils.OpenForm(frm);
            }
            else
            {
                ProductsModel model   = (ProductsModel)ProductsBO.Instance.FindByPK(id);
                int           version = TextUtils.ToInt(grvData.GetFocusedRowCellValue(colVersion));

                frmProduct frm = new frmProduct();
                frm.Product       = model;
                frm.IsShowVersion = true;
                frm.Version       = version;
                TextUtils.OpenForm(frm);
            }
        }
Exemplo n.º 17
0
        private void btnCreateVersion_Click(object sender, EventArgs e)
        {
            int id = TextUtils.ToInt(grvData.GetFocusedRowCellValue(colID));

            if (id == 0)
            {
                return;
            }
            ProductsModel product = (ProductsModel)ProductsBO.Instance.FindByPK(id);

            DialogResult result = MessageBox.Show("Bạn có chắc muốn tạo phiên bản cho sản phẩm [" + product.Name + "] ?",
                                                  TextUtils.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.No)
            {
                return;
            }

            string           reason = "";
            frmVersionReason frm    = new frmVersionReason();

            if (frm.ShowDialog() == DialogResult.OK)
            {
                reason = frm.Reason;
            }
            else
            {
                return;
            }

            createProductVersion(product, reason);

            loadGrid(true);
        }
Exemplo n.º 18
0
        public IActionResult searchProduct(string product_name)
        {
            var product = new ProductsModel();

            ViewBag.product = product.searchProduct(product_name);
            return(View("~/Views/User/DetailProduct.cshtml"));
        }
Exemplo n.º 19
0
        public bool AddStock(string productCode, decimal quantity)
        {
            try
            {
                // Connect to the ProductsModel database
                using (ProductsModel database = new ProductsModel())
                {
                    // Find the ProductID for the specified product
                    int productID = (from p in database.Products where String.Compare(p.Code, productCode) == 0 select p.Id).First();

                    // Find the Stock object that matches the parameters passed
                    // in to the operation
                    Stock stock = database.Stocks.First(pi => pi.Id == productID);
                    stock.Quantity   = quantity;
                    stock.LastUpdate = DateTime.Now;

                    database.Stocks.Add(stock);

                    database.SaveChanges();
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
        private void Decrement_Button_Clicked(object sender, System.EventArgs e)
        {
            decimal       basePrice         = 0;
            ProductsModel selectedItem      = ProductsView.SelectedItem as ProductsModel;
            ProductsModel productsModelData = (from row in ProductsList where row.ProductId == selectedItem.ProductId select row).FirstOrDefault();

            if (productsModelData != null && Convert.ToInt32(productsModelData.Quantity) > 0)
            {
                ProductsList.Remove(productsModelData);
                basePrice = Convert.ToInt32(productsModelData.SellPrice);
                productsModelData.Quantity = Convert.ToString(Convert.ToInt32(productsModelData.Quantity) - 1);

                //productsModelData.Price = Convert.ToString(Convert.ToInt32(productsModelData.Price) - basePrice);
                ProductsList.Add(productsModelData);
                prodAddedPrice = Convert.ToInt32(productsModelData.SellPrice);

                //else if(Convert.ToInt32(productsModelData.Quantity) == 1)
                //{
                //    Delete_Button_Clicked(sender, e);
                //}
                TotalAmount.Text          = Convert.ToString(Convert.ToDecimal(TotalAmount.Text) - basePrice);
                ProductsView.ItemsSource  = null;
                ProductsView.ItemsSource  = ProductsList.OrderBy(x => x.SerialNo);
                ProductsView.SelectedItem = null;
                ProductsView.SelectedItem = productsModelData;
            }
        }
Exemplo n.º 21
0
        public List <ProductData> ListProducts()
        {
            // Create a list of products
            List <ProductData> productsList = new List <ProductData>();

            try
            {
                using (ProductsModel database = new ProductsModel())
                {
                    List <Product> products = (from product in database.Products select product).ToList();

                    foreach (Product product in products)
                    {
                        ProductData productData = new ProductData()
                        {
                            Name  = product.Name,
                            Code  = product.Code,
                            Price = product.Price
                        };
                        productsList.Add(productData);
                    }
                }
            }
            catch
            {
                // Ignore exceptions in this implementation
            }
            return(productsList);
        }
Exemplo n.º 22
0
        public ActionResult Detail(string id)
        {
            var _id      = int.Parse(id.Split('-').Last());
            var coiunt   = 0;
            var getCount = db.web_vangia_project.FirstOrDefault(x => x.vangia_id_project == _id);

            if (getCount?.vangia_order_project != null)
            {
                coiunt = (int)getCount.vangia_order_project;
            }
            var dataprodu = db.web_vangia_project.Find(_id);

            dataprodu.vangia_order_project = coiunt + 1;
            db.Entry(dataprodu).State      = EntityState.Modified;
            db.SaveChanges();
            var qrData = (from dataPro in db.web_vangia_project
                          where dataPro.vangia_status_project == 1 && dataPro.company == 4 && dataPro.vangia_id_project == _id
                          select dataPro).FirstOrDefault();

            var datareatle =
                db.web_vangia_project.Where(
                    x =>
                    x.company == 4 && x.vangia_status_project == 1 &&
                    x.vangia_typeid_project == qrData.vangia_typeid_project).ToList();
            var dataProductFeature = datareatle.OrderBy(x => Guid.NewGuid());
            var dataAll            = new ProductsModel
            {
                tblProject  = qrData,
                ListProject = dataProductFeature.ToList()
            };

            return(View(dataAll));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,ProductID,EAN,Title,Brand,ShortDescription,FullDescription,Image,Weight,Price,Category,SubCategory,SubSubCategory")] ProductsModel productsModel)
        {
            if (id != productsModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(productsModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductsModelExists(productsModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(productsModel));
        }
Exemplo n.º 24
0
        public IActionResult showProductDetail(int product_id)
        {
            var product = new ProductsModel();

            ViewBag.product = product.showProductDetail(product_id);
            return(View("~/Views/User/DetailProduct.cshtml"));
        }
Exemplo n.º 25
0
        private ProductsModel GetModel(int page, int categoryID, string searchString)
        {
            var data = db.Products.Select(p => p)
                       .Where(p => categoryID == 0 ||
                              p.CategoryID == categoryID)
                       .Where(p => string.IsNullOrEmpty(searchString) ||
                              p.ProductDescShort.Contains(searchString))
                       .OrderBy(p => p.ProductName)
                       .Skip((page - 1) * PAGESIZE).Take(PAGESIZE);

            ProductsModel model = new ProductsModel
            {
                Products   = data,
                Pagination = new PaginationModel
                {
                    CurrentPage = page,
                    ItemsOnPage = PAGESIZE,
                    TotalItems  = categoryID == 0
                                                 ? db.Products.Count()
                                                 : db.Products.Select(p => p)
                                  .Where(p => p.CategoryID == categoryID)
                                  .Where(p => p.ProductDescShort.Contains(searchString)).Count()
                },

                CategoryID = categoryID
            };

            return(model);
        }
Exemplo n.º 26
0
    public static ProductsModel GetRandomPro()
    {
        ProductsModel pro = new ProductsModel();
        try
        {

            using (DataContentDataContext dc = new DataContentDataContext())
            {
                var items = (from temp in dc.Products
                             select temp);
                int count = items.Count(); // 1st round-trip
                int index = new Random().Next(count);
                Product i = items.Skip(index).FirstOrDefault();
                ProductsModel p = new ProductsModel(i.Id, i.Header, i.Name, i.Descrition, i.Price, i.Link_Image_Small, i.Link_Image, i.Creater, i.CreateDate, i.Modifier, i.ModifyDate);
                pro = p;

            }
            return pro;
        }
        catch (Exception)
        {
            return pro;

        }
    }
Exemplo n.º 27
0
        private ProductsModel GetModel(int page, int categoryId, string searchString)
        {
            var data = _context.Products.Select(p => p)
                       .Where(p => categoryId == 0 || p.CategoryId == categoryId)
                       .Where(p => string.IsNullOrEmpty(searchString) || p.Description.Contains(searchString))
                       .OrderBy(p => p.ProductName)
                       .Skip((page - 1) * PageSize)
                       .Take(PageSize);

            var model = new ProductsModel
            {
                Products   = data,
                Pagination = new PaginationModel
                {
                    CurrentPage  = page,
                    ItemsPerPage = PageSize,
                    TotalItems   = categoryId == 0 ?
                                   _context.Products.Count() :
                                   _context.Products
                                   .Select(p => p)
                                   .Where(p => p.CategoryId == categoryId)
                                   .Count(p => p.Description.Contains(searchString))
                },
                CategoryId = categoryId
            };

            return(model);
        }
Exemplo n.º 28
0
        private async void Button_Clicked(object sender, EventArgs e)
        {
            try
            {
                var app = new Android.App.Application();
                MobileBarcodeScanner.Initialize(app);

                var scanner = new MobileBarcodeScanner();
                scanner.TopText    = "Hold the camera up to the QR code\nAbout 6 inches away";
                scanner.BottomText = "Wait for the QR code to automatically scan!";

                //This will start scanning
                ZXing.Result result = await scanner.Scan();

                string[] lines = result.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

                ProductsModel productsModel = new ProductsModel()
                {
                    ProductId          = lines[0].Substring(lines[0].IndexOf('-') + 1),
                    SerialNo           = "1",
                    ProductDescription = lines[1].Substring(lines[1].IndexOf('-') + 1),
                    UnitPrice          = lines[2].Substring(lines[2].IndexOf('-') + 1),
                    SellPrice          = lines[3].Substring(lines[3].IndexOf('-') + 1),
                    Quantity           = lines[4].Substring(lines[4].IndexOf('-') + 1)
                };
                await Navigation.PushAsync(new ProductListPage(productsModel, UserId));
            }
            catch (Exception ex)
            {
                //await DisplayAlert("Error", ex.Message, "Ok");
            }
        }
Exemplo n.º 29
0
        public static ProductsModel GetAllProductbyID(int prodid)
        {
            try
            {
                ApplicationDbContext context = new ApplicationDbContext();
                var productlist = context.products.Where(ps => ps.ID == prodid).FirstOrDefault();

                ProductsModel pm = new ProductsModel
                {
                    ID            = productlist.ID,
                    Name          = productlist.Name,
                    Image         = productlist.Image,
                    Price         = productlist.Price,
                    SubCategoryID = int.Parse(productlist.subCategoryID.ToString()),
                    Quantity      = productlist.Quantity,
                    SupplierID    = productlist.SupplierID,
                    SupplierName  = productlist.Supplier.UserName
                    ,
                    CategoryID = int.Parse(productlist.subCategory.CategoryID.ToString())
                }
                ;


                return(pm);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 30
0
        public async Task <IActionResult> PutProductsModel(int id, ProductsModel ProductsModel)
        {
            ProductsModel.IdProduct = id;

            _context.Entry(ProductsModel).State = EntityState.Modified;

            if (id != ProductsModel.IdProduct)
            {
                return(BadRequest());
            }

            _context.Entry(ProductsModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductsModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 31
0
    public static int Insert(ProductsModel model)
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                Product newItem = new Product();
                newItem.Id = model.ID;
                newItem.Header = model.Header;
                newItem.Descrition = model.Descrition;
                newItem.Name = model.Name;
                newItem.Link_Image = model.Link_Image;
                newItem.Link_Image_Small = model.Link_Image_Small;
                newItem.Price = model.Price;
                newItem.Creater = model.Creater;
                newItem.CreateDate = model.CreateDate;
                newItem.Modifier = model.Modifier;
                newItem.ModifyDate = model.ModifyDate;
                dc.Products.InsertOnSubmit(newItem);
                dc.SubmitChanges();

            }
            return 1;
        }
        catch (Exception)
        {
            return 0;

        }
    }
Exemplo n.º 32
0
        public void get_product_detail_by_id_return_product_detail()
        {
            // Arrange
            int product_id = 2;

            var mockService = new Mock <IProductService>();

            mockService.Setup(
                service => service.getProductDetail(product_id))
            .Returns(
                new ProductsModel {
                id = 2, name = "43 Piece dinner Set", gender = "Female", age = "3_to_5", availability = "InStock", brand = "CoolKidz"
            }
                );

            var controller = new ProductsController(mockService.Object);

            var expected_product = new ProductsModel {
                id = 2, name = "43 Piece dinner Set", gender = "Female", age = "3_to_5", availability = "InStock", brand = "CoolKidz"
            };

            //Act
            var result = controller.Get(product_id);

            // Assert
            var user = Assert.IsType <ProductsModel>(result);

            Assert.Equal("43 Piece dinner Set", user.name);
        }
Exemplo n.º 33
0
 protected void lbtnDelete_Command(object sender, CommandEventArgs e)
 {
     try
     {
         ProductsModel model = new ProductsModel();
         model.ID = e.CommandArgument.ToString();
         ProductsViewModel.Delete(model);
     }
     catch (Exception)
     {
         lblError.Text = "Lỗi hệ thống! Liên hệ nhà quản trị";
     }
 }
Exemplo n.º 34
0
 public void SaveProduct()
 {
     ProductsModel model = new ProductsModel();
     model.ID = txtId.Text;
     model.Name = txtName.Text;
     model.Price = txtPrice.Text;
     model.Type_Product = cmdProType.SelectedValue;
     model.Header = FTBHeader.Text;
     model.Descrition = FTBContents.Text;
     model.Link_Image_Small = UploadImage(imgSmall, "small");
     model.Link_Image = UploadImage(imgBig, "big");
     model.Creater = Session["user"].ToString();
     model.CreateDate = DateTime.Now.ToString("yyyyMMdd");
     ProductsViewModel.Insert(model);
 }
Exemplo n.º 35
0
 public void UpdateProduct()
 {
     ProductsModel model = new ProductsModel();
     model.ID = txtId.Text;
     model.Name = txtName.Text;
     model.Price = txtPrice.Text;
     model.Type_Product = cmdProType.SelectedValue;
     model.Header = FTBHeader.Text;
     model.Descrition = FTBContents.Text;
     model.Link_Image_Small = (imgSmall.FileName != null) ? UploadImage(imgSmall, "small") : showImgSmall.ImageUrl;
     model.Link_Image = (imgBig.FileName != "") ? UploadImage(imgBig, "big") : showImageBig.ImageUrl;
     model.Modifier = Session["user"].ToString();
     model.ModifyDate = DateTime.Now.ToString("yyyyMMdd");
     ProductsViewModel.Update(model);
 }
Exemplo n.º 36
0
    public static int Delete(ProductsModel model)
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                Product delItem = dc.Products.Where(a => a.Id == model.ID).SingleOrDefault();
                dc.Products.DeleteOnSubmit(delItem);
                dc.SubmitChanges();
            }
            return 1;
        }
        catch (Exception)
        {

            return 0;
        }
    }
Exemplo n.º 37
0
    public void getDateEdit()
    {
        ProductsModel model = new ProductsModel();
        model.ID = Request.QueryString["id"];
        if (model.ID != "")
        {
            model = ProductsViewModel.SelectOne(model);
            txtId.Text = model.ID;
            txtName.Text = model.Name;
            txtPrice.Text = model.Price;
            cmdProType.SelectedValue = model.Type_Product;
            showImgSmall.ImageUrl = model.Link_Image_Small;
            showImageBig.ImageUrl = model.Link_Image;
            FTBHeader.Text = model.Header;
            FTBContents.Text = model.Descrition;

        }
    }
Exemplo n.º 38
0
    private void BindData()
    {
        try
        {
            if (Request.QueryString["id"] != null)
            {
                ProductsModel model = new ProductsModel();
                model.ID = Request.QueryString["id"];
                pro = ProductsViewModel.SelectOne(model);
                repList.DataSource = ProductsViewModel.SelectAll();
                repList.DataBind();
            }

        }
        catch (Exception)
        {

            throw;
        }
    }
Exemplo n.º 39
0
    public static ProductsModel SelectOne(ProductsModel model)
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                Product i = dc.Products.Where(a => a.Id == model.ID).SingleOrDefault();
                return new ProductsModel(i.Id, i.Header, i.Name, i.Descrition, i.Price, i.Link_Image_Small, i.Link_Image, i.Creater, i.CreateDate, i.Modifier, i.ModifyDate);
            }
        }
        catch (Exception)
        {

            return new ProductsModel();
        }
    }
Exemplo n.º 40
0
 private void BindRanDomPro()
 {
     pro = ProductsViewModel.GetRandomPro();
 }
Exemplo n.º 41
0
    /// <summary>
    /// Select top product to view in default page.
    /// </summary>
    /// <param name="top"></param>
    /// <returns></returns>
    public static List<ProductsModel> SelectTopProduct(int top)
    {
        List<ProductsModel> lst = new List<ProductsModel>();
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                var items = (from temp in dc.Products
                            select temp).Take(top);
                foreach (var i in items)
                {
                    ProductsModel n = new ProductsModel(i.Id, i.Header, i.Name, i.Descrition, i.Price, i.Link_Image_Small, i.Link_Image, i.Creater, i.CreateDate, i.Modifier, i.ModifyDate);
                    lst.Add(n);
                }
            }
            return lst;
        }
        catch (Exception)
        {
            return lst;

        }
    }
Exemplo n.º 42
0
    public static int Update(ProductsModel model)
    {
        try
        {
            using (DataContentDataContext dc = new DataContentDataContext())
            {
                Product changeItem = dc.Products.Where(a => a.Id == model.ID).SingleOrDefault();
                changeItem.Header = model.Header;
                changeItem.Name = model.Name;
                changeItem.Price = model.Price;
                changeItem.Descrition = model.Descrition;
                changeItem.Link_Image = model.Link_Image;
                changeItem.Link_Image_Small = model.Link_Image_Small;
                changeItem.ModifyDate = model.ModifyDate;
                changeItem.Modifier = model.Modifier;
                dc.SubmitChanges();
            }
            return 1;
        }
        catch (Exception)
        {

            return 0;
        }
    }