private void Update(User user) { using (var ctx = new FightFleetDataContext()) { ctx.Users.Attach(user, true); ctx.SubmitChanges(); } }
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(); } }
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); }
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(); } }
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; }
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(); } }
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(); } }
private void Update(User user) { using (var ctx = new FightFleetDataContext()) { ctx.Users.Attach(user, true); ctx.SubmitChanges(); } }