Пример #1
0
        public void AddContextSame()
        {
            var vectorData = new WordsContext(word);

            vectorData.AddContext(word);
            Assert.AreEqual(0, vectorData.Words.Count);
        }
        public ActionResult Index([Bind(Include = "language,strategy")] LanguageAndStrategyContener lanStr)
        {
            using (wordcontext = new WordsContext())
            {
                UserCl usercl = wordcontext.Users.Where(x => x.name == User.Identity.Name).FirstOrDefault();
                if (usercl.languages.Where(x => x.id == lanStr.language.id).FirstOrDefault() == null)
                {
                    if (usercl.languages.ToList() == null)
                    {
                        usercl.languages = new List <Language>();
                    }
                    if (usercl.usersWords.ToList() == null)
                    {
                        usercl.usersWords = new List <UserWord>();
                    }
                    IQueryable <Word> languageWords = wordcontext.Words.Where(x => x.foreignLanguage.id == lanStr.language.id);
                    foreach (Word word in languageWords)
                    {
                        usercl.usersWords.Add(new UserWord()
                        {
                            lastTimeAccesed = DateTime.Now, levelOfKnowledge = 0, user = usercl, word = word
                        });
                    }
                    usercl.languages.Add(wordcontext.Languages.Where(x => x.id == lanStr.language.id).First());
                }
                usercl.settings.currentLangage           = usercl.languages.FirstOrDefault(x => x.id == lanStr.language.id);
                usercl.settings.numberOfWordsPerLearning = lanStr.strategy.id;
                wordcontext.SaveChanges();

                return(RedirectToAction("Index", "Home"));
            }
        }
Пример #3
0
        //public ActionResult CreateNewDuplicate()
        //{
        //    try
        //    {
        //        using (var ctx = new WordsContext())
        //        {
        //            var model = new Models.DuplicatesModel();

        //            //CREATE NEW DUPLICATE
        //            int order = ctx.Duplicates.OrderByDescending(i => i.Order).Take(1).Select(x => x.Order).FirstOrDefault();
        //            order++;
        //            var dup = ctx.Duplicates.Add(new Duplicate() { Answer1 = "xxx", Answer2 = "xxx", Answer3 = "xxx", Answer4 = "xxx", Order = order });
        //            ctx.SaveChanges();
        //            model.Duplicate = dup;

        //            return View(model);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ex;
        //    }
        //}

        public ActionResult CreateCollection()
        {
            using (var ctx = new WordsContext())
            {
                var collection = new Collection()
                {
                    Name = "Empty" + DateTime.Now.Millisecond
                };

                var dup = new List <Duplicate>();
                for (int i = 0; i < 10; i++)
                {
                    dup.Add(new Duplicate()
                    {
                        Order      = i,
                        Collection = collection
                    });
                }
                //collection.Duplicates = dup;
                collection.Type = collectionType.duplicates;
                ctx.Collections.Add(collection);
                ctx.SaveChanges();
            }
            Response.StatusCode = (int)System.Net.HttpStatusCode.OK;
            return(RedirectToAction("Index", "Duplicates"));
        }
Пример #4
0
        public JsonResult AddNewLanguageWords()
        {
            bool isAuthenticated = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated;

            if (!isAuthenticated)
            {
                return(null);
            }

            using (wordContext = new WordsContext())
            {
                usercl = wordContext.Users.Where(x => x.name == User.Identity.Name).FirstOrDefault();
                IEnumerable <UserWord> userLanguageWords = usercl.usersWords.Where(x => x.word.foreignLanguage.id == usercl.settings.currentLangage.id);
                IQueryable <Word>      newLanguageWords  = wordContext.Words.Where(x => x.foreignLanguage.id == usercl.settings.currentLangage.id);
                int numberOfNewWords = 0;
                foreach (Word word in newLanguageWords)
                {
                    if (userLanguageWords.FirstOrDefault(x => x.word.id == word.id) == null)
                    {
                        usercl.usersWords.Add(new UserWord()
                        {
                            lastTimeAccesed = DateTime.Now, levelOfKnowledge = 0, user = usercl, word = word
                        });
                        numberOfNewWords++;
                    }
                }

                wordContext.SaveChanges();

                return(Json(numberOfNewWords, JsonRequestBehavior.AllowGet));
            }
        }
