Example #1
0
 private int CheckData(Entity.Product product)
 {
     if (product.ProductID == 0)
     {
         return(0);
     }
     else if (product.ProductName.Length == 0)
     {
         return(0);
     }
     else if (product.ProductPrice == 0)
     {
         return(0);
     }
     else if (product.ProductQuantity == 0)
     {
         return(0);
     }
     // else if (product.ProductPicture.Length == 0) return 0;
     else if (product.CategoryID == 0)
     {
         return(0);
     }
     else if (product.SupplerID == 0)
     {
         return(0);
     }
     else
     {
         return(1);
     }
 }
 public ActionResult DeleteConfirmed(int id)
 {
     Entity.Product product = db.Products.Find(id);
     db.Products.Remove(product);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
        public AddTypeVM()
        {
            SelectedProduct = new Entity.Product();
            SelectedProduct.ProductType = new ProductType();

            surrogate = new Surrogate<Entity.Product>(new ProductServiceProxy());
            Products = surrogate.Deserialize(surrogate.GetAll());

            surrogateProductType = new Surrogate<ProductType>(new ProductTypeServiceProxy());
        }
        private void cmbProducts_SelectedIndexChanged(object sender, EventArgs e)
        {
            // get product id of the selected item
            DataRowView item = (DataRowView)cmbProducts.SelectedItem;
            int         selectedProductId = Int32.Parse(item["ID"].ToString());

            // get product and show available qty
            Entity.Product product = ProductController.GetOne(selectedProductId);
            txtAvailableQty.Text = product.qty.ToString();
            txtSalePrice.Text    = product.salePrice.ToString();
        }
 public ActionResult Edit([Bind(Include = "Id,Name,Description,Price,Stock,Image,IsHome,IsApproved,CategoryId")] Entity.Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId);
     return(View(product));
 }
 // GET: Product/Details/5
 public ActionResult Details(int?id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     Entity.Product product = db.Products.Find(id);
     if (product == null)
     {
         return(HttpNotFound());
     }
     return(View(product));
 }
