public virtual void UpdateGroup(tbs_Group group) { using (SecurityEntities sc = new SecurityEntities()) using (TransactionScope ts = new TransactionScope()) { var mapper = ServiceContainer.GetService <IMapper>(); tbs_Group edited = mapper.Map <tbs_Group>(group); sc.tbs_Group.Attach(edited); sc.Entry(edited).State = System.Data.Entity.EntityState.Modified; sc.SaveChanges(); ts.Complete(); } }
public virtual void UpdateUser(tbs_User user) { using (SecurityEntities sc = new SecurityEntities()) using (TransactionScope ts = new TransactionScope()) { var mapper = ServiceContainer.GetService <IMapper>(); var passList = sc.tbs_User.Where(u => u.UserCode == user.UserCode).Select(u => u.Password).ToList(); string pass = passList.Count > 0 ? passList[0] : string.Empty; tbs_User edited = mapper.Map <tbs_User>(user); if (false == edited.Password.Equals(pass) || string.IsNullOrEmpty(pass)) { edited.Password = SecurityModelCrypto.HashEncrypt(edited.Password); } sc.tbs_User.Attach(edited); sc.Entry(edited).State = System.Data.Entity.EntityState.Modified; sc.SaveChanges(); ts.Complete(); } }
public virtual bool ChangePassword(string userCode, string oldPassword, string newPassword) { using (SecurityEntities db = new SecurityEntities()) { string encryptedOld = SecurityModelCrypto.HashEncrypt(oldPassword); var users = db.tbs_User .Where(a => (a.UserCode == userCode) && a.Password == encryptedOld) .ToList(); if (users.Count != 1) { return(false); } string encryptedNew = SecurityModelCrypto.HashEncrypt(newPassword); users[0].Password = encryptedNew; db.Entry(users[0]).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(true); } }