public async Task <IActionResult> AddProductForm([Bind("IdProduct,Name,QuantityInStorage,Price,PriceInPoints")] ProductString product)
        {
            //Debug.WriteLine(product.Price);
            try
            {
                decimal x = Convert.ToDecimal(product.Price);
            }
            catch (Exception)
            {
                return(View(product));
            }
            Product p = new Product()
            {
                IdProduct         = product.IdProduct,
                Name              = product.Name,
                QuantityInStorage = product.QuantityInStorage,
                Price             = Convert.ToDecimal(product.Price),
                PriceInPoints     = product.PriceInPoints
            };

            //product.Price = Convert.ToDecimal(product.Price.ToString().Replace(".", ","));
            if (ModelState.IsValid)
            {
                _context.Add(p);
                await _context.SaveChangesAsync();

                return(RedirectToAction("ViewProductList"));
                //return View(product);
            }
            return(View(product));
        }
Example #2
0
        public JsonResult MixSearch(string ironcontent)
        {
            var productsFilteredList = _applicationDbContext.Products.ToList();
            List <ProductString> productsFilteredListString = new List <ProductString>();
            Product productModelNew             = new Product();
            var     productsFilteredListUpdated = productsFilteredList;
            int     i = 1;

            foreach (var product in productsFilteredList.ToList())
            {
                var productIronContent = product.IronContent;
                var ironContentNew     = Convert.ToInt16(ironcontent) * 2 - productIronContent;
                productModelNew = productsFilteredListUpdated.Where(x => x.IronContent == ironContentNew).FirstOrDefault();
                if (ironContentNew == productIronContent)
                {
                    ProductString productInString = new ProductString();
                    productInString.Id           = i;
                    productInString.ParticleSize = product.ParticleSize.ToString();
                    productInString.IronContent  = product.IronContent.ToString();
                    productInString.Reactivitiy  = product.Reactivitiy.ToString();
                    productInString.Price        = product.Price;
                    productInString.SurfaceArea  = product.SurfaceArea.ToString();
                    productInString.Logevity     = product.Logevity.ToString();
                    productInString.Media        = product.Media;
                    productInString.Location     = product.Location;
                    productsFilteredListString.Add(productInString);
                    i++;
                }
                else
                {
                    if (productModelNew != null)
                    {
                        ProductString productInString = new ProductString();
                        productInString.Id = i;
                        if (product.ParticleSize == productModelNew.ParticleSize)
                        {
                            productInString.ParticleSize = product.ParticleSize.ToString();
                        }
                        else
                        {
                            productInString.ParticleSize = product.ParticleSize + " - " + productModelNew.ParticleSize;
                        }
                        if (product.IronContent == productModelNew.IronContent)
                        {
                            productInString.IronContent = product.IronContent.ToString();
                        }
                        else
                        {
                            productInString.IronContent = product.IronContent + " - " + productModelNew.IronContent;
                        }
                        if (product.Reactivitiy == productModelNew.Reactivitiy)
                        {
                            productInString.Reactivitiy = product.Reactivitiy.ToString();
                        }
                        else
                        {
                            productInString.Reactivitiy = product.Reactivitiy + " - " + productModelNew.Reactivitiy;
                        }
                        productInString.Price = (product.Price + productModelNew.Price) / 2;
                        if (product.SurfaceArea == productModelNew.SurfaceArea)
                        {
                            productInString.SurfaceArea = product.SurfaceArea.ToString();
                        }
                        else
                        {
                            productInString.SurfaceArea = product.SurfaceArea + " - " + productModelNew.SurfaceArea;
                        }
                        if (product.Logevity == productModelNew.Logevity)
                        {
                            productInString.Logevity = product.Logevity.ToString();
                        }
                        else
                        {
                            productInString.Logevity = product.Logevity + " - " + productModelNew.Logevity;
                        }
                        if (product.Media.Equals(productModelNew.Media))
                        {
                            productInString.Media = product.Media;
                        }
                        else
                        {
                            productInString.Media = product.Media + " - " + productModelNew.Media;
                        }
                        if (product.Location.Equals(productModelNew.Location))
                        {
                            productInString.Location = product.Location;
                        }
                        else
                        {
                            productInString.Location = product.Location + " - " + productModelNew.Location;
                        }
                        productsFilteredListUpdated.Remove(product);
                        productsFilteredListUpdated.Remove(productModelNew);
                        productsFilteredListString.Add(productInString);
                        i++;
                    }
                }
            }
            return(Json(productsFilteredListString.OrderBy(o => o.Id)));
        }