Beispiel #1
0
        public void Create(Marker marker)
        {
            using (var db = new Pb.Dal.EfEntities())
            {
                db.Markers.Add(new Pb.Dal.Marker()
                {
                    Created = DateTime.Now,
                    Id = marker.Id,
                    ImageUrl = marker.ImageUrl,
                    Deleted = false,
                    Manufacturer = marker.Manufacturer,
                    Name = marker.Name,
                    PlayerId = marker.PlayerId
                });

                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    Console.WriteLine(e);
                }
            }
        }
Beispiel #2
0
        public void Create(UserTeam userTeam)
        {
            userTeam.Created = DateTime.Now;
            userTeam.Modified = DateTime.Now;

            //using (var db = new DocumentStore() { Url = ConfigurationManager.AppSettings["dbUrl"], DefaultDatabase = ConfigurationManager.AppSettings["defaultDb"] })
            //{
            //    db.Initialize();
            //    using (var session = db.OpenSession())
            //    {
            //        session.Store(userTeam);
            //        session.SaveChanges();
            //    }
            //}

            using (var db = new Pb.Dal.EfEntities())
            {
                var insertme = new Pb.Dal.UserTeam()
                {
                    Id = userTeam.Id == Guid.Empty ? Guid.NewGuid() : userTeam.Id,
                    UserId = userTeam.UserId,
                    TeamId = userTeam.TeamId,
                    Created = userTeam.Created,
                    Modified = userTeam.Modified,
                    Deleted = userTeam.Deleted,
                    Default = userTeam.Default
                };

                db.UserTeams.Add(insertme);
                db.SaveChanges();

            }
        }
Beispiel #3
0
 public void DeleteAll()
 {
     using (var db = new Pb.Dal.EfEntities())
     {
         db.UserTeams.Where(x => x.Deleted == false).Update(y => new Pb.Dal.UserTeam() {Deleted = true,Modified = DateTime.Now});
         db.SaveChanges();
     }
 }
Beispiel #4
0
 public void Delete(Guid id)
 {
     using (var db = new Pb.Dal.EfEntities())
     {
         db.Gears.Where(x => x.Id == id).Update(y => new Pb.Dal.Gear() {Deleted = true, Modified = DateTime.Now});
         db.SaveChanges();
     }
 }
Beispiel #5
0
 public void DeleteByUserId(Guid userId)
 {
     using (var db = new Pb.Dal.EfEntities())
     {
         db.UserRanks.Where(x => x.UserId == userId && x.Deleted == false).Update(y => new Pb.Dal.UserRank() { Deleted = true, Modified = DateTime.Now});
         db.SaveChanges();
     }
 }
 public void DeleteAll()
 {
     using (var db = new Pb.Dal.EfEntities())
     {
         db.Notifications.Where(x => x.Deleted == false).Update(y => new Pb.Dal.Notification() {Deleted = true});
         db.SaveChanges();
     }
 }
Beispiel #7
0
        public void UpdateName(Guid id, string name)
        {
            using (var db = new Pb.Dal.EfEntities())
            {
                db.Loadouts.Where(x => x.Id == id).Update(y => new Pb.Dal.Loadout() {Name = name, Modified = DateTime.Now});

                db.SaveChanges();
            }
        }
Beispiel #8
0
        public void UpdateImageUrl(Guid id, string url)
        {
            using (var db = new Pb.Dal.EfEntities())
            {
                db.Loadouts.Where(x => x.Id == id).Update(y => new Pb.Dal.Loadout() {ImageUrl = url, Modified = DateTime.Now});

                db.SaveChanges();
            }
        }
Beispiel #9
0
        public void Delete(Guid id)
        {
            using (var db = new Pb.Dal.EfEntities())
            {
                db.Markers.Where(x => x.Id == id).Update(y => new Pb.Dal.Marker()
                {
                    Deleted = true
                });

                db.SaveChanges();
            }
        }
Beispiel #10
0
        public void Delete(Guid userId, Guid teamId)
        {
            var id = IdByUserAndTeam(userId, teamId);

            var efUserTeam = new Pb.Dal.UserTeam()
                                 {
                                     Id = id,
                                     Deleted = true
                                 };

            using (var db = new Pb.Dal.EfEntities())
            {
                db.UserTeams.Attach(efUserTeam);
                db.Entry(efUserTeam).Property(x => x.Deleted).IsModified = true;

                db.SaveChanges();
            }
        }
Beispiel #11
0
        public void Create(Loadout loadout)
        {
            using (var db = new Pb.Dal.EfEntities())
            {
                db.Loadouts.Add(new Pb.Dal.Loadout()
                {
                    Created = DateTime.Now,
                    Deleted = false,
                    Id = loadout.Id,
                    ImageUrl = loadout.ImageUrl,
                    Modified = DateTime.Now,
                    Name = loadout.Name,
                    PlayerId = loadout.PlayerId
                });

                db.SaveChanges();
            }
        }
        public void Create(Notification notification)
        {
            var efNotification = new Pb.Dal.Notification()
            {
                Created = DateTime.Now,
                Deleted = false,
                Description = notification.Description,
                Id = notification.Id,
                Modified = DateTime.Now,
                Scope = notification.Scope.GetHashCode(),
                Title = notification.Title,
                Type = notification.Type.GetHashCode()
            };

            using (var db = new Pb.Dal.EfEntities())
            {
                db.Notifications.Add(efNotification);
                db.SaveChanges();
            }
        }
Beispiel #13
0
        public void Update(Domain.Gear gear)
        {
            using (var db = new Pb.Dal.EfEntities())
            {
                db.Gears.Where(x => x.Id == gear.Id).Update(y => new Pb.Dal.Gear()
                {
                    //Created = gear.Created,
                    Deleted = gear.Deleted,
                    LoadoutId = gear.LoadoutId,
                    Manufacturer = gear.Manufacturer,
                    Modified = DateTime.Now,
                    Name = gear.Name,
                    Section = gear.Section.GetHashCode(),
                    Quantity = gear.Quantity,
                    ImageUrl = gear.ImageUrl
                });

                db.SaveChanges();
            }
        }
Beispiel #14
0
        public void Create(Domain.Gear gear)
        {
            using (var db = new Pb.Dal.EfEntities())
            {
                db.Gears.Add(new Pb.Dal.Gear()
                {
                    Id = gear.Id == Guid.Empty ? Guid.NewGuid() : gear.Id,
                    Created = DateTime.Now,
                    Deleted = gear.Deleted,
                    LoadoutId = gear.LoadoutId,
                    Manufacturer = gear.Manufacturer,
                    Modified = DateTime.Now,
                    Name = gear.Name,
                    Section = gear.Section.GetHashCode(),
                    Quantity = gear.Quantity,
                    ImageUrl = gear.ImageUrl
                });

                db.SaveChanges();
            }
        }
Beispiel #15
0
        public Guid UpsertFromExternal(string id, string email, string username)
        {
            using (var db = new Pb.Dal.EfEntities())
            {
                var exists = db.Users.Any(u => u.Deleted == false && u.ExternalId == id);

                if (!exists)
                {
                    var newId = Guid.NewGuid();
                    db.Users.Add(new Pb.Dal.User()
                    {
                        Id = newId,
                        ExternalId = id,
                        Email = email,
                        Password = "",
                        FirstName = username,
                        Created = DateTime.Now,
                        Modified = DateTime.Now
                    });

                    try
                    {
                        db.SaveChanges();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        throw;
                    }

                    _logger.Information("User created, id: {id}, email: {email}", newId, email);

                    return newId;
                }

                return db.Users.Where(u => u.Deleted == false && u.ExternalId == id).Select(x => x.Id).First();
            }
        }
Beispiel #16
0
        public void SetDefault(Guid userId, Guid teamId)
        {
            var id = IdByUserAndTeam(userId, teamId);

            var efUserTeam = new Pb.Dal.UserTeam()
                                     {
                                         Id = id,
                                         Default = true
                                     };

            using (var db = new Pb.Dal.EfEntities())
            {
                // Set all of our current relationsips to false if they are true
                db.UserTeams.Where(x => x.UserId == userId && x.Deleted == false && x.Default == true).Update(y=> new Pb.Dal.UserTeam() {Default = false});

                db.UserTeams.Attach(efUserTeam);
                db.Entry(efUserTeam).Property(x => x.Default).IsModified = true;

                db.SaveChanges();
            }
        }
Beispiel #17
0
        public void Update(Marker marker)
        {
            using (var db = new Pb.Dal.EfEntities())
            {
                bool sameVersion = db.Markers.AsNoTracking().Any(x => x.Id == marker.Id && x.Version == marker.Version);

                if (!sameVersion)
                    throw new StaleDataException();

                db.Markers.Where(y => y.Id == marker.Id).Update(x => new Pb.Dal.Marker()
                {
                    Deleted = marker.Deleted,
                    ImageUrl = marker.ImageUrl,
                    Manufacturer = marker.Manufacturer,
                    Name = marker.Name
                });

                db.SaveChanges();
            }
        }
Beispiel #18
0
        public void DeleteByUserTeamId(Guid userTeamId)
        {
            using (var db = new Pb.Dal.EfEntities())
            {
                var efUserTeam = new Pb.Dal.UserTeam()
                                     {
                                         Id = userTeamId,
                                         Deleted = true,
                                         Modified = DateTime.Now
                                     };

                db.UserTeams.Attach(efUserTeam);
                db.Entry(efUserTeam).Property(x => x.Deleted).IsModified = true;
                db.Entry(efUserTeam).Property(x => x.Modified).IsModified = true;

                db.SaveChanges();

            }
        }