public bool UpdateRole(RoleClass role) { try { LCDBEntities model = new LCDBEntities(); if (!model.Roles.Any(i => i.Name.Equals(role.Name))) { throw new Exception("This role not found..."); } Role r = model.Roles.Where(i => i.Name.Equals(role.Name)).First(); r.Name = role.Name; r.Description = role.Description; model.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public bool AddRole(RoleClass role) { try { LCDBEntities model = new LCDBEntities(); if (model.Roles.Any(i => i.Name.Equals(role.Name))) { throw new Exception("This Role already exists..."); } Role r = new Role(); r.Name = role.Name; r.Description = role.Description; model.Roles.Add(r); model.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }