public UserRoleGetModel Create(UserRolePostModel userRolePostModel) { UserRole toAdd = UserRolePostModel.ToUserRole(userRolePostModel); context.UserRoles.Add(toAdd); context.SaveChanges(); return(UserRoleGetModel.FromUserRole(toAdd)); }
public UserRoleGetModel GetById(int id) { UserRole userRole = context.UserRoles .AsNoTracking() .FirstOrDefault(ur => ur.Id == id); return(UserRoleGetModel.FromUserRole(userRole)); }
public UserRoleGetModel Delete(int id) { var existing = context.UserRoles .FirstOrDefault(ur => ur.Id == id); if (existing == null) { return(null); } context.UserRoles.Remove(existing); context.SaveChanges(); return(UserRoleGetModel.FromUserRole(existing)); }
public UserRoleGetModel Upsert(int id, UserRolePostModel userRolePostModel) { var existing = context.UserRoles.AsNoTracking().FirstOrDefault(urole => urole.Id == id); if (existing == null) { UserRole toAdd = UserRolePostModel.ToUserRole(userRolePostModel); context.UserRoles.Add(toAdd); context.SaveChanges(); return(UserRoleGetModel.FromUserRole(toAdd)); } UserRole Up = UserRolePostModel.ToUserRole(userRolePostModel); Up.Id = id; context.UserRoles.Update(Up); context.SaveChanges(); return(UserRoleGetModel.FromUserRole(Up)); }
public IEnumerable <UserRoleGetModel> GetAll() { return(context.UserRoles.Select(userRol => UserRoleGetModel.FromUserRole(userRol))); }