public IActionResult AddProduct() { var model = new UIProductSupCategory(); var c = new SubCategoryRepository().GetAll("Id", "Name"); if (c.Count > 0) { foreach (var item in c) { model.Subcategores.Add(new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem(item.Name, item.Id.ToString())); } } return(View(model)); }
public IActionResult UpdateProduct(int id) { var pr = repository.GetByColumName("Id", id); var model = new UIProductSupCategory(); model.Product = pr.FirstOrDefault(); var c = new SubCategoryRepository().GetAll("Id", "Name"); if (c.Count > 0) { foreach (var item in c) { model.Subcategores.Add(new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem(item.Name, item.Id.ToString())); } } return(View(model)); }
public IActionResult AddProduct(UIProductSupCategory model) { string filename = null; if (model.Img != null) { filename = Guid.NewGuid().ToString() + "_" + model.Img.FileName.Split("\\").LastOrDefault(); string fn = Path.Combine(Environment.WebRootPath, "userimg", filename); using (FileStream fs = new FileStream(fn, FileMode.Create)) { model.Img.CopyTo(fs); } } repository.Insert(model.Product); return(RedirectToAction("AllProduct")); }