Example #7
0
 public int Add(Entity.Product Product)
 {
     try
     {
         _context.Products.Add(Product);
         _context.SaveChanges();
         return(Product.Id);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 // GET: Product/Edit/5
 public ActionResult Edit(int?id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     Entity.Product product = db.Products.Find(id);
     if (product == null)
     {
         return(HttpNotFound());
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId);
     return(View(product));
 }
        public AddProductParametrVM()
        {
            SelectedProduct = new Entity.Product();
            SelectedProduct.ProductType = new ProductType();
            SelectedProductParameter = new ProductParametr();

            surrogateProduct = new Surrogate<Entity.Product>(new ProductServiceProxy());
            Products = surrogateProduct.Deserialize(surrogateProduct.GetAll());

            surrogateProductParameter = new Surrogate<ProductParametr>(new ProductParameterServiceProxy());
            Products = surrogateProduct.Deserialize(surrogateProductParameter.GetAll());

            ProductParametrs = new ObservableCollection<ProductParametr>(Products.Select(a => a.ProductType).ToList().FirstOrDefault().ProductParametrs.ToList());
        }
Example #10
0
        public void AddProduct(Entity.Product product, int quantity)
        {
            var line = _cardLines.FirstOrDefault(i => i.Product.Id == product.Id);

            if (line == null)
            {
                _cardLines.Add(new CartLine()
                {
                    Product = product, Quantity = quantity
                });
            }
            else
            {
                line.Quantity += quantity;
            }
        }
Example #11
0
		public void initialize()
		{
			try
			{
                if (!System.IO.File.Exists(@fileName))
					System.IO.File.Create(@fileName).Close();
                //this.products.Clear();

				// Create an instance of StreamReader to read from a file. 
				using (StreamReader sr = new StreamReader(@fileName))
				{
					/*
					0.	id
					1.	code
					2.	name
					3.	brand
					4.	price
					5.	vat
					6.	priceVat
					 */
					string line;
					// Read and display lines from the file until the end of the file is reached. 
					while ((line = sr.ReadLine()) != null)
					{
						if (string.IsNullOrWhiteSpace(line))
							continue;
						string[] arr = line.Split(';');
						if (arr.Length < 7)
							continue;
						Interface.IProduct product = new Entity.Product();
						product.id = int.Parse(arr[0]);
						product.code = arr[1];
						product.name = arr[2];
						product.brand = arr[3];
						product.price = decimal.Parse(arr[4]);
						product.vat = decimal.Parse(arr[5]);
						product.priceVat = decimal.Parse(arr[6]);
						this.products.Add(product);
					}
					this.initialized = true;
				}
			}
			catch (Exception e)
			{
				System.Windows.MessageBox.Show("The file could not be read: " + e.Message);
			}
		}
        private Entity.Product GetInputs()
        {
            var product = new Entity.Product();

            // convert input photo to a byte array
            MemoryStream ms = new MemoryStream();

            imgProduct.Image.Save(ms, imgProduct.Image.RawFormat);
            byte[] photo = ms.ToArray();

            product.name        = txtName.Text.Trim();
            product.photo       = photo;
            product.price       = Decimal.Parse(txtPrice.Text.Trim());
            product.salePrice   = Decimal.Parse(txtSalePrice.Text.Trim());
            product.qty         = Int32.Parse(txtQty.Text.Trim());
            product.addedDate   = DateTime.Now.ToString("yyyy-MM-dd");
            product.addedUserId = 6;

            return(product);
        }
        public ActionResult Create(Product product)
        {
            try
            {
                var db = new CRUDExample();
                var model = new Entity.Product();
                if (model != null)
                {
                    model.Name = product.Name;

                    db.Product.Add(model);
                    db.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Example #14
0
 public int Create(ProductView item)
 {
     try
     {
         if (checkNameProduct(item.name_product) == false)
         {
             Entity.Product pro = new Entity.Product()
             {
                 id = item.id, name_product = item.name_product, name_image = item.name_image, id_brand = item.id_brand, id_category = item.id_category, description = item.description, discount = item.discount, price = item.price, created = item.created, status = item.status
             };
             database.Products.Add(pro);
             database.SaveChanges();
             return(1);
         }
         return(0);
     }
     catch (Exception)
     {
         return(0);
     }
 }
Example #15
0
        public ActionResult Create(Product product)
        {
            try
            {
                var db    = new CRUDExample();
                var model = new Entity.Product();
                if (model != null)
                {
                    model.Name = product.Name;

                    db.Product.Add(model);
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        private Entity.Invoice GetInputs()
        {
            Entity.Invoice invoice = new Entity.Invoice();
            invoice.grandTotal    = Decimal.Parse(txtGrandTotal.Text);
            invoice.discountRatio = Int32.Parse(txtDiscountRatio.Text);
            invoice.netTotal      = Decimal.Parse(txtNetTotal.Text);
            invoice.addedDate     = DateTime.Now.ToString("yyyy-MM-dd");
            invoice.addedUserId   = 6;
            invoice.products      = new List <Entity.Product>();

            // add products
            foreach (ListViewItem item in listProducts.Items)
            {
                Entity.Product product = new Entity.Product();
                product.id  = Int32.Parse(item.SubItems[0].Text);
                product.qty = Int32.Parse(item.SubItems[3].Text);
                invoice.products.Add(product);
            }

            return(invoice);
        }
Example #17
0
        public int InsertProduct(Product product)
        {
            if (product == null)
            {
                return(0);
            }

            WebApplicationApi.Entity.Product insertP = new Entity.Product()
            {
                ProductCategoryId = product.ProductCategoryId,
                ID     = System.Guid.NewGuid(),
                Name   = product.Name,
                Price  = product.Price,
                Amount = product.Amount
            };

            Entity.ECMallEntities1 entity = new Entity.ECMallEntities1();
            entity.Product.Add(insertP);
            var result = entity.SaveChanges();

            return(result);
        }
		private void submit_Click(object sender, RoutedEventArgs e)
		{
            if ((code.Text == string.Empty) || (name.Text == string.Empty) || (brand.Text == string.Empty)
            || (price.Text == string.Empty) || (vat.Text == string.Empty) || (priceVat.Text == string.Empty))
            {
                System.Windows.MessageBox.Show("Musia byť vyplnené poviné údaje");
                return;
            }
            if ((code.Text.Contains(";")) || (name.Text.Contains(";")) || (brand.Text.Contains(";"))
          || (price.Text.Contains(";")) || (vat.Text.Contains(";")) || (priceVat.Text.Contains(";")))
            {
                System.Windows.MessageBox.Show("Znak ; je vyhradeni, prosím zmente vstup tak aby neobsahoval znak ; ");
                return;
            }
			Entity.Product product = new Entity.Product();
			if (Settings.Config.getProducts().Count > 0)
				product.id = Settings.Config.getProducts().LastOrDefault(x => x.id > 0).id + 1;
			else
				product.id = 1;

			product.code = this.code.Text.ToString();
			product.name = this.name.Text.ToString();
			product.brand = this.brand.Text.ToString();
			product.price = decimal.Parse(this.price.Text.ToString());
			product.vat = decimal.Parse(this.vat.Text.ToString());
			product.priceVat = decimal.Parse(this.priceVat.Text.ToString());
			if (Settings.Config.getProducts().Count(x => x.code == product.code) > 0)
			{
				MessageBox.Show("Produkt s kódom " + product.code + " sa už nachádza v evidencii.");
			}
			else
			{
				Settings.Config.getProducts().Add(product);
				Settings.Config.saveProducts();
				MessageBox.Show("Produkt " + product.code + " - " + product.name + " bol úspešne pridaný.");
				this.code.Text = this.name.Text = this.brand.Text = this.price.Text = this.vat.Text = this.priceVat.Text = string.Empty;
			}
		}
Example #19
0
        public bool Update(Entity.Product Product)
        {
            try
            {
                var prod = _context.Products.FirstOrDefault(x => x.Id == Product.Id);
                if (prod != null)
                {
                    prod.Name          = Product.Name;
                    prod.Description   = Product.Description;
                    prod.Price         = Product.Price;
                    prod.DeliveryPrice = Product.DeliveryPrice;

                    _context.Products.Update(prod);
                    _context.SaveChanges();
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public void OnGet(int id)
 {
     product = _productRepository.GetProduct(id);
 }
Example #21
0
 public bool Update(ProductDto Product)
 {
     Entity.Product product = _mapper.Map <ProductDto, Entity.Product>(Product);
     return(_ProductRepository.Update(product));
 }
Example #22
0
 public int Add(ProductCreateDto newProduct)
 {
     Entity.Product product = _mapper.Map <ProductCreateDto, Entity.Product>(newProduct);
     return(_ProductRepository.Add(product));
 }
Example #23
0
 public void Add(Entity.Product entity)
 {
     _productsList.Add(entity);
 }
Example #24
0
        public BaseResponse UpdateProductInfo(ProductUpdateInfo info)
        {
            var response = new BaseResponse();

            using (var db = DbContext)
            {
                var entityDb = new Entity.Product { Id = info.Id };
                db.Products.Attach(entityDb);

                var changed = false;

                if (changed)
                {
                    response.Success = db.SaveChanges() > 0;
                }
            }

            return response;
        }
Example #25
0
 public void DeleteProduct(Entity.Product product)
 {
     _cardLines.RemoveAll(i => i.Product.Id == product.Id);
 }