Пример #5
0
        public void T1_TestDbConnection()
        {
            var db = new WordsContext();

            Console.WriteLine("Testausgabe: " + db.Categories.Count());
            Assert.AreEqual(true, db.Categories.Count() > 0);
        }
Пример #6
0
 public List <Word> Get()
 {
     using (var Context = new WordsContext())
     {
         return(Context.Words.ToList());
     }
 }
Пример #7
0
        public ActionResult Learn()
        {
            using (wordContext = new WordsContext())
            {
                try
                {
                    usercl = wordContext.Users.Where(x => x.name == User.Identity.Name).FirstOrDefault();

                    if (usercl.languages.Count < 1)
                    {
                        return(RedirectToAction("Index", "ChooseLanguage"));
                    }

                    IEnumerable <Language> userLanguages = usercl.languages.ToList();
                    SelectList             sl            = new SelectList(from e in userLanguages
                                                                          select new
                    {
                        Value = e.id,
                        Text  = e.name
                    }, "Value", "Text");
                    return(View(sl));
                }
                catch (Exception e)
                {
                    return(View("Error"));
                }
            }
        }
Пример #8
0
        public ActionResult CreateCollection()
        {
            using (var ctx = new WordsContext())
            {
                var collection = new Collection()
                {
                    Name = "Empty" + DateTime.Now.Millisecond
                };

                var words = new List <Word>();
                for (int i = 0; i < 10; i++)
                {
                    words.Add(new Word()
                    {
                        Part1      = "",
                        Part2      = "",
                        Part3      = "",
                        Part4      = "",
                        Collection = collection
                    });
                }
                //collection.Words = words;
                collection.Type = collectionType.words;
                ctx.Collections.Add(collection);
                ctx.SaveChanges();
            }
            Response.StatusCode = (int)HttpStatusCode.OK;
            return(RedirectToAction("Index", "Words"));
        }
Пример #9
0
        public ActionResult ManageWords(int?collectionid)
        {
            try
            {
                using (var ctx = new WordsContext())
                {
                    if (collectionid == null)
                    {
                        collectionid = -1;
                    }

                    var model = new Models.MainModel();
                    model.Words        = ctx.Words.Include(x => x.Image).Where(x => x.Collection.CollectionId == collectionid).ToList();
                    model.CollectionId = collectionid;
                    var c = ctx.Collections.Include(x => x.Image).Where(x => x.CollectionId == collectionid).FirstOrDefault();
                    if (c != null)
                    {
                        model.CollectionName = c.Name;
                    }
                    if (c.Image != null)
                    {
                        model.CollectionPictureId = c.Image.PictureId;
                    }
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #10
0
        public ActionResult Index(int?collectionid, bool ordenades = false)
        {
            using (var ctx = new WordsContext())
            {
                if (collectionid == null)
                {
                    collectionid = ctx.Collections.Min(x => x.CollectionId);
                }

                var model = new Models.MainModel()
                {
                    Words        = ctx.Words.Include(x => x.Image).Where(x => x.Collection.CollectionId == collectionid).ToList(),
                    CollectionId = collectionid
                };

                var c = ctx.Collections.Include(x => x.Image).Where(x => x.CollectionId == collectionid).FirstOrDefault();
                if (c != null)
                {
                    model.CollectionName = c.Name;
                }
                if (c.Image != null)
                {
                    model.CollectionPictureId = c.Image.PictureId;
                }

                model.Ordenades = ordenades;
                return(View(model));
            }
        }
Пример #11
0
        public ActionResult ManageDuplicatesAjax(string duplicateid, string question, string answer1, string answer2, string answer3, string answer4, bool answer1iscorrect, bool answer2iscorrect, bool answer3iscorrect, bool answer4iscorrect)
        {
            if (!(Session["IsAdmin"] != null && Session["IsAdmin"].ToString().ToUpper() == "TRUE"))
            {
                return(Content("Not allowed", MediaTypeNames.Text.Plain));
            }


            using (var ctx = new WordsContext())
            {
                var dup = ctx.Duplicates.Where(x => x.DuplicateId.ToString() == duplicateid).SingleOrDefault();
                dup.Question = question;

                dup.Answer1 = answer1;
                dup.Answer2 = answer2;
                dup.Answer3 = answer3;
                dup.Answer4 = answer4;

                dup.Answer1IsCorrect = answer1iscorrect;
                dup.Answer2IsCorrect = answer2iscorrect;
                dup.Answer3IsCorrect = answer3iscorrect;
                dup.Answer4IsCorrect = answer4iscorrect;
                ctx.ChangeTracker.DetectChanges(); //alternative is to set  context.Configuration.AutoDetectChangesEnabled = true
                ctx.SaveChanges();
            }

            //  Response.StatusCode = (int)HttpStatusCode.OK;
            return(Content("Message sent!", MediaTypeNames.Text.Plain));
            //  return View(model);
        }
Пример #12
0
        public void Create()
        {
            var vectorData = new WordsContext(word);

            Assert.AreEqual(word, vectorData.Word);
            Assert.AreEqual(0, vectorData.Words.Count);
        }
Пример #13
0
        public WordsService(WordsContext wordsContext, IFileReader fileReader)
        {
            _fileReader = fileReader;
            _context    = wordsContext;
            var entityType = _context.Model.FindEntityType(typeof(Word));

            _wordsTableName = entityType.GetTableName();
        }
Пример #14
0
 public static void Add(Word word)
 {
     using (wordsContext = new WordsContext())
     {
         wordsContext.Words.Add(word);
         wordsContext.SaveChanges();
     }
 }
Пример #15
0
 /// <summary>
 /// Initializes the singleton application object.  This is the first line of authored code
 /// executed, and as such is the logical equivalent of main() or WinMain().
 /// </summary>
 public App()
 {
     InitializeComponent();
     Suspending += OnSuspending;
     using (var db = new WordsContext())
     {
         db.Database.Migrate();
     }
 }
Пример #16
0
        public void AddContext()
        {
            var addingWord = new WordEx(new SimpleWord("Test"));
            var vectorData = new WordsContext(word);

            vectorData.AddContext(addingWord);
            Assert.AreEqual(1, vectorData.Words.Count);
            vectorData.AddContext(addingWord);
            Assert.AreEqual(2, vectorData.Words.Count);
        }
Пример #17
0
 public JsonResult LevelUp(int option)
 {
     using (wordcontext = new WordsContext())
     {
         UserCl usercl = wordcontext.Users.Where(x => x.name == User.Identity.Name).FirstOrDefault();
         wordcontext.UserWords.Where(x => x.id == option).First().levelOfKnowledge = 10;
         wordcontext.SaveChanges();
         return(Json(JsonRequestBehavior.AllowGet));
     }
 }
Пример #18
0
 public ActionResult DeleteCollection(int collectionid)
 {
     using (var ctx = new WordsContext())
     {
         ctx.Words.RemoveRange(ctx.Words.Where(x => x.Collection.CollectionId == collectionid));
         ctx.Collections.RemoveRange(ctx.Collections.Where(x => x.CollectionId == collectionid));
         ctx.SaveChanges();
     }
     return(RedirectToAction("Index", "Words"));
 }
Пример #19
0
        public ActionResult UploadImage(string FileUpload, string DuplicateId, int Num)
        {
            if (!(Session["IsAdmin"] != null && Session["IsAdmin"].ToString().ToUpper() == "TRUE"))
            {
                return(Content("Not allowed", System.Net.Mime.MediaTypeNames.Text.Plain));
            }


            using (var ctx = new WordsContext())
            {
                using (var image = System.Drawing.Image.FromStream(Request.Files[0].InputStream))
                {
                    using (var scaledImage = ImageController.ScaleImage(image, 300, 300))
                    {
                        MemoryStream ms = new MemoryStream();
                        scaledImage.Save(ms, ImageFormat.Jpeg);

                        var dup = ctx.Duplicates.Where(x => x.DuplicateId.ToString() == DuplicateId).SingleOrDefault();
                        switch (Num)
                        {
                        case 0:
                            dup.ImageQuestion         = new Picture();
                            dup.ImageQuestion.Content = ms.ToArray();
                            break;

                        case 1:
                            dup.Image1         = new Picture();
                            dup.Image1.Content = ms.ToArray();
                            break;

                        case 2:
                            dup.Image2         = new Picture();
                            dup.Image2.Content = ms.ToArray();
                            break;

                        case 3:
                            dup.Image3         = new Picture();
                            dup.Image3.Content = ms.ToArray();
                            break;

                        case 4:
                            dup.Image4         = new Picture();
                            dup.Image4.Content = ms.ToArray();
                            break;
                        }


                        ctx.ChangeTracker.DetectChanges();
                        ctx.SaveChanges();
                    }
                }
            }

            return(Json(new { success = "Valid" }));
        }
Пример #20
0
 public ActionResult ChangeCollectionName(string collectionname, int collectionid)
 {
     using (var ctx = new WordsContext())
     {
         var collectionToChange = ctx.Collections.Where(x => x.CollectionId == collectionid).SingleOrDefault();
         collectionToChange.Name = collectionname;
         ctx.ChangeTracker.DetectChanges();
         ctx.SaveChanges();
     }
     return(Json(new { success = "Valid" }));
 }
Пример #21
0
        public ActionResult Upload(string File, int WordId, int PartId)
        {
            if (!(Session["IsAdmin"] != null && Session["IsAdmin"].ToString().ToUpper() == "TRUE"))
            {
                return(Content("Not allowed", System.Net.Mime.MediaTypeNames.Text.Plain));
            }


            var file = Request.Files[0];


            using (var ctx = new WordsContext())
            {
                var wordToChange = ctx.Words.Where(x => x.WordId == WordId).SingleOrDefault();
                var bytes        = SoundController.ReadFully(file.InputStream);
                //var data = ConvertWavToMp3(bytes);
                switch (PartId)
                {
                case 1:
                    wordToChange.Part1Sound = bytes;
                    break;

                case 2:
                    wordToChange.Part2Sound = bytes;
                    break;

                case 3:
                    wordToChange.Part3Sound = bytes;
                    break;

                case 4:
                    wordToChange.Part4Sound = bytes;
                    break;

                case 5:
                    wordToChange.Part5Sound = bytes;
                    break;

                case 6:
                    wordToChange.Part6Sound = bytes;
                    break;

                case 7:
                    wordToChange.Part7Sound = bytes;
                    break;
                }

                ctx.ChangeTracker.DetectChanges();
                ctx.SaveChanges();
            }

            return(Json(new { success = "Successfully uploaded file for Wordid:" + WordId + " PartId:" + PartId }));
        }
Пример #22
0
        // GET: Pieces
        public ActionResult Index()
        {
            using (var ctx = new WordsContext())
            {
                var model = new Models.MainModel()
                {
                    Words = ctx.Words.Where(x => x.Type == Word.TypeEnum.Piece && !string.IsNullOrEmpty(x.Part1.Trim())).ToList(),
                };

                return(View(model));
            }
        }
Пример #23
0
        public ActionResult Index()
        {
            using (wordContext = new WordsContext())
            {
                bool isAuthenticated = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
                if (isAuthenticated)
                {
                    usercl = wordContext.Users.Where(x => x.name == User.Identity.Name).FirstOrDefault();
                }

                return(View());
            }
        }
Пример #24
0
        //[OutputCache(Duration = 3600, VaryByParam = "*")]
        public ActionResult Index(string WordId, int PartId)
        {
            using (var ctx = new WordsContext())
            {
                var word = ctx.Words.Where(x => x.WordId.ToString() == WordId).SingleOrDefault();
                if (word == null)
                {
                    return(null);
                }

                byte[] data = null;
                switch (PartId)
                {
                case 1:
                    data = word.Part1Sound;
                    break;

                case 2:
                    data = word.Part2Sound;
                    break;

                case 3:
                    data = word.Part3Sound;
                    break;

                case 4:
                    data = word.Part4Sound;
                    break;

                case 5:
                    data = word.Part5Sound;
                    break;

                case 6:
                    data = word.Part6Sound;
                    break;

                case 7:
                    data = word.Part7Sound;
                    break;
                }
                if (data != null)
                {
                    return(File(data, "audio/mpeg"));
                }
                else
                {
                    return(null);
                }
            }
        }
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Manage"));
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };

                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        var usercl = new UserCl {
                            name = user.UserName
                        };
                        var userSettings = new UserSettings {
                            currentLangage = null, numberOfWordsPerLearning = 20
                        };
                        WordsContext wc = new WordsContext();

                        wc.Settings.Add(userSettings);
                        usercl.settings = userSettings;
                        wc.Users.Add(usercl);
                        wc.SaveChanges();
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
Пример #26
0
 public static void Delete(string wordId)
 {
     using (wordsContext = new WordsContext())
     {
         foreach (var item in wordsContext.Words)
         {
             if (item.WordId == wordId)
             {
                 wordsContext.Words.Remove(item);
                 wordsContext.SaveChanges();
             }
         }
     }
 }
Пример #27
0
 public static Word Get(string wordId)
 {
     using (wordsContext = new WordsContext())
     {
         foreach (var item in wordsContext.Words)
         {
             if (item.WordId == wordId)
             {
                 return(item);
             }
         }
         return(default(Word));
     }
 }
Пример #28
0
        public ActionResult Index(int?collectionid)
        {
            using (var ctx = new WordsContext())
            {
                if (collectionid == null)
                {
                    CreateNewDuplicateCollection();
                }

                var col = ctx.Collections.Where(x => x.CollectionId == collectionid).SingleOrDefault();
                var dup = ctx.Duplicates.Where(x => x.Collection_CollectionId == col.CollectionId).OrderBy(x => x.Order).FirstOrDefault();

                return(RedirectToAction("IndexByDupId", new { id = dup.DuplicateId }));
            }
        }
Пример #29
0
        public ActionResult Previous(int id)
        {
            var model = new Models.DuplicatesModel();

            using (var ctx = new WordsContext())
            {
                model.Duplicate = ctx.Duplicates.Where(x => x.DuplicateId == id).FirstOrDefault(); //.OrderBy(x=>x.Order).ToList(),
                var order        = model.Duplicate.Order;
                var oldDuplicate = model.Duplicate;

                model.Duplicate = ctx.Duplicates.Where(x => x.Order < order && x.Collection.CollectionId == oldDuplicate.Collection.CollectionId).OrderByDescending(x => x.Order).FirstOrDefault() ?? model.Duplicate;

                return(RedirectToAction("IndexByDupId", "Duplicates", new { id = model.Duplicate.DuplicateId }));
            }
        }
Пример #30
0
        public JsonResult GetCurrentLanguage()
        {
            bool isAuthenticated = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated;

            if (!isAuthenticated)
            {
                return(null);
            }
            using (wordContext = new WordsContext())
            {
                usercl = wordContext.Users.Where(x => x.name == User.Identity.Name).FirstOrDefault();

                return(Json(usercl.settings.currentLangage.name, JsonRequestBehavior.AllowGet));
            }
        }