public ActionResult Index(string searchText, string message, int?i, bool update = false, int id = 0)
        {
            if (searchText != null)
            {
                searchText = searchText.ToLower();
            }
            string messageType = null;

            if (update && db.keywords.Count((a) => a.id == id) == 1)
            {
                keywords targetKeyword = db.keywords.Find(id);
                if (targetKeyword != null)
                {
                    ViewData["Word"]   = targetKeyword.keyword;
                    ViewData["Update"] = update;
                    ViewData["Id"]     = id;
                }
            }
            if (message != null)
            {
                if (message == "Произошла ошибка или запись уже есть." || message == "Произошла непредвиденная ошибка." || message == "Произошла непредвиденная ошибка или такое слово уже есть.")
                {
                    messageType = "danger";
                }
                else
                {
                    messageType = "success";
                }
                ViewData["messageType"] = messageType;
                ViewData["message"]     = message;
            }
            return(View((db.keywords.Where(word => word.keyword.ToLower().Contains(searchText) || searchText == null)).OrderBy(x => x.keyword).ToList().ToPagedList(i ?? 1, 10)));
        }
示例#2
0
        //this funciton is used to insert entries into the symbol table
        public void insert(string lex, keywords token, int depth)
        {
            int location = hash(lex);
            TableEntryInterface newEntry = new SymbolTableEntry();

            newEntry.lexeme = lex;
            newEntry.token  = token;
            newEntry.depth  = depth;
            if (token == keywords.idt)
            {
                if (Globals.table[location].Count != 0)
                {
                    Globals.table[location].Insert(0, newEntry);
                }
                else
                {
                    Globals.table[location].Add(newEntry);
                }
            }
            else
            {
                Console.WriteLine("ERROR! SYMBOL TABLE ONLY ACCEPTS IDENTIFIER TOKENS!");
                Console.WriteLine("Press any key to exit");
                Console.ReadKey();
                System.Environment.Exit(1);
            }
        }
        public ActionResult Update(string keywordInput, int idInput)
        {
            string localMessage = "Произошла непредвиденная ошибка или такое слово уже есть.";

            if (ModelState.IsValid && db.keywords.Count((a) => a.id == idInput) == 1 && db.keywords.Count((a) => a.keyword == keywordInput) == 0)
            {
                keywords targetWord = db.keywords.Find(idInput);
                localMessage               = $"Запись {targetWord.keyword} успешно изменена на {keywordInput}.";
                targetWord.keyword         = keywordInput;
                db.Entry(targetWord).State = EntityState.Modified;
                db.SaveChanges();
            }
            return(RedirectToAction("/Index", new { i = 1, message = localMessage }));
        }
        // GET: Keywords/Edit/5
        public ActionResult Edit(int?id)
        {
            string localMessage = "Произошла непредвиденная ошибка.";

            if (id != null)
            {
                keywords targetWord = db.keywords.Find(id);
                if (targetWord != null)
                {
                    return(RedirectToAction("/Index", new { i = 1, id = id, update = true }));
                }
            }
            return(RedirectToAction("/Index", new { i = 1, message = localMessage }));
        }
        public ActionResult CreatePK(string Keywords, string Publications)
        {
            string localMessage = "Произошла ошибка или запись уже есть.";

            keywords     a = db.keywords.Where(x => x.keyword == Keywords).FirstOrDefault();
            publications p = db.publications.Where(x => x.title == Publications).FirstOrDefault();

            if (a != null && p != null && !p.keywords.Contains(a))
            {
                a.publications.Add(p);
                p.keywords.Add(a);
                db.SaveChanges();
                localMessage = $"Связь между словом: {a.keyword} и публикацией: {p.title} успешно добавлена.";
            }
            return(RedirectToAction("/Index", new { message = localMessage }));
        }
        // GET: Keywords/Delete/5
        public ActionResult Delete(int?id)
        {
            string localMessage = null;

            if (id != null)
            {
                keywords targetWord = db.keywords.Find(id);
                if (targetWord != null)
                {
                    db.keywords.Remove(targetWord);
                    db.SaveChanges();
                    localMessage = $"Запись {targetWord.keyword} была успешно удалена.";
                    return(RedirectToAction("/Index", new { i = 1, message = localMessage }));
                }
            }
            localMessage = "Произошла непредвиденная ошибка.";
            return(RedirectToAction("/Index", new { i = 1, message = localMessage }));
        }
        public ActionResult Create(string keywordInput)
        {
            string localMessage = "Произошла ошибка или запись уже есть.";

            if (ModelState.IsValid && db.keywords.Count((a) => a.keyword == keywordInput) == 0)
            {
                int current_id = db.keywords.Count();
                while (db.keywords.Count((a) => a.id == current_id) == 1)
                {
                    current_id++;
                }
                keywords newWord = new keywords();
                newWord.id      = current_id;
                newWord.keyword = keywordInput;
                db.keywords.Add(newWord);
                db.SaveChanges();
                localMessage = $"Запись {keywordInput} успешно добавлена.";
            }
            return(RedirectToAction("/Index", new { i = 1, message = localMessage }));
        }
        private List <int> GetKeywords(string input)
        {
            char[]     delimiter = { ',' };
            string[]   keywords  = input.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
            List <int> keys      = new List <int>();

            for (int i = 0; i < keywords.Length; i++)
            {
                keywords[i] = keywords[i].ToLower().Replace(" ", "");
            }
            foreach (string word in keywords)
            {
                keywords w = db.keywords.Where(x => x.keyword == word).FirstOrDefault();
                if (w != null)
                {
                    keys.Add(w.id);
                }
            }
            return(keys);
        }
        public ActionResult Update(string titleInput, int idInput, int yearInput, string[] Authors, string Words, string Source, string Type, int issueInput = 0, int volumeInput = 0)
        {
            List <int> authorId = GetAuthors(Authors);

            string[] words        = GetKeywords(Words);
            string   localMessage = "Произошла непредвиденная ошибка или такая публикация уже есть.";

            try
            {
                if (ModelState.IsValid && db.publications.Count((a) => a.id == idInput) == 1 && db.publications.Count((a) => (a.title == titleInput) && (a.year == yearInput)) == 0)
                {
                    publications targetPublication = db.publications.Find(idInput);
                    localMessage            = $"Запись {targetPublication.title} успешно изменена на {titleInput}.";
                    targetPublication.title = titleInput;
                    targetPublication.year  = Convert.ToInt16(yearInput);

                    foreach (authors au in targetPublication.authors)
                    {
                        au.publications.Remove(targetPublication);
                    }
                    targetPublication.authors.Clear();
                    foreach (int authorid in authorId)
                    {
                        authors a = db.authors.Find(authorid);
                        if (a != null)
                        {
                            targetPublication.authors.Add(a);
                            a.publications.Add(targetPublication);
                        }
                    }
                    foreach (keywords kw in targetPublication.keywords)
                    {
                        kw.publications.Remove(targetPublication);
                    }
                    targetPublication.keywords.Clear();
                    foreach (string keyword in words)
                    {
                        keywords k = db.keywords.Where(x => x.keyword == keyword).FirstOrDefault();
                        if (k == null)
                        {
                            int k_id = db.keywords.Count();
                            while (db.keywords.Count((a) => a.id == k_id) == 1)
                            {
                                k_id++;
                            }
                            k         = new keywords();
                            k.id      = k_id;
                            k.keyword = keyword;
                            db.keywords.Add(k);
                            db.SaveChanges();
                        }
                        targetPublication.keywords.Add(k);
                        k.publications.Add(targetPublication);
                    }
                    foreach (sources so in targetPublication.sources)
                    {
                        so.publications.Remove(targetPublication);
                    }
                    targetPublication.sources.Clear();
                    sources s = db.sources.Where(x => x.item_title == Source).FirstOrDefault();
                    if (s != null)
                    {
                        targetPublication.sources.Add(s);
                        if (issueInput > 0 && volumeInput > 0)
                        {
                            s.journal_issue  = issueInput;
                            s.journal_volume = volumeInput;
                        }
                        else
                        {
                            s.journal_issue  = null;
                            s.journal_volume = null;
                        }
                        s.publications.Add(targetPublication);
                    }
                    foreach (types ty in targetPublication.types)
                    {
                        ty.publications.Remove(targetPublication);
                    }
                    targetPublication.types.Clear();
                    types t = db.types.Where(x => x.type_name == Type).FirstOrDefault();
                    if (t != null)
                    {
                        targetPublication.types.Add(t);
                        t.publications.Add(targetPublication);
                    }

                    db.Entry(targetPublication).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch
            {
            }
            return(RedirectToAction("/Index", new { i = 1, message = localMessage }));
        }
        public ActionResult Create(string titleInput, int yearInput, string[] Authors, string Words, string Source, string Type, int issueInput = 0, int volumeInput = 0)
        {
            string     localMessage = "Произошла ошибка или запись уже есть.";
            List <int> authorId     = GetAuthors(Authors);

            string[] words = GetKeywords(Words);

            try
            {
                if (ModelState.IsValid && db.publications.Count((a) => a.title == titleInput) == 0 && authorId.Count != 0)
                {
                    int current_id = db.publications.Count();
                    while (db.publications.Count((a) => a.id == current_id) == 1)
                    {
                        current_id++;
                    }
                    publications newPublication = new publications();

                    newPublication.id    = current_id;
                    newPublication.title = titleInput;
                    newPublication.year  = Convert.ToInt16(yearInput);
                    foreach (int authorid in authorId)
                    {
                        authors a = db.authors.Find(authorid);
                        if (a != null)
                        {
                            newPublication.authors.Add(a);
                            a.publications.Add(newPublication);
                        }
                    }
                    foreach (string keyword in words)
                    {
                        keywords k = db.keywords.Where(x => x.keyword == keyword).FirstOrDefault();
                        if (k == null)
                        {
                            int k_id = db.keywords.Count();
                            while (db.keywords.Count((a) => a.id == k_id) == 1)
                            {
                                k_id++;
                            }
                            k         = new keywords();
                            k.id      = k_id;
                            k.keyword = keyword;
                            db.keywords.Add(k);
                            db.SaveChanges();
                        }
                        newPublication.keywords.Add(k);
                        k.publications.Add(newPublication);
                    }
                    sources s = db.sources.Where(x => x.item_title == Source).FirstOrDefault();
                    if (s != null)
                    {
                        newPublication.sources.Add(s);
                        if (issueInput > 0 && volumeInput > 0)
                        {
                            s.journal_issue  = issueInput;
                            s.journal_volume = volumeInput;
                        }
                        else
                        {
                            s.journal_issue  = null;
                            s.journal_volume = null;
                        }
                        s.publications.Add(newPublication);
                    }
                    types t = db.types.Where(x => x.type_name == Type).FirstOrDefault();
                    if (t != null)
                    {
                        newPublication.types.Add(t);
                        t.publications.Add(newPublication);
                    }

                    db.publications.Add(newPublication);
                    db.SaveChanges();
                    localMessage = $"Запись {titleInput} успешно добавлена.";
                }
            }
            catch
            {
            }
            return(RedirectToAction("/Index", new { i = 1, message = localMessage }));
        }