public async Task <IActionResult> Delete(int?id) { if (id == null) { return(NotFound()); } Special_Tags st = null; if (orm == 1) { st = db.retSpecialTag((int)id); } else { st = await _db.SpecialTags.FindAsync(id); } if (st == null) { return(NotFound()); } return(View(st)); }
public async Task <IActionResult> Index() { if (Convert.ToInt32(TempData["edit"]) == 1) { ViewBag.edit = true; } else if (Convert.ToInt32(TempData["delete"]) == 1) { ViewBag.delete = true; } else if (Convert.ToInt32(TempData["create"]) == 1) { ViewBag.create = true; } if (orm == 1) { db = new Qdatabase(); SpecialTags = db.retSpecialTag(); } else { SpecialTags = await _db.SpecialTags.ToListAsync(); } return(View(SpecialTags)); }
public async Task <IActionResult> CreatePost() { if (!ModelState.IsValid) { List <Special_Tags> specialtags = null; List <ProductTypes> producttypes = null; if (orm == 1) { specialtags = qdb.retSpecialTag(); producttypes = qdb.retProductType(); } else { specialtags = _db.SpecialTags.ToList(); producttypes = _db.ProductTypes.ToList(); } ProductsVm.SpecialTags = specialtags; ProductsVm.ProductTypes = producttypes; return(View("Create", ProductsVm)); } Products obj = null; if (orm == 1) { obj = ProductsVm.Products; obj.Id = qdb.inProduct(ProductsVm.Products); //obj = qdb.retProduct(ProductsVm.Products); } else { _db.Products.Add(ProductsVm.Products); await _db.SaveChangesAsync(); obj = await _db.Products.FindAsync(ProductsVm.Products.Id); } string path = _hostingEnvironment.WebRootPath; var files = HttpContext.Request.Form.Files; //if the user uploads image : if (files.Count != 0) { string extension = Path.GetExtension(files[0].FileName); string newName = path + @"\" + SD.ImageFolder + @"\" + ProductsVm.Products.Id + extension; using (FileStream fs = new FileStream(newName, FileMode.Create)) { files[0].CopyTo(fs); } obj.Image = @"\" + SD.ImageFolder + @"\" + ProductsVm.Products.Id + extension; } //if user doesn't upload any image : else { string newName = path + @"\" + SD.ImageFolder + @"\" + SD.DefaultProductImage; System.IO.File.Copy(newName, path + @"\" + SD.ImageFolder + @"\" + ProductsVm.Products.Id + ".jpg"); obj.Image = @"\" + SD.ImageFolder + @"\" + ProductsVm.Products.Id + ".jpg"; } if (orm == 1) { qdb.upProduct(obj); } else { await _db.SaveChangesAsync(); } TempData["create"] = 1; return(RedirectToAction(nameof(Index))); }