public void RegisterUser(UserModel registrationModel) { var user = Mapper.Map <UserEntity>(registrationModel); var userProgress = new UserProgressEntity() { QuestionNumber = 0, User = user, UserId = user.UserId, PartNumber = 0 }; UnitOfWork.UserProgressRepository.Insert(userProgress); UnitOfWork.UserRepository.Insert(user); UnitOfWork.Commit(); }
public static UserProgressEntity GetRelevantUserProgress( this UserProgressEntity userProgress, ITaskRepository taskRepository) { var topics = taskRepository.GetTopics(); foreach (var topic in topics) { userProgress.TopicsProgress.TryAdd(topic.Id, topic.ToProgressEntity()); } var ids = topics.Select(topic => topic.Id); var progress = userProgress .TopicsProgress .TakeFrom(ids); return(userProgress.With(topicsProgress: progress)); }
public static UserEntity FindOrInsertUser( this IUserRepository userRepository, Guid userId, ITaskRepository taskRepository) { var progress = new UserProgressEntity( Guid.NewGuid(), Guid.NewGuid(), userId, id: Guid.NewGuid(), currentTask: null, topicsProgress: taskRepository .GetTopics() .SafeToDictionary( topic => topic.Id, topic => topic.ToProgressEntity())); return(userRepository.FindById(userId) ?? userRepository.Insert(new UserEntity(userId, progress))); }
public UserEntity With(UserProgressEntity userProgress) => new UserEntity(Id, userProgress);
public UserEntity(Guid id, UserProgressEntity userProgressEntity) : base(id) { UserProgressEntity = userProgressEntity; }