Example #1
0
        private void InitFirstTimeUse()
        {
            int rowCount = db.User.Count();

            if (rowCount == 0)
            {
                User user = new User {
                    Username = "******", Password = "******"
                };
                db.User.Add(user);
                db.SaveChanges();
            }
            rowCount = db.Language.Count();
            if (rowCount == 0)
            {
                Language language1 = new Language {
                    Name = "Svenska", Code = "SV-SE"
                };
                db.Language.Add(language1);
                Language language2 = new Language {
                    Name = "Franska", Code = "FR-FR"
                };
                db.Language.Add(language2);
                db.SaveChanges();
            }
        }
Example #2
0
        private int GetWordGroup(int userId, string wordGroupName)
        {
            WordGroup wordGroup = db.WordGroup.Where(n => n.Description == wordGroupName && n.UserId == userId).FirstOrDefault();

            if (wordGroup == null)
            {
                wordGroup = new WordGroup {
                    Description = wordGroupName, UserId = userId
                };
                db.WordGroup.Add(wordGroup);
                db.SaveChanges();
            }
            return(wordGroup.Id);
        }
Example #3
0
        public ActionResult Create([Bind(Include = "Id,Name,Code")] Language language)
        {
            if (CheckAdminUser() == false)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid)
            {
                db.Language.Add(language);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(language));
        }
Example #4
0
        public ActionResult Create([Bind(Include = "Id,Username,Password,Name")] User user)
        {
            if (ModelState.IsValid)
            {
                db.User.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            if (CheckAdminUser())
            {
                return(View(user));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Example #5
0
        public ActionResult Create([Bind(Include = "Id,Description")] WordGroup wordGroup)
        {
            if (ModelState.IsValid)
            {
                int userId = 0;
                if (Session["UserId"] != null)
                {
                    userId = int.Parse(Session["UserId"].ToString());
                }
                else
                {
                    return(HttpNotFound("Error UserId for creator not found"));
                }

                wordGroup.UserId = userId;
                db.WordGroup.Add(wordGroup);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(wordGroup));
        }
Example #6
0
        public ActionResult NewWord(SynonymsView synonymsView, int LanguageId, int SynonymId)
        {
            int wordGroupId = 0;

            if (!int.TryParse(Session["WordGroupId"].ToString(), out wordGroupId))
            {
                throw new Exception("Hittar inget grupp Id och kan inte spara ny synonym i gruppen");
            }

            Word word = new Word();

            word.LanguageId = LanguageId;
            word.Text       = synonymsView.NewWordText;
            db.Word.Add(word);
            db.SaveChanges();
            Synonyms synonym = null;

            synonym = new Synonyms();
            if (SynonymId == 0) //Vi lägger till en helt ny grupp synonymer
            {
                synonym.SynonymId = GetNewSynonymsId();
                db.WordGroupSynonym.Add(new WordGroupSynonym {
                    SynonymId = synonym.SynonymId, WordGroupId = wordGroupId
                });
                db.SaveChanges();
            }
            else
            {
                synonym.SynonymId = SynonymId;
            }

            synonym.Word = word;
            db.Synonyms.Add(synonym);
            db.SaveChanges();

            var routeValuesNewQuestion = new RouteValueDictionary();

            routeValuesNewQuestion.Add("wordGroupId", wordGroupId.ToString());
            return(RedirectToAction("Index", routeValuesNewQuestion));
        }