public IActionResult ManageUnit(US_UNIT _obj) { if (ModelState.IsValid) { if (_obj.ID == 0) { try { _obj.ID = _unitOfWork.US_UNIT.GetAll().Max(x => x.ID) + 1; } catch { _obj.ID = 1; } _obj.IS_ACTIVE = true; _unitOfWork.US_UNIT.Add(_obj); } else { _unitOfWork.US_UNIT.Update(_obj); } _unitOfWork.Save(); TempData["msg"] = SweetMsg.SaveSuccess(); return(RedirectToAction(nameof(ManageUnit))); } TempData["msg"] = SweetMsg.SaveErrorOK(); return(View(_obj)); }
public IActionResult ManageUnit(int?id) { US_UNIT _obj = new US_UNIT(); if (id != null) { _obj = _unitOfWork.US_UNIT.Get(id.Value); if (_obj == null) { TempData["msg"] = SweetMsg.SaveWarningOK(); } } return(View(_obj)); }