public async Task <IActionResult> Create([Bind("Id,ItemName,Remark")] TaxItemSetting taxItemSetting) { bool IsTaxItemSettingExist = _context.TaxItemSetting.Any (x => x.ItemName == taxItemSetting.ItemName && x.Id != taxItemSetting.Id); if (IsTaxItemSettingExist == true) { ModelState.AddModelError("ItemName", "Name Already exit"); } if (ModelState.IsValid) { taxItemSetting.InsertDate = DateTime.Now; //taxItemSetting.InsertBy= _context.Add(taxItemSetting); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(taxItemSetting)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,ItemName,Remark")] TaxItemSetting taxItemSetting) { if (id != taxItemSetting.Id) { return(NotFound()); } bool IsTaxItemSettingExist = _context.TaxItemSetting.Any (x => x.ItemName == taxItemSetting.ItemName && x.Id != taxItemSetting.Id); if (IsTaxItemSettingExist == true) { ModelState.AddModelError("ItemName", "Name Already exit"); } if (ModelState.IsValid) { try { taxItemSetting.UpdateDate = DateTime.Now; //taxItemSetting.UpdatedBy= _context.Update(taxItemSetting); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TaxItemSettingExists(taxItemSetting.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(taxItemSetting)); }