Esempio n. 1
0
        public void UpdateWord(WordModel model)
        {
            var entity = context.Words.Single(w => w.WordId == model.WordId);

            entity.Word       = model.Word;
            entity.Definition = model.Definition;
            entity.Etymology  = model.Etymology;
            context.SaveChanges();
        }
Esempio n. 2
0
        public void deleteTranslationLanguage(string id)
        {
            var deleteTranslations = dbContext.Translations.Where(t => t.LanguageId == id);

            foreach (Translation translation in deleteTranslations)
            {
                dbContext.Translations.Remove(translation);
            }
            dbContext.SaveChanges();
        }
Esempio n. 3
0
        protected void btnAddWord_Click(object sender, EventArgs e)
        {
            Page.Validate("AddWord");
            if (Page.IsValid)
            {
                try
                {
                    Word word = new Word();
                    //fill word data on english
                    word.Name        = tbWordEn.Text;
                    word.Description = ftbMeaningEn.Text;
                    word.LanguageID  = Helpers.EnLangID;
                    int resultID;
                    if (int.TryParse(ddlCategoriesEn.SelectedValue, out resultID))
                    {
                        word.CategoryID = resultID;
                    }

                    VocabularyContext context = new VocabularyContext();
                    context.Word.Add(word);
                    context.SaveChanges();

                    ////////////////////////////////////

                    //fill word data on bulgarian
                    word             = new Word();
                    word.Name        = tbWordBg.Text;
                    word.Description = ftbMeaningBg.Text;
                    word.LanguageID  = Helpers.BgLangID;
                    resultID         = 0;
                    if (int.TryParse(ddlCategoriesBg.SelectedValue, out resultID))
                    {
                        word.CategoryID = resultID;
                    }
                    context.Word.Add(word);
                    context.SaveChanges();

                    tbWordEn.Text     = string.Empty;
                    ftbMeaningEn.Text = string.Empty;
                    tbWordBg.Text     = string.Empty;
                    ftbMeaningBg.Text = string.Empty;
                    hfResult.Value    = "1";
                    pnlDialog.Visible = true;
                    litResult.Text    = GetLocalResourceObject("Success").ToString();
                }
                catch (Exception ex)
                {
                    string s = ex.Message;
                    hfResult.Value    = "0";
                    pnlDialog.Visible = true;
                    litResult.Text    = GetLocalResourceObject("Fail").ToString();
                }
            }
        }
Esempio n. 4
0
        public ActionResult CreateLanguage(Language language)
        {
            var langtag = language.LanguageId;

            try
            {
                CultureInfo lang = new CultureInfo(langtag);
                var         vocabularyLanguage = dbContext.Languages.Find(langtag);
                if (vocabularyLanguage == null)
                {
                    language.LanguageNativeName = lang.NativeName;
                    dbContext.Languages.Add(language);
                    dbContext.SaveChanges();
                    Session["LanguageMessage"] = "Язык успешно добавлен в словарь.";
                    return(RedirectToAction("ListLanguages"));
                }
                else
                {
                    ModelState.AddModelError("", "Создаеваемый язык уже добавлен в словарь.");
                    return(View(language));
                }
            }
            catch
            {
                ModelState.AddModelError("", "Языка, с создаваемой аббревиатурой, не существует.");
                return(View(language));
            }
        }
Esempio n. 5
0
        protected void btnAddCategory_Click(object sender, EventArgs e)
        {
            Page.Validate("AddCategory");
            if (Page.IsValid)
            {
                try
                {
                    Category category = new Category();
                    //fill word data on english
                    category.Name       = tbCategoryEn.Text;
                    category.LanguageID = Helpers.EnLangID;

                    VocabularyContext context = new VocabularyContext();
                    context.Categories.Add(category);
                    context.SaveChanges();

                    ////////////////////////////////////

                    //fill word data on bulgarian
                    category            = new Category();
                    category.Name       = tbCategoryBg.Text;
                    category.LanguageID = Helpers.BgLangID;

                    context.Categories.Add(category);
                    context.SaveChanges();

                    tbCategoryEn.Text = string.Empty;
                    tbCategoryBg.Text = string.Empty;

                    hfResult.Value    = "1";
                    pnlDialog.Visible = true;
                    litResult.Text    = GetLocalResourceObject("Success").ToString();
                }
                catch (Exception ex)
                {
                    string s = ex.Message;
                    hfResult.Value    = "0";
                    pnlDialog.Visible = true;
                    litResult.Text    = GetLocalResourceObject("Fail").ToString();
                }
            }
        }
