public async Task <IActionResult> Edit(int id, [Bind("ID,Category_title")] Item_category item_category)
        {
            if (id != item_category.IDT)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(item_category);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Item_categoryExists(item_category.IDT))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(item_category));
        }
        public async Task <IActionResult> Create(Item_category model)
        {
            string fileName = System.IO.Path.GetFileName(model.Category_image.FileName);
            string filePath = "/Images/" + fileName;

            if (ModelState.IsValid)
            {
                if (model.Category_image != null)
                {
                    string folder = "images/" + Guid.NewGuid().ToString() + model.Category_image.FileName;
                    folder += Guid.NewGuid().ToString() + model.Category_image.FileName;
                    string serverFolder = Path.Combine(_webHostEnvironment.WebRootPath, folder);
                    await model.Category_image.CopyToAsync(new FileStream(serverFolder, FileMode.Create));

                    //model.SaveAs(Server.MapPath(filePath));

                    //var filename = Path.GetFileName(file.FileName);
                    //var path = Path.Combine(Server.MapPath("~/Uploads/Photo/"), filename);
                    //file.SaveAs(path);
                    //tyre.Url = filename;


                    Item_category itemC = new Item_category
                    {
                        Category_name = model.Category_name,
                        ImageURL      = folder,
                    };
                    _context.Add(itemC);
                    await _context.SaveChangesAsync();
                }
            }

            List <Item_category> itemlist = _context.Items_category.ToList();

            ViewBag.itemlist = itemlist;
            return(RedirectToAction(nameof(Create)));

            //return View(await _context.Items_category.ToListAsync());
        }
Beispiel #3
0
        public IActionResult Create(Item_category cateGory, [Optional] string Value)
        {
            var combineList = _context.Add_item.ToList();

            ViewBag.itemlist = combineList;
            List <Add_item>            ListOfItems = _context.Add_item.ToList();
            List <Item_category>       categorys   = _context.Items_category.ToList();
            List <JoinCategoryAndItem> joinList    = new List <JoinCategoryAndItem>();

            var results = (from pd in categorys
                           join od in ListOfItems on pd.IDT equals od.Category_id
                           select new
            {
                pd.Category_name,
                od.Item_price,
                pd.ImageURL,
                od.Item_name,
                od.Quantity,
                od.id,
            }).ToList();

            foreach (var item in results)
            {
                JoinCategoryAndItem JoinObject = new JoinCategoryAndItem();
                JoinObject.Category_name = item.Category_name;
                JoinObject.Item_price    = item.Item_price;
                JoinObject.ImageURL      = item.ImageURL;
                JoinObject.Quantity      = item.Quantity;
                JoinObject.Item_name     = item.Item_name;
                JoinObject.id            = item.id;
                joinList.Add(JoinObject);


                var JoinListToViewbag = joinList.ToList();
                ViewData["SearchStatus"] = search;
                if (Value == null)
                {
                    ViewBag.JoinList = JoinListToViewbag;
                }

                else
                {
                    //LETS COUNT THE RESULTS
                    int counts = joinLists(Value).Count();
                    if (counts > 0)
                    {
                        ViewBag.JoinList    = joinLists(Value);
                        ViewBag.ItemsCount  = counts;
                        ViewBag.SearchValue = Value;
                    }
                    else
                    {
                        ViewBag.JoinList    = null;
                        ViewBag.ItemsCount  = 0;
                        ViewBag.SearchValue = Value;
                    }
                }
            }



            BindCategoryName();

            return(View());
        }