public RolesAcciones GetRolesAccionesPorId(int IdRol, int IdAccion) { RolesAcciones Lista = new RolesAcciones(); try { using (var db = new DataContext()) { Lista = db.RolesAcciones.Where(x => x.IdRol == IdRol && x.IdAcciones == IdAccion).FirstOrDefault(); } } catch (Exception) { throw; } return(Lista); }
public RespondModel Guardar(RolesAcciones RolesAcciones) { var rm = new RespondModel(); string mensaje = ""; try { using (var db = new DataContext()) { RolesAcciones dato = GetRolesAccionesPorId(RolesAcciones.IdRol, RolesAcciones.IdAcciones); if (dato.IdRol == 0) { db.Entry(RolesAcciones).State = System.Data.Entity.EntityState.Added; mensaje = "Registro agregado exitosamente"; } db.SaveChanges(); rm.SetResponse(true, mensaje); } } catch (DbEntityValidationException ex) { foreach (var eve in ex.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } rm.SetResponse(false, ex.Message); } catch (Exception ex) { rm.SetResponse(false, ex.Message); } return(rm); }
public RespondModel Guardar(RolesAcciones RolesAcciones) { return(RolActManager.Guardar(RolesAcciones)); }