Ejemplo n.º 1
0
 private void Update(User user)
 {
     using (var ctx = new FightFleetDataContext())
     {
         ctx.Users.Attach(user, true);
         ctx.SubmitChanges();
     }
 }
Ejemplo n.º 2
0
 private void Update(User user)
 {
     using (var ctx = new FightFleetDataContext())
     {
         ctx.Users.Attach(user, true);
         ctx.SubmitChanges();
     }
 }
Ejemplo n.º 3
0
        public void Save()
        {
            ValidateToken();
            using (var ctx = new FightFleetDataContext())
            {
                if (this.AuthenticationId == 0)
                    ctx.Authentications.InsertOnSubmit(this);
                else
                    ctx.Authentications.Attach(this, true);

                ctx.SubmitChanges();
            }
        }
Ejemplo n.º 4
0
 public static IEnumerable <MoveModel> GetForGame(int gameId)
 {
     using (FightFleetDataContext ctx = new FightFleetDataContext())
     {
         return(ctx.Moves.Where(c => c.GameId == gameId).ToList().Select(c => new MoveModel
         {
             CreatedDate = c.CreatedDate,
             GameId = gameId,
             MoveId = c.MoveId,
             Position = c.Position,
             UserId = c.UserId
         }));
     }
 }
Ejemplo n.º 5
0
        public static IEnumerable<MoveModel> GetForGame(int gameId)
        {
            using (FightFleetDataContext ctx = new FightFleetDataContext())
            {
                return ctx.Moves.Where(c => c.GameId == gameId).ToList().Select(c => new MoveModel
                    {
                        CreatedDate = c.CreatedDate,
                        GameId = gameId,
                        MoveId = c.MoveId,
                        Position = c.Position,
                        UserId = c.UserId
                    });

            }
        }
Ejemplo n.º 6
0
 private void Create(User user)
 {
     ValidateUser(user);
     using (var ctx = new FightFleetDataContext())
     {
         var existingUserName = ctx.Users.FirstOrDefault(c => c.UserName.ToLower() == user.UserName.ToLower());
         if (existingUserName != null)
             throw new UserNameExistsException("Username Is In Use");
         if (user.CreatedDate == DateTime.MinValue)
             user.CreatedDate = DateTime.Now;
         user.Password = HashPassword(user.Password);
         ctx.Users.InsertOnSubmit(user);
         ctx.SubmitChanges();
     }
 }
Ejemplo n.º 7
0
        public void Save()
        {
            ValidateToken();
            using (var ctx = new FightFleetDataContext())
            {
                if (this.AuthenticationId == 0)
                {
                    ctx.Authentications.InsertOnSubmit(this);
                }
                else
                {
                    ctx.Authentications.Attach(this, true);
                }

                ctx.SubmitChanges();
            }
        }
Ejemplo n.º 8
0
 private void Create(User user)
 {
     ValidateUser(user);
     using (var ctx = new FightFleetDataContext())
     {
         var existingUserName = ctx.Users.FirstOrDefault(c => c.UserName.ToLower() == user.UserName.ToLower());
         if (existingUserName != null)
         {
             throw new UserNameExistsException("Username Is In Use");
         }
         if (user.CreatedDate == DateTime.MinValue)
         {
             user.CreatedDate = DateTime.Now;
         }
         user.Password = HashPassword(user.Password);
         ctx.Users.InsertOnSubmit(user);
         ctx.SubmitChanges();
     }
 }
Ejemplo n.º 9
0
        public UserAuthenticationModel Authenticate(string userName, string passWord)
        {
            var model             = new UserAuthenticationModel();
            var encryptedPassword = HashPassword(passWord);

            using (var ctx = new FightFleetDataContext())
            {
                var user = ctx.Users.FirstOrDefault(c => c.UserName.ToLower() == userName.ToLower() &&
                                                    c.Password == encryptedPassword);
                if (user == null)
                {
                    return(model);
                }

                model.UserName = user.UserName;
                model.UserId   = user.UserId;
                var authentication = user.Authentications.FirstOrDefault(c => c.ExpiresOn >= DateTime.Now);
                if (authentication == null)
                {
                    authentication = new Authentication
                    {
                        ExpiresOn   = DateTime.Now.AddDays(7),
                        AccessToken = Guid.NewGuid(),
                        CreatedOn   = DateTime.Now,
                    };
                    user.Authentications.Add(authentication);
                    ctx.SubmitChanges();
                }
                else if ((DateTime.Now - authentication.ExpiresOn).TotalDays <= 1)
                {
                    authentication.ExpiresOn = DateTime.Now.AddDays(7);
                    ctx.SubmitChanges();
                }
                model.AccessToken = authentication.AccessToken;
            }

            return(model);
        }
Ejemplo n.º 10
0
        public UserAuthenticationModel Authenticate(string userName, string passWord)
        {
            var model = new UserAuthenticationModel();
            var encryptedPassword = HashPassword(passWord);
            using (var ctx = new FightFleetDataContext())
            {
                var user = ctx.Users.FirstOrDefault(c => c.UserName.ToLower() == userName.ToLower()
                    && c.Password == encryptedPassword);
                if (user == null)
                    return model;

                model.UserName = user.UserName;
                model.UserId = user.UserId;
                var authentication = user.Authentications.FirstOrDefault(c => c.ExpiresOn >= DateTime.Now);
                if (authentication == null )
                {
                    authentication = new Authentication
                    {
                        ExpiresOn = DateTime.Now.AddDays(7),
                        AccessToken = Guid.NewGuid(),
                        CreatedOn = DateTime.Now,

                    };
                    user.Authentications.Add(authentication);
                    ctx.SubmitChanges();
                }
                else if ((DateTime.Now - authentication.ExpiresOn).TotalDays <= 1)
                {
                    authentication.ExpiresOn = DateTime.Now.AddDays(7);
                    ctx.SubmitChanges();
                }
                model.AccessToken = authentication.AccessToken;
            }

            return model;
        }