Esempio n. 1
0
        void AddWordPair(SptUnitOfWork uw, string w1, string w2, Word.SoundGroupEnum grp, bool testOnly)
        {
            var speakers = uw.SpeakerRepository.GetAll().ToList();

            var word1 = new Word {
                WordEntry = w1, SoundGroup = grp, TestOnly = testOnly
            };
            var word2 = new Word {
                WordEntry = w2, SoundGroup = grp, TestOnly = testOnly
            };

            speakers.ForEach(t => word1.WordSpeakers.Add(new WordSpeaker {
                Speaker = t, FileName = w1 + "." + t.SpeakerName + ".mp3"
            }));
            speakers.ForEach(t => word2.WordSpeakers.Add(new WordSpeaker {
                Speaker = t, FileName = w2 + "." + t.SpeakerName + ".mp3"
            }));

            uw.WordRepository.Add(word1);
            uw.WordRepository.Add(word2);
            uw.Save();

            word1.Pair = word2;
            word2.Pair = word1;
            uw.WordRepository.Edit(word1);
            uw.WordRepository.Edit(word2);
            uw.Save();
        }
Esempio n. 2
0
        public override AddUserResponse ProcessRequest(AddUserRequest request)
        {
            AddUserResponse response = new AddUserResponse();

            try
            {
                using (var uow = new SptUnitOfWork())
                {
                    SptUser user = new SptUser
                    {
                        Username = request.Email,
                        Password = request.Password,
                        IsAdmin  = request.IsAdmin,
                        Person   = new Person
                        {
                            FirstName        = request.FirstName,
                            LastName         = request.LastName,
                            Gender           = request.Gender,
                            AgeGroup         = (Person.AgeGroupEnum)request.AgeGroup,
                            ProficiencyLevel = (Person.ProficiencyLevelEnum)request.ProficiencyLevel,
                            CFType           = uow.CFTypeRepository.FindById(request.CFType)
                        }
                    };

                    uow.UserRepository.Add(user);
                    uow.Save();
                }

                return(response);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public override PopulateActivityResponse ProcessRequest(PopulateActivityRequest request)
        {
            PopulateActivityResponse response = new PopulateActivityResponse();

            try
            {
                using (var uow = new SptUnitOfWork())
                {
                    string username = AuthContext.Instance.UserName;
                    var    user     = uow.UserRepository.GetByUserName(username);

                    var             activity     = uow.ActivityRepository.FindById(request.ActivityId);
                    SptUserActivity userActivity = new SptUserActivity
                    {
                        SptUser   = user,
                        Activity  = activity,
                        StartDate = DateTime.Now
                    };

                    var wordSpeakers = uow.WordSpeakerRepository.GetAll();
                    if (activity.IsTest)
                    {
                        wordSpeakers = wordSpeakers
                                       .Where(t => t.Word.TestOnly && t.Speaker.TestOnly == false)
                                       .Union(wordSpeakers.Where(t => t.Word.TestOnly == false)).OrderBy(t => Guid.NewGuid());
                        // wordSpeakers = wordSpeakers.OrderBy(t => Guid.NewGuid());
                    }
                    else
                    {
                        wordSpeakers = wordSpeakers.Where(t => t.Speaker.TestOnly == false && t.Word.TestOnly == false).OrderBy(t => Guid.NewGuid());
                    }

                    foreach (var ws in wordSpeakers)
                    {
                        userActivity.SptUserActivityDetails.Add(new SptUserActivityDetail
                        {
                            SptUserActivity = userActivity,
                            WordSpeaker     = ws
                        });
                    }

                    uow.UserActivityRepository.Add(userActivity);
                    uow.Save();
                }

                return(response);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 4
0
        public override UpdateProfileResponse ProcessRequest(UpdateProfileRequest request)
        {
            UpdateProfileResponse response = new UpdateProfileResponse();

            try
            {
                using (var uow = new SptUnitOfWork())
                {
                    var username = AuthContext.Instance.UserName;
                    var user     = uow.UserRepository.GetByUserName(username);
                    user.Person.FirstName = request.FirstName;
                    user.Person.LastName  = request.LastName;
                    uow.UserRepository.Edit(user);
                    uow.Save();
                }

                return(response);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public override UpdateQuestionResponse ProcessRequest(UpdateQuestionRequest request)
        {
            UpdateQuestionResponse response = new UpdateQuestionResponse();

            try
            {
                using (var uow = new SptUnitOfWork())
                {
                    var question = uow.UserActivityDetailRepository.FindById(request.QuestionId);
                    if (question.WordSpeaker.Word.WordEntry == request.ChosenWord)
                    {
                        question.Result        = true;
                        response.Result        = true;
                        response.FileNameOne   = null;
                        response.FileNameTwo   = null;
                        response.CFFileNameOne = null;
                        response.CFFileNameTwo = null;
                    }
                    else
                    {
                        response.Result = false;
                        question.Result = false;

                        response.FileNameOne = question.WordSpeaker.FileName;
                        response.FileNameTwo = uow.WordSpeakerRepository.FindBy(t => t.Word.Id == question.WordSpeaker.Word.Pair.Id && t.Speaker.Id == question.WordSpeaker.Speaker.Id).Single().FileName;

                        var speaker = question.WordSpeaker.Speaker;
                        if (speaker.SpeakerName.Contains("M"))
                        {
                            speaker = uow.SpeakerRepository.FindBy(t => t.SpeakerName == speaker.SpeakerName.Replace("M", "F")).Single();
                        }
                        else
                        {
                            speaker = uow.SpeakerRepository.FindBy(t => t.SpeakerName == speaker.SpeakerName.Replace("F", "M")).Single();
                        }

                        var cFTypeSpeaker = uow.CFTypeSpeakerRepository.FindBy(t => t.Speaker.Id == speaker.Id && t.CFType.Id == question.SptUserActivity.SptUser.Person.CFType.Id).FirstOrDefault();
                        response.CFFileNameOne = cFTypeSpeaker != null ? cFTypeSpeaker.FileName1 : null;
                        response.CFFileNameTwo = cFTypeSpeaker != null ? cFTypeSpeaker.FileName2 : null;
                    }

                    uow.UserActivityDetailRepository.Edit(question);
                    uow.Save();

                    if (uow.UserActivityDetailRepository.FindBy(t => t.UserActivityId == question.UserActivityId && t.Result == null).Count() == 0)
                    {
                        var userActivity = uow.UserActivityRepository.FindBy(t => t.Id == question.UserActivityId).First();
                        userActivity.FinishDate = DateTime.Now;
                        uow.UserActivityRepository.Edit(userActivity);
                        uow.Save();
                    }
                }

                return(response);
            }
            catch (Exception ex)
            {
                using (SptUnitOfWork cLog = new SptUnitOfWork())
                {
                    EventLog log = new EventLog
                    {
                        EventType    = "Error",
                        Source       = ex.Source,
                        MessageOne   = ex.Message,
                        MessageTwo   = ex.InnerException == null ? null : ex.InnerException.Message,
                        MessageThree = ex.InnerException == null ? null : ex.InnerException.InnerException == null ? null : ex.InnerException.InnerException.Message,
                        StackTrace   = ex.StackTrace
                    };

                    cLog.EventLogRepository.Add(log);
                    cLog.Save();
                }
                throw;
            }
        }
Esempio n. 6
0
        public override SeedDataResponse ProcessRequest()
        {
            var uow = new SptUnitOfWork();
            SeedDataResponse response = new SeedDataResponse();

            try
            {
                // add speakers
                var speakers = new List <Speaker>();
                speakers.Add(new Speaker {
                    SpeakerName = "M1", TestOnly = false
                });
                speakers.Add(new Speaker {
                    SpeakerName = "F1", TestOnly = false
                });
                speakers.Add(new Speaker {
                    SpeakerName = "M2", TestOnly = true
                });
                speakers.Add(new Speaker {
                    SpeakerName = "F2", TestOnly = true
                });
                uow.SpeakerRepository.AddRange(speakers);
                uow.Save();

                // add CFType
                var cFTypes = new List <CFType>();
                cFTypes.Add(new CFType {
                    CFTypeName = "Target"
                });
                cFTypes.Add(new CFType {
                    CFTypeName = "NonTarget"
                });
                cFTypes.Add(new CFType {
                    CFTypeName = "Combination"
                });
                uow.CFTypeRepository.AddRange(cFTypes);
                uow.Save();

                // add CFTypeSpeakers
                var cFTypeSpeakers   = new List <CFTypeSpeaker>();
                var trainingSpeakers = uow.SpeakerRepository.FindBy(t => t.TestOnly == false).ToList();
                var singleCF         = uow.CFTypeRepository.GetAll().ToList().Take(2).ToList();
                var combinedCF       = uow.CFTypeRepository.GetAll().ToList().Last();

                singleCF.ForEach(t => trainingSpeakers.ForEach(p => cFTypeSpeakers.Add(new CFTypeSpeaker {
                    CFType = t, Speaker = p, FileName1 = t.CFTypeName + p.SpeakerName + ".mp3"
                })));
                trainingSpeakers.ForEach(p => cFTypeSpeakers.Add(new CFTypeSpeaker {
                    CFType = combinedCF, Speaker = p, FileName1 = combinedCF.CFTypeName + p.SpeakerName + "P1.mp3", FileName2 = combinedCF.CFTypeName + p.SpeakerName + "P2.mp3"
                }));
                uow.CFTypeSpeakerRepository.AddRange(cFTypeSpeakers);
                uow.Save();

                // add user and pesrson
                var users = new List <SptUser>();
                users.Add(new SptUser
                {
                    Username = "******",
                    Password = "******",
                    IsAdmin  = true,
                    Person   = new Person
                    {
                        FirstName        = "Shilan",
                        LastName         = "Shebli",
                        Gender           = "F",
                        AgeGroup         = Person.AgeGroupEnum.GrpAbove15,
                        ProficiencyLevel = Person.ProficiencyLevelEnum.Beginner,
                        CFType           = uow.CFTypeRepository.FindById(1)
                    }
                });

                users.Add(new SptUser
                {
                    Username = "******",
                    Password = "******",
                    IsAdmin  = true,
                    Person   = new Person
                    {
                        FirstName        = "Siavash",
                        LastName         = "Rostami",
                        Gender           = "M",
                        AgeGroup         = Person.AgeGroupEnum.GrpAbove15,
                        ProficiencyLevel = Person.ProficiencyLevelEnum.Beginner,
                        CFType           = uow.CFTypeRepository.FindById(2)
                    }
                });

                uow.UserRepository.AddRange(users);
                uow.Save();

                // add activities
                var activities = new List <Activity>();
                activities.Add(new Activity {
                    ActivityOrder = 1, ActivityName = "PreTest", ActivitySession = 1, IsTest = true, ActivityTitle = "Pretest", ActivityDesc = "You may Press the play button to hear the pronunciation of a word<br/>then choose the correct written form between the options below.<br/>You can only play once before pressing the answer."
                });
                activities.Add(new Activity {
                    ActivityOrder = 2, ActivityName = "Training", ActivitySession = 1, IsTest = false, ActivityTitle = "Training  - Session 1", ActivityDesc = "You may Press the play button to hear the pronunciation of a word<br/>then choose the correct written form between the options below.<br/>You can play as many times as you need before pressing the answer.<br/>If you pick the wrong answer, you will be presented with an auditory feedback."
                });
                activities.Add(new Activity {
                    ActivityOrder = 3, ActivityName = "Training", ActivitySession = 2, IsTest = false, ActivityTitle = "Training  - Session 2", ActivityDesc = "You may Press the play button to hear the pronunciation of a word<br/>then choose the correct written form between the options below.<br/>You can play as many times as you need before pressing the answer.<br/>If you pick the wrong answer, you will be presented with an auditory feedback."
                });
                activities.Add(new Activity {
                    ActivityOrder = 4, ActivityName = "Training", ActivitySession = 3, IsTest = false, ActivityTitle = "Training  - Session 3", ActivityDesc = "You may Press the play button to hear the pronunciation of a word<br/>then choose the correct written form between the options below.<br/>You can play as many times as you need before pressing the answer.<br/>If you pick the wrong answer, you will be presented with an auditory feedback."
                });
                activities.Add(new Activity {
                    ActivityOrder = 5, ActivityName = "Training", ActivitySession = 4, IsTest = false, ActivityTitle = "Training  - Session 4", ActivityDesc = "You may Press the play button to hear the pronunciation of a word<br/>then choose the correct written form between the options below.<br/>You can play as many times as you need before pressing the answer.<br/>If you pick the wrong answer, you will be presented with an auditory feedback."
                });
                activities.Add(new Activity {
                    ActivityOrder = 6, ActivityName = "Training", ActivitySession = 5, IsTest = false, ActivityTitle = "Training  - Session 5", ActivityDesc = "You may Press the play button to hear the pronunciation of a word<br/>then choose the correct written form between the options below.<br/>You can play as many times as you need before pressing the answer.<br/>If you pick the wrong answer, you will be presented with an auditory feedback."
                });
                activities.Add(new Activity {
                    ActivityOrder = 7, ActivityName = "Training", ActivitySession = 6, IsTest = false, ActivityTitle = "Training  - Session 6", ActivityDesc = "You may Press the play button to hear the pronunciation of a word<br/>then choose the correct written form between the options below.<br/>You can play as many times as you need before pressing the answer.<br/>If you pick the wrong answer, you will be presented with an auditory feedback."
                });
                activities.Add(new Activity {
                    ActivityOrder = 8, ActivityName = "PostTest", ActivitySession = 1, IsTest = true, ActivityTitle = "Posttest", ActivityDesc = "You may Press the play button to hear the pronunciation of a word<br/>then choose the correct written form between the options below.<br/>You can only play once before pressing the answer."
                });
                uow.ActivityRepository.AddRange(activities);
                uow.Save();

                // add Words and WordSpeakers

                // Set 1, familiar
                AddWordPair(uow, "Bet", "Bert", Word.SoundGroupEnum.Set1, false);
                AddWordPair(uow, "Bed", "bird", Word.SoundGroupEnum.Set1, false);
                AddWordPair(uow, "Ten", "Turn", Word.SoundGroupEnum.Set1, false);
                AddWordPair(uow, "Hell", "Hurl", Word.SoundGroupEnum.Set1, false);
                AddWordPair(uow, "Nest", "Nursed", Word.SoundGroupEnum.Set1, false);
                AddWordPair(uow, "Bled", "Blurred", Word.SoundGroupEnum.Set1, false);
                AddWordPair(uow, "Best", "Burst", Word.SoundGroupEnum.Set1, false);
                // set 1, unfamiliar
                AddWordPair(uow, "Well", "Whirl", Word.SoundGroupEnum.Set1, true);
                AddWordPair(uow, "End", "Earned", Word.SoundGroupEnum.Set1, true);
                AddWordPair(uow, "Spend", "Spurned", Word.SoundGroupEnum.Set1, true);


                // Set 2, familiar
                AddWordPair(uow, "Ship", "Sheep", Word.SoundGroupEnum.Set2, false);
                AddWordPair(uow, "Fit", "Feet", Word.SoundGroupEnum.Set2, false);
                AddWordPair(uow, "Bit", "Beat", Word.SoundGroupEnum.Set2, false);
                AddWordPair(uow, "Rich", "Reach", Word.SoundGroupEnum.Set2, false);
                AddWordPair(uow, "Itch", "Each", Word.SoundGroupEnum.Set2, false);
                AddWordPair(uow, "Chick", "Cheek", Word.SoundGroupEnum.Set2, false);
                AddWordPair(uow, "Dip", "Deep", Word.SoundGroupEnum.Set2, false);
                // set 2, unfamiliar
                AddWordPair(uow, "Fizz", "Fees", Word.SoundGroupEnum.Set2, true);
                AddWordPair(uow, "Hip", "Heap", Word.SoundGroupEnum.Set2, true);
                AddWordPair(uow, "Pill", "Peel", Word.SoundGroupEnum.Set2, true);


                // Set 3, familiar
                AddWordPair(uow, "Pull", "Pool", Word.SoundGroupEnum.Set3, false);
                AddWordPair(uow, "Wood", "Would", Word.SoundGroupEnum.Set3, false);
                AddWordPair(uow, "Soot", "Suit", Word.SoundGroupEnum.Set3, false);
                AddWordPair(uow, "Pulls", "Pools", Word.SoundGroupEnum.Set3, false);
                AddWordPair(uow, "Food", "Foot", Word.SoundGroupEnum.Set3, false);
                AddWordPair(uow, "Kook", "Cook", Word.SoundGroupEnum.Set3, false);
                AddWordPair(uow, "Luke", "Look", Word.SoundGroupEnum.Set3, false);
                // set 3, unfamiliar
                AddWordPair(uow, "Boole", "Bull", Word.SoundGroupEnum.Set3, true);
                AddWordPair(uow, "Stewed", "Stood", Word.SoundGroupEnum.Set3, true);
                AddWordPair(uow, "Gooed", "Good", Word.SoundGroupEnum.Set3, true);


                // Set 4, familiar
                AddWordPair(uow, "O", "Or", Word.SoundGroupEnum.Set4, false);
                AddWordPair(uow, "Code", "Cord", Word.SoundGroupEnum.Set4, false);
                AddWordPair(uow, "Doze", "Doors", Word.SoundGroupEnum.Set4, false);
                AddWordPair(uow, "Foam", "Form", Word.SoundGroupEnum.Set4, false);
                AddWordPair(uow, "Goal", "Gall", Word.SoundGroupEnum.Set4, false);
                AddWordPair(uow, "Load", "Lord", Word.SoundGroupEnum.Set4, false);
                AddWordPair(uow, "Moan", "Mourn", Word.SoundGroupEnum.Set4, false);
                // set 4, unfamiliar
                AddWordPair(uow, "Motor", "Mortar", Word.SoundGroupEnum.Set4, true);
                AddWordPair(uow, "Mow", "More", Word.SoundGroupEnum.Set4, true);
                AddWordPair(uow, "Oat", "Ought", Word.SoundGroupEnum.Set4, true);

                uow.Dispose();
                return(response);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 7
0
        public override RegisterResponse ProcessRequest(RegisterRequest request)
        {
            var uow = new SptUnitOfWork();
            RegisterResponse response = new RegisterResponse();

            try
            {
                if (uow.UserRepository.FindBy(t => t.Username == request.Email).Any())
                {
                    throw new Exception("Email address is not available!");
                }

                var cfs =
                    from c in uow.CFTypeRepository.GetAll()
                    join p in uow.PersonRepository.FindBy(t => t.AgeGroup == (Person.AgeGroupEnum)request.AgeGroup && t.ProficiencyLevel == (Person.ProficiencyLevelEnum)request.ProficiencyLevel) on c.Id equals p.CFType.Id into ps
                    from q in ps.DefaultIfEmpty()
                    select new { cf = c, cnt = q.CFType != null?ps.Count(t => t.CFType.Id == c.Id) : 0 };

                var next = cfs.OrderBy(t => t.cnt).ThenBy(t => t.cf.Id).First().cf;

                SptUser user = new SptUser
                {
                    Username = request.Email,
                    Password = request.Password,
                    IsAdmin  = false,
                    Person   = new Person
                    {
                        FirstName        = request.FirstName,
                        LastName         = request.LastName,
                        Gender           = request.Gender,
                        AgeGroup         = (Person.AgeGroupEnum)request.AgeGroup,
                        ProficiencyLevel = (Person.ProficiencyLevelEnum)request.ProficiencyLevel,
                        CFType           = next
                    }
                };

                uow.UserRepository.Add(user);
                uow.Save();
                uow.Dispose();

                try
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("Dear {0},");
                    sb.Append("\n\nThank you for registering for the Oratio speech perception training.");
                    sb.Append("\n\n\tYour username : {1}");
                    sb.Append("\n\tYour password : {2}");
                    sb.Append("\n\nYou can sign in and start using your credentials straight away.");
                    sb.Append("\nIf you have any questions please contact support at [email protected].");
                    sb.Append("\n\nBest regards,");
                    sb.Append("\nOratio");
                    sb.Append("\n[" + DateTime.Now + "]");

                    string body = string.Format(sb.ToString(), request.FirstName, request.Email, request.Password);
                    // MailHleper.Instance.SendMail(request.Email, "Welcome to Oratio!", body);
                }
                catch (Exception) {}

                return(response);
            }
            catch (Exception)
            {
                throw;
            }
        }