protected void fvMessage_DataBound(object sender, EventArgs e)
        {
            if(fvMessage.DataItem != null)
            {
                Message message = (Message)fvMessage.DataItem;
                VocabularyContext context = new VocabularyContext();

                if(message.SenderID != message.RecipientID)
                {
                    if(currentUser.ID == message.SenderID )
                    {
                        Label lblSender = (Label)fvMessage.FindControl("lblSender");
                        lblSender.Text = GetLocalResourceObject("from").ToString() + " " + currentUser.Name;

                        Label lblRecipient = (Label)fvMessage.FindControl("lblRecipient");
                        lblRecipient.Text = GetLocalResourceObject("to").ToString() + " "
                                            + context.Users.SingleOrDefault(u => u.ID == message.RecipientID).Name;
                    }
                    if (currentUser.ID == message.RecipientID)
                    {
                        Label lblRecipient = (Label)fvMessage.FindControl("lblRecipient");
                        lblRecipient.Text = GetLocalResourceObject("to").ToString() + " " + currentUser.Name;

                        Label lblSender = (Label)fvMessage.FindControl("lblSender");
                        lblSender.Text = GetLocalResourceObject("from").ToString() + " "
                                        + context.Users.SingleOrDefault(u => u.ID == message.SenderID).Name;
                    }
                }
            }
        }
Example #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     VocabularyContext context = new VocabularyContext();
     int currentLanguageID = context.Languages.SingleOrDefault(l => l.Name == CultureInfo.CurrentUICulture.Name).ID;
     lvCategories.DataSource = context.Categories.Where(c => c.LanguageID == currentLanguageID).ToList();
     lvCategories.DataBind();
 }
        protected void PrepareAnswerMessage()
        {
            if(Request.QueryString["p"] != null)
            {
                int messageID;
                if(int.TryParse(Request.QueryString["p"].ToString(), out messageID))
                {
                    VocabularyContext context = new VocabularyContext();
                    Message message = context.Messages.SingleOrDefault(m => m.ID == messageID);
                    if (message != null)
                    {
                        if(currentUser.Role == "admin")
                        {
                            if(currentUser.ID != message.RecipientID)
                            {
                                //current user is the sender (this is from message object) and send message to the recipient again
                                tbRecipient.Text = context.Users.SingleOrDefault(u => u.ID == message.RecipientID).Name;
                            }
                            else
                            {
                                //current user is the recipient (this is from message object) and send back message to the sender
                                tbRecipient.Text = context.Users.SingleOrDefault(u => u.ID == message.SenderID).Name;
                            }
                        }

                        tbMessageText.Text = System.Environment.NewLine + message.Content;
                        tbMessageText.Focus();
                    }
                }
            }
        }
        string LoadUsers(string partOfName)
        {
            VocabularyContext ctx = new VocabularyContext();
            List<User> userList = ctx.Users.Where(u => u.Name.StartsWith(partOfName) == true).ToList();

            JavaScriptSerializer js = new JavaScriptSerializer();
            return js.Serialize(userList);
        }
        string LoadWords(string partOfName)
        {
            VocabularyContext ctx = new VocabularyContext();
            List<Word> wordList = ctx.Word.Where(w => w.Name.StartsWith(partOfName) == true).ToList();

            JavaScriptSerializer js = new JavaScriptSerializer();
            return js.Serialize(wordList);
        }
 protected void btnSearchUsers_Click(object sender, EventArgs e)
 {
     VocabularyContext context = new VocabularyContext();
     List<User> userList = context.Users.ToList();
     lvUserList.DataSource = userList.FindAll(u => u.Name.Contains(tbUserName.Text));
     RequestedUserName = tbUserName.Text;
     lvUserList.DataBind();
     divContainerBorder.Visible = true;
     tbUserName.Text = string.Empty;
 }
 protected void cvExistingCategory_ServerValidate(object source, ServerValidateEventArgs args)
 {
     VocabularyContext context = new VocabularyContext();
     Category category = context.Categories.SingleOrDefault(c => c.Name == args.Value);
     if(category == null)
     {
         args.IsValid = true;
     }
     else
     {
         args.IsValid = false;
     }
 }
Example #8
0
        protected void lvCateories_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            Category category = (e.Item.DataItem as Category);

            if (category != null)
            {
                VocabularyContext context = new VocabularyContext();
                int wordCount = context.Word.Count(w => w.CategoryID == category.ID);

                Label lblWordCountInCategory = e.Item.FindControl("lblWordCountInCategory") as Label;
                lblWordCountInCategory.Text = wordCount.ToString();
            }
        }
        protected void lvSendedMessages_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.DataItem != null)
            {
                VocabularyContext context = new VocabularyContext();
                Message message = (Message)e.Item.DataItem;

                Label lblRecipient = e.Item.FindControl("lblRecipient") as Label;
                if (lblRecipient != null)
                {
                    lblRecipient.Text = context.Users.SingleOrDefault(u => u.ID == message.RecipientID).Name;
                }
            }
        }
Example #10
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();
            }
        }
Example #11
0
        protected void lvResults_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if(e.Item.DataItem != null)
            {
                VocabularyContext context = new VocabularyContext();
                int languageID = Helpers.GetCurrentLanguageID();
                Word word = (Word)e.Item.DataItem;

                Label lblCategory = e.Item.FindControl("lblCategory") as Label;
                if (lblCategory != null)
                {
                    lblCategory.Text = context.Categories.SingleOrDefault(c => c.ID == word.CategoryID).Name;
                }
            }
        }
Example #12
0
 protected void btnLogin_Click(object sender, EventArgs e)
 {
     VocabularyContext context = new VocabularyContext();
     User user = context.Users.SingleOrDefault(u => u.Name == tbUserName.Text && u.Password == tbPassword.Text);
     if(user != null)
     {
         Session["currentUser"] = user;
         Response.Redirect("~/Default.aspx");
     }
     else
     {
         lblFail.Text = GetLocalResourceObject("fail").ToString();
         lblFail.ForeColor = System.Drawing.Color.Red;
         lblFail.Visible = true;
     }
 }
Example #13
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();
            }
        }
        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();
                }
            }
        }
Example #15
0
 private void setRightView(string viewName)
 {
     if(Session["currentUser"] != null)
     {
         User currentUser = (User)Session["currentUser"];
         VocabularyContext context = new VocabularyContext();
         switch (viewName)
         {
             case "SendedMessages": mvMessageBox.SetActiveView(vSendedMessages);
                                     lvSendedMessages.DataSource = context.Messages.Where(m => m.SenderID == currentUser.ID && m.UserDeletedThis != currentUser.ID).ToList();
                                     lvSendedMessages.DataBind();
                                     break;
             case "ReceivedMessages": mvMessageBox.SetActiveView(vReceivedMessages);
                                     lvReceivedMessages.DataSource = context.Messages.Where(m => m.RecipientID == currentUser.ID && m.UserDeletedThis != currentUser.ID).ToList();
                                      lvReceivedMessages.DataBind();
                                      break;
             default: Response.Redirect("Default.aspx"); break;
         }
     }
 }
Example #16
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //bind list view
            VocabularyContext context = new VocabularyContext();
            int languageID = Helpers.GetCurrentLanguageID();

            if (Request.QueryString["p"] == null)
                Response.Redirect("Default.aspx");

            string inputtedWord = HttpUtility.UrlDecode(Request.QueryString["p"].ToString());
            List<Word> wordList = context.Word.Where(w => w.Name == inputtedWord && w.LanguageID == languageID).ToList();
            if(wordList.Count == 1)
            {
                Response.Redirect("DisplayWord.aspx?pid=" + wordList[0].ID);
            }
            else
            {
                lvResults.DataSource = wordList;
                lvResults.DataBind();
            }
        }
Example #17
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();
                }
            }
        }
        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);
                }

            }
        }
Example #19
0
 public static int GetCurrentLanguageID()
 {
     VocabularyContext context = new VocabularyContext();
     return context.Languages.SingleOrDefault(l => l.Name == CultureInfo.CurrentUICulture.Name).ID;
 }
Example #20
0
 // call when send
 private int GetRecipientID(string recipientName)
 {
     VocabularyContext context = new VocabularyContext();
     User user = context.Users.SingleOrDefault(u => u.Name == recipientName);
     if (user != null)
         return user.ID;
     else return 0;
 }
 // The id parameter should match the DataKeyNames value set on the control
 // or be decorated with a value provider attribute, e.g. [QueryString]int id
 public WebVocabulary2.Models.Message fvMessage_GetItem([QueryString("p")] int id)
 {
     VocabularyContext context = new VocabularyContext();
     return context.Messages.SingleOrDefault(m => m.ID == id);
 }