public IActionResult RolCreate(TUsRol rols, int usid, string actionType) { ViewData["panel"] = 5; //int chid=chart.RcharCharId; rols.UsRolUsId = usid; rols.UsRolDateEnd = System.DateTime.Now; if (actionType == "Add") { if (ModelState.IsValid) { try{ _dbContext.TUsRols.Add(rols); _dbContext.SaveChanges(); } catch (Exception ex) { string mensaje = ex.Message; return(View("Error")); } } else { CreateViewBags(0, usid); return(View(rols)); } } CreateViewBags(0, usid); return(RedirectToAction("UserEdit", new{ id = usid, panel = 5 })); }
private void manageRolUser(int id, int wrem, string RolCode, int assign = 0) { try{ if (assign == 1) { ViewData["Assign"] = 1; } if (wrem != 0) { var mode = _dbContext.TUsRols .SingleOrDefault(u => u.UsRolId.Equals(wrem)); try{ _dbContext.TUsRols.Remove(mode); _dbContext.SaveChanges(); } catch (Exception ex) { string mensaje = ex.Message; } } if (RolCode != null) { try{ TUsRol author = new TUsRol { UsRolUsId = id, UsRolName = RolCode, UsRolDateEnd = System.DateTime.Now }; _dbContext.TUsRols.Add(author); _dbContext.SaveChanges(); } catch (Exception ex) { string mensaje = ex.Message; } } } catch (Exception ex) { string mensaje = ex.Message; } }