public IActionResult ManageUserRole(US_USER_ROLE _obj) { if (ModelState.IsValid) { _obj.IS_ACTIVE = true; _unitOfWork.US_USER_ROLE.Add(_obj); _unitOfWork.Save(); TempData["msg"] = SweetMsg.SaveSuccess(); return(RedirectToAction(nameof(ManageUserRole))); } TempData["msg"] = SweetMsg.SaveErrorOK(); DropDownFor_ManageUserRole(); return(View(_obj)); }
//need to change this method HttpPost public IActionResult UserRoleSetup(string post_data) { try { bool _save = false; var _post_data_vm = JsonConvert.DeserializeObject <List <post_data2_vm> >(post_data); var _obj1 = _unitOfWork.US_USER.GetFirstOrDefult(x => x.LOGIN_ID == _post_data_vm.FirstOrDefault().myuser); foreach (var item in _post_data_vm) { var _obj = _unitOfWork.US_USER_ROLE.GetFirstOrDefult(x => x.ROLE_ID == item.myrole && x.USER_ID == _obj1.ID); if (_obj != null && _obj.IS_ACTIVE != item.mystate) { _obj.IS_ACTIVE = item.mystate; _unitOfWork.US_USER_ROLE.Update(_obj); _save = true; } else if (_obj == null && item.mystate == true) { US_USER_ROLE uS = new US_USER_ROLE(); uS.ROLE_ID = item.myrole; uS.USER_ID = _obj1.ID; _unitOfWork.US_USER_ROLE.Add(uS); _save = true; } else { _save = false; } if (_save) { _unitOfWork.Save(); } } return(Json(new { success = true, messages = SweetMsg._SaveSuccess })); } catch { return(Json(new { success = false, messages = SweetMsg._SaveError })); } }