public void AddUser(UserIdentity us) { var user1 = this.userRepository.GetUser(us.Login); if (user1 == null) { var user2 = new CommunicatorUser(); user2.Login = us.Login; user2.Salt = Guid.NewGuid().ToString(); var toHash = $"{us.Password}{user2.Salt}"; string md5Password = string.Empty; using (MD5 md5Hash = MD5.Create()) { md5Password = AuthService.GetMd5Hash(md5Hash, toHash); } user2.Password = md5Password; user2.Name = us.Login; this.userRepository.AddUser(user2); } else { throw new Exception(); } }
public void ModifyUser(CommunicatorUser user) { var userInDb = this.context.CommunicatorUser.FirstOrDefault(u => u.Login == user.Login); if (userInDb == null) { throw new Exception(); } userInDb.Status = user.Status; userInDb.Password = user.Password; userInDb.Avatar = user.Avatar; userInDb.Name = user.Name; this.context.SaveChanges(); }
public void AddUser(CommunicatorUser user) { this.context.CommunicatorUser.Add(user); this.context.SaveChanges(); }