public List<RankModel> ByTeamId(Guid teamId, string externalId) { using (var db = new EfEntities()) { Guid userId = _userRepository.IdByExternalId(externalId); var query = from x in db.Ranks join ur in db.UserRanks on x.Id equals ur.RankId into urs from sub in urs.Where(f => f.Deleted == false && f.UserId == userId).DefaultIfEmpty() where x.Deleted == false && x.TeamId == teamId select new RankModel() { Id = x.Id, TeamId = x.TeamId, Name = x.Name, Sequence = x.Sequence, ImageUrl = x.ImageUrl, Created = x.Created, Modified = x.Modified, Deleted = x.Deleted, IsUserInRank = (userId == sub.UserId) }; var efRanks = query.AsNoTracking().ToList(); //return Mapper.Map<List<RankModel>>(efRanks); return efRanks; } }
public void DeleteAll() { using (var db = new EfEntities()) { db.Teams.Where(x => x.Deleted == false).Update(y => new Pb.Dal.Team() {Deleted = true, Modified = DateTime.Now}); db.SaveChanges(); } }
public List<UserModel> All() { using (var db = new EfEntities()) { var query = from x in db.Users where x.Deleted == false orderby x.LastName select x; var efUsers = query.AsNoTracking().ToList(); return AutoMapper.Mapper.Map<List<UserModel>>(efUsers); } }
public Domain.Rank ById(Guid id) { using (var db = new Pb.Dal.EfEntities()) { var query = from x in db.Ranks where x.Deleted == false && x.Id == id select x; var efRank = query.AsNoTracking().FirstOrDefault(); return AutoMapper.Mapper.Map<Domain.Rank>(efRank); } }
public void Update(TeamModel team) { using (var db = new EfEntities()) { db.Teams.Where(x => x.Deleted == false && x.Id == team.Id).Update(y => new Pb.Dal.Team() { Modified = DateTime.Now, Description = team.Description, ImageUrl = team.ImageUrl, Name = team.Name }); db.SaveChanges(); } }
public void Create(Guid notificationId, string externalId) { using (var db = new Pb.Dal.EfEntities()) { Guid userId = db.Users.First(x => x.ExternalId == externalId).Id; db.NotificationPlayers.Add(new NotificationPlayer() { Id = Guid.NewGuid(), Created = DateTime.Now, NotificationId = notificationId, PlayerId = userId }); db.SaveChanges(); } }
public void Create(Team team) { team.Created = DateTime.Now; team.Modified = DateTime.Now; using (var db = new Pb.Dal.EfEntities()) { db.Teams.Add(new Pb.Dal.Team() { Id = team.Id == Guid.Empty ? Guid.NewGuid() : team.Id, Name = team.Name, Description = team.Description, Created = team.Created, Modified = team.Modified, Deleted = team.Deleted }); db.SaveChanges(); } }
public User ById(Guid id) { using (var db = new Pb.Dal.EfEntities()) { var query = from u in db.Users join ut in db.UserTeams on u.Id equals ut.UserId into userTeams from subUserTeams in userTeams.DefaultIfEmpty() join t in db.Teams on subUserTeams.TeamId equals t.Id into teams from subTeams in teams.DefaultIfEmpty() where u.Id == id && u.Deleted == false select new { u,subUserTeams, subTeams }; var rawResult = query.AsNoTracking().ToList(); if (!rawResult.Any()) return null; var rawUser = rawResult.First(); var user = new PB.Domain.User() { Id = rawUser.u.Id, Email = rawUser.u.Email, //Password = rawUser.u.Password, FirstName = rawUser.u.FirstName, LastName = rawUser.u.LastName, Created = rawUser.u.Created, Modified = rawUser.u.Modified, Deleted = rawUser.u.Deleted, Teams = new List<Team>(), DefaultTeam = null, Callsign = rawUser.u.Callsign }; return user; } }
public User ByEmailAndPassword(string email, string password) { email = email.Trim(); var hashedPassword = _encryptor.Encrypt(password); using (var db = new Pb.Dal.EfEntities()) { var query = from u in db.Users where u.Deleted == false && u.Email == email && u.Password == hashedPassword select u; var efUser = query.FirstOrDefault(); if (efUser == null) return null; return ConvertUser(efUser); } }
public void Create(List<Team> teams) { teams.ForEach(x => { x.Created = DateTime.Now; x.Modified = DateTime.Now; }); using (var db = new Pb.Dal.EfEntities()) { foreach (var team in teams) { db.Teams.Add(new Pb.Dal.Team() { Id = team.Id == Guid.Empty ? Guid.NewGuid() : team.Id, Name = team.Name, Description = team.Description, Created = team.Created, Modified = team.Modified, Deleted = team.Deleted }); } db.SaveChanges(); } }
public List<UserModel> ByTeamId(Guid id) { using (var db = new EfEntities()) { var query = from x in db.Users join ut in db.UserTeams on x.Id equals ut.UserId where x.Deleted == false && ut.Deleted == false && ut.TeamId == id select x; var efUsers = query.AsNoTracking().ToList(); return AutoMapper.Mapper.Map<List<UserModel>>(efUsers); } }
public void DeleteByTeamId(Guid teamId) { using (var db = new EfEntities()) { db.Ranks.Where(x => x.TeamId == teamId && x.Deleted == false).Update(y=> new Pb.Dal.Rank() {Deleted = true, Modified = DateTime.Now }); db.SaveChanges(); } }
public void Update(User user) { using (var db = new Pb.Dal.EfEntities()) { db.Users.Where(x => x.Id == user.Id).Update(y => new Pb.Dal.User() {FirstName = user.FirstName, LastName = user.LastName, Callsign = user.Callsign, Modified = DateTime.Now}); db.SaveChanges(); } }
public void SetPassword(Guid userId, string password) { using (var db = new Pb.Dal.EfEntities()) { db.Users.Where(x => x.Id == userId).Update(y => new Pb.Dal.User() {Password = _encryptor.Encrypt(password), Modified = DateTime.Now}); db.SaveChanges(); } }
public Guid IdByExternalId(string externalId) { using (var db = new EfEntities()) { var query = from x in db.Users where x.Deleted == false && x.ExternalId == externalId select x.Id; return query.FirstOrDefault(); } }
public bool EmailExists(string email) { using (var db = new Pb.Dal.EfEntities()) { return db.Users.AsNoTracking().Any(x => x.Deleted == false && x.Email == email); } }
public void Delete(Guid id) { using (var db = new Pb.Dal.EfEntities()) { db.Users.Where(x => x.Id == id).Update(y => new Pb.Dal.User() {Deleted = true, Modified = DateTime.Now}); db.SaveChanges(); } }
public void Create(User user) { user.Created = DateTime.Now; user.Modified = DateTime.Now; //user.Password = _encryptor.Encrypt(user.Password); var efUser = ConvertUser(user); efUser.Password = ""; using (var db = new Pb.Dal.EfEntities()) { db.Users.Add(efUser); db.SaveChanges(); } }
public void Create(Domain.Rank rank) { var efRank = Mapper.Map<Pb.Dal.Rank>(rank); efRank.Id = efRank.Id == Guid.Empty ? Guid.NewGuid() : efRank.Id; efRank.Created = DateTime.Now; efRank.Modified = DateTime.Now; efRank.Deleted = false; using (var db = new Pb.Dal.EfEntities()) { db.Ranks.Add(efRank); db.SaveChanges(); } }
private void ExecuteDb(Action<Pb.Dal.EfEntities> action) { using (var db = new Pb.Dal.EfEntities()) { action(db); } }