Example #1
0
        public async Task <IActionResult> Create([Bind("short_desc,desc,is_in_camp,is_in_stock,quantity,tax_id,mensei_id,id,name,is_active")] Products products, string price, string camp_price, string categories)
        {
            //formdan double gelmesi gereken bilgi bölgesel farklılıklar nedeniyle tamsayı olarak dönüşüyor.
            //Alttaki ekle bu durum düzeltiliyor.
            products.price      = Tools.toDouble(price);
            products.camp_price = Tools.toDouble(camp_price);
            products.is_delete  = false;
            products.c_date     = DateTime.Now;
            products.seo_url    = Tools.toSlug(products.name);
            if (ModelState.IsValid)
            {
                _context.Add(products);

                _context.SaveChanges();
                List <PrelCs> prelc = new List <PrelCs>();
                foreach (var item in categories.Split(","))
                {
                    prelc.Add(new PrelCs()
                    {
                        ProductId  = products.id,
                        CategoryId = Int32.Parse(item)
                    });
                }

                _context.AddRange(prelc);
                _context.SaveChanges();
                FileUploadAndBound(products.id);
            }

            ViewData["mensei_id"]  = new SelectList(_context.Mensei, "id", "name", products.mensei_id);
            ViewData["tax_id"]     = new SelectList(_context.Tax, "id", "name", products.tax_id);
            ViewData["Categories"] = categories;
            return(View(products));
        }