public IActionResult Add(DataViewModel.CategoryViewModel categories) { try { if (categories.cat_id > 0) { Category cat = _context.categories.Find(categories.cat_id); cat.category = categories.category; _context.Update(cat); _context.SaveChanges(); return(Json(new { success = true })); } else { Category cat = new Category(); cat.category = categories.category; _context.Add(cat); _context.SaveChanges(); return(Json(new { success = true, cid = cat.cat_id })); } // return Json(new { success = false }); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> Createsupplier(Supplier sup) { if (ModelState.IsValid) { var uploads = Path.Combine(_environment.WebRootPath, "images"); if (sup.file != null && sup.file.Length > 0) { var fileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(sup.file.FileName); using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create)) { await sup.file.CopyToAsync(fileStream); sup.image = fileName; } } _context.Add(sup); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(sup)); }