public async Task <IActionResult> Edit(long id, SupplierTbl supplierTbl) { // supplierTbl = _context.SupplierTbl.Find(id); if (ModelState.IsValid) { try { //var edits = _context.SupplierTbl.Where(x => x.SupplierId == id).First(); //supplierTbl. supplierTbl.SupplierId = id; supplierTbl.CreatedAtSupplier = supplierTbl.CreatedAtSupplier; supplierTbl.ModifyAtSupplier = DateTime.Now; // _context.Entry(supplierTbl).State = EntityState.Detached; _context.SupplierTbl.Update(supplierTbl); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SupplierTblExists(supplierTbl.SupplierId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(supplierTbl)); }
public void save(SupplierVM vm) { SupplierTbl entity = new SupplierTbl(); entity.Name = vm.Name; entity.Number = vm.Number; entity.AccountNumber = vm.AccountNumber; entity.BankName = vm.BankName; _MarbalContext.Entry(entity).State = EntityState.Added; _MarbalContext.SaveChanges(); }
public async Task <IActionResult> Create([Bind("SupplierId,SupplierCode,Description,Address,Contact,ProductData,CreatedAtSupplier,ModifyAtSupplier")] SupplierTbl supplierTbl) { if (ModelState.IsValid) { String idrunning = ""; idrunning = generateRunningNumber(idrunning); supplierTbl.SupplierCode = idrunning; supplierTbl.CreatedAtSupplier = DateTime.Now; supplierTbl.ModifyAtSupplier = DateTime.Now; _context.Add(supplierTbl); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(supplierTbl)); }
//========================================================================================================= //GENERATE RUNNING NUMBER private String generateRunningNumber(string id) { SupplierTbl data = _context.SupplierTbl.Where(x => x.SupplierCode == "SP" + DateTime.Now.ToString("yyMM") + "0001").FirstOrDefault(); string tempSubId = ""; int tempId; if (data == null) { id = "SP" + DateTime.Now.ToString("yyMM") + "0001"; } else { var xx = (from a in _context.SupplierTbl where a.SupplierCode.Substring(0, 6) == "SP" + DateTime.Now.ToString("yyMM") select a).Max(a => a.SupplierCode); tempSubId = xx.Substring(6, 4); tempId = Convert.ToInt32(tempSubId); tempId = tempId + 1; if (tempId.ToString().Length == 1) { id = "SP" + DateTime.Now.ToString("yyMM") + "000" + tempId; } else if (tempId.ToString().Length == 2) { id = "SP" + DateTime.Now.ToString("yyMM") + "00" + tempId; } else if (tempId.ToString().Length == 3) { id = "SP" + DateTime.Now.ToString("yyMM") + "0" + tempId; } else if (tempId.ToString().Length == 4) { id = "SP" + DateTime.Now.ToString("yyMM") + tempId; } } return(id); }