Esempio n. 6
0
        protected void ibtnDeleteWord_Command(object sender, CommandEventArgs e)
        {
            VocabularyContext context = new VocabularyContext();
            Word word = context.Word.SingleOrDefault(w => w.ID == (int)e.CommandArgument);

            if (word != null)
            {
                context.Word.Remove(word);
                context.SaveChanges();
            }
        }
 public static void UpdateRow(VocabularyContext vocabularyContext, Vocabulary newRow)
 {
     try
     {
         vocabularyContext.Vocabularies.AddOrUpdate(newRow);
         vocabularyContext.SaveChanges();
     }
     catch (Exception e)
     {
         Exceptions.Catching(e);
     }
 }
 public static void RemoveRow(VocabularyContext vocabularyContext, Vocabulary row)
 {
     try
     {
         vocabularyContext.Vocabularies.Remove(row);
         vocabularyContext.SaveChanges();
     }
     catch (Exception e)
     {
         Exceptions.Catching(e);
     }
 }
        protected void ibtnDeleteMessage_Command(object sender, CommandEventArgs e)
        {
            int messageID;

            if (int.TryParse(e.CommandArgument.ToString(), out messageID))
            {
                VocabularyContext context = new VocabularyContext();
                Message           message = context.Messages.SingleOrDefault(m => m.ID == messageID);

                if (Session["currentUser"] != null)
                {
                    currentUser = (User)Session["currentUser"];

                    string redirectPage;
                    if (currentUser.ID == message.SenderID)
                    {
                        redirectPage = "MessageBox.aspx?p=SendedMessages";
                    }
                    else
                    {
                        redirectPage = "MessageBox.aspx?p=ReceivedMessages";
                    }

                    if (message.UserDeletedThis == 0)
                    {
                        message.UserDeletedThis = currentUser.ID;
                        context.SaveChanges();
                    }
                    else
                    {
                        context.Messages.Remove(message);
                        context.SaveChanges();
                    }
                    Response.Redirect(redirectPage);
                }
            }
        }
Esempio n. 10
0
 public static void RemoveUser(UserContext userContext, VocabularyContext vocabularyContext, ref User user)
 {
     try
     {
         VocabularyController.RemoveVocabulary(vocabularyContext, user);
         vocabularyContext.SaveChanges();
         userContext.Users.Remove(user);
         userContext.SaveChanges();
         user = null;
     }
     catch (Exception e)
     {
         Exceptions.Catching(e);
     }
 }
Esempio n. 11
0
        protected void ibtnDeleteUser_Command(object sender, CommandEventArgs e)
        {
            VocabularyContext context = new VocabularyContext();
            int  userID = Convert.ToInt32(e.CommandArgument);
            User user   = context.Users.SingleOrDefault(u => u.ID == userID);

            if (user != null)
            {
                context.Users.Remove(user);
                context.SaveChanges();

                List <User> userList = context.Users.ToList();
                lvUserList.DataSource = userList.FindAll(u => u.Name.Contains(RequestedUserName));
                lvUserList.DataBind();
            }
        }
Esempio n. 12
0
        protected void btnSend_Click(object sender, EventArgs e)
        {
            if (Session["currentUser"] != null)
            {
                VocabularyContext context = new VocabularyContext();
                User    currentUser       = (User)Session["currentUser"];
                Message newMessage        = new Message();
                newMessage.MessageDate     = DateTime.Now;
                newMessage.Content         = tbMessageText.Text;
                newMessage.UserDeletedThis = 0;
                newMessage.SenderID        = currentUser.ID;
                newMessage.RecipientID     = GetRecipientID(tbRecipient.Text);

                context.Messages.Add(newMessage);
                context.SaveChanges();
            }
        }
Esempio n. 13
0
        public string Index(string message)
        {
            string[] userWords;
            string   answer = "";
            bool     IsAdmin;

            userWords = message.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if ((UserManager.FindByName(User.Identity.Name) == null) &&
                (userWords[0].Equals("login") == false) &&
                (userWords[0].Equals("register") == false))
            {
                return("Sorry, Stranger, login or register, please.");
            }
            FirstRun();
            IsAdmin = User.Identity.Name.Equals("Administrator");
            answer  = CommandMode(userWords, IsAdmin);
            //IdentifyNewWords(userWords);
            db.SaveChanges();
            return(answer);
        }
Esempio n. 14
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            Page.Validate("Register");
            if (Page.IsValid)
            {
                try
                {
                    User user             = new User();
                    VocabularyContext ctx = new VocabularyContext();
                    user = ctx.Users.SingleOrDefault(u => u.Name == tbUserName.Text);

                    if (user != null)
                    {
                        hfResult.Value    = "1";
                        pnlDialog.Visible = true;
                        litResult.Text    = GetLocalResourceObject("ExistUser").ToString();
                    }
                    else
                    {
                        user = new User {
                            Name = tbUserName.Text, Role = "user", Password = tbPassword.Text
                        };
                        ctx.Users.Add(user);
                        ctx.SaveChanges();

                        //Login user
                        Session["currentUser"] = user;
                        Response.Redirect("~/Default.aspx");
                    }
                }
                catch (Exception ex)
                {
                    string s = ex.Message;
                    hfResult.Value    = "0";
                    pnlDialog.Visible = true;
                    litResult.Text    = GetLocalResourceObject("Fail").ToString();
                }
            }
        }
Esempio n. 15
0
 public bool Save()
 {
     return(_context.SaveChanges() >= 0);
 }
 public void Save()
 {
     db.SaveChanges();
 }
Esempio n. 17
0
 public void Create(Word item)
 {
     db.Words.Add(item);
     db.SaveChanges();
 }