Ejemplo n.º 1
0
        protected void LinkButtonSaveUser_Click(object sender, EventArgs e)
        {
            var context = new ApplicationDbContext();
            var user    = context.Users.Find(userId);

            user.UserName = this.TextBoxUserName.Text;
            user.Email    = this.TextBoxEmail.Text;
            if (UploadAvatar.HasFile)
            {
                if (UploadAvatar.PostedFile.ContentType == "image/jpeg" ||
                    UploadAvatar.PostedFile.ContentType == "image/gif" ||
                    UploadAvatar.PostedFile.ContentType == "image/png")
                {
                    if (UploadAvatar.PostedFile.ContentLength < 102400)
                    {
                        var filename = user.UserName + Path.GetExtension(UploadAvatar.FileName);
                        UploadAvatar.SaveAs(Server.MapPath("~/Avatar_Files/") + filename);
                        user.Avatar = filename;
                    }
                    else
                    {
                        ErrorSuccessNotifier.AddErrorMessage("Upload status: The file has to be less than 100 kb!");
                        return;
                    }
                }
                else
                {
                    ErrorSuccessNotifier.AddErrorMessage("Upload status: Only JPEG, Gif and PNG files are accepted!");
                    return;
                }
            }
            try
            {
                context.SaveChanges();
                ErrorSuccessNotifier.AddSuccessMessage("User's data is updated!");
                ErrorSuccessNotifier.ShowAfterRedirect = true;
                Response.Redirect("~/Admin/Users", false);
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }
        }
Ejemplo n.º 2
0
        public IQueryable <Skill> GridViewAllSkills_GetData()
        {
            var context = new ApplicationDbContext();

            IOrderedQueryable <Skill> allSkills = null;

            try
            {
                allSkills =
                    (from s in context.Skills
                     select s).OrderBy(s => s.SkillId);
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }

            return(allSkills);
        }
Ejemplo n.º 3
0
        public IQueryable <Category> GridViewUsers_GetCategories()
        {
            try
            {
                var context    = new NoticeboardEntities();
                var categories =
                    from category in context.Categories
                    orderby category.CategoryId
                    select category;

                return(categories);
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }

            return(null);
        }
Ejemplo n.º 4
0
        public IQueryable <DevSocialMe.Models.Group> GridViewAllGroups_GetData()
        {
            var context = new ApplicationDbContext();

            IQueryable <Group> allGroups = null;

            try
            {
                allGroups =
                    (from gr in context.Groups
                     select gr).OrderBy(g => g.GroupId);
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }

            return(allGroups);
        }
Ejemplo n.º 5
0
        public void GridViewUsers_BanUser(string userId)
        {
            using (var context = new NoticeboardEntities())
            {
                try
                {
                    var user = context.AspNetUsers.Find(userId);
                    //user.Banned = true;
                    context.SaveChanges();

                    this.GridViewUsers.PageIndex = 0;
                    ErrorSuccessNotifier.AddInfoMessage("User successfully deleted.");
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex);
                }
            }
        }
Ejemplo n.º 6
0
        protected void OnClick(object sender, EventArgs e)
        {
            var text = this.newSkill.Text;

            if (text.Length == 0)
            {
                ErrorSuccessNotifier.AddErrorMessage("You cannot add a skill without a name!");
                return;
            }

            this.Service.Add(new Skill {
                Name = text
            });
            this.newSkill.Text = "";

            ErrorSuccessNotifier.ShowAfterRedirect = false;
            ErrorSuccessNotifier.AddSuccessMessage("Successfully added a new skill to the db!");
            ErrorSuccessNotifier.ShowAfterRedirect = true;
        }
Ejemplo n.º 7
0
        protected void Delete_Command(object sender, CommandEventArgs e)
        {
            try
            {
                int categoryId = Convert.ToInt32(e.CommandArgument);

                Entities context  = new Entities();
                Category category = context.Categories.Find(categoryId);

                this.TextBox_DeleteCategoryName.Text      = category.CategoryName;
                this.LinkButton_YesDelete.CommandArgument = categoryId.ToString();

                this.pageMode = Mode.Delete;
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }
        }
        // The id parameter name should match the DataKeyNames value set on the control
        public void GridViewQuestions_DeleteItem(int questionId)
        {
            var      context  = new PollSystemEntities();
            Question question = context.Questions.Include("Answers")
                                .FirstOrDefault(q => q.QuestionId == questionId);

            try
            {
                context.Answers.RemoveRange(question.Answers);
                context.Questions.Remove(question);
                context.SaveChanges();
                this.GridViewQuestions.PageIndex = 0;
                ErrorSuccessNotifier.AddInfoMessage("Question deleted.");
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }
        }
Ejemplo n.º 9
0
        protected void Delete_Command(object sender, CommandEventArgs e)
        {
            try
            {
                int bookId = Convert.ToInt32(e.CommandArgument);

                Entities context = new Entities();
                Book     book    = context.Books.Find(bookId);

                this.TextBox_DeleteTitle.Text             = book.Title;
                this.LinkButton_YesDelete.CommandArgument = bookId.ToString();

                this.pageMode = Mode.Delete;
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }
        }
Ejemplo n.º 10
0
        protected void UploadButton_Click(object sender, EventArgs e)
        {
            if (ImageFileUpload.HasFile)
            {
                try
                {
                    if (ImageFileUpload.PostedFile.ContentType == "image/jpeg")
                    {
                        if (ImageFileUpload.PostedFile.ContentLength <= 16 * 1000 * 1024)
                        {
                            string username  = User.Identity.Name;
                            string id        = User.Identity.GetUserId();
                            string directory = Server.MapPath("~/UploadedFiles/ProfileImages/") + id;
                            string filename  = Guid.NewGuid().ToString() + ".jpg";
                            string path      = directory + "/" + filename;
                            string url       = "~/UploadedFiles/ProfileImages/" + id + "/" + filename;

                            if (!Directory.Exists(directory))
                            {
                                Directory.CreateDirectory(directory);
                            }

                            ImageFileUpload.SaveAs(path);
                            UserService.ChangeProfilePhotoUrl(id, url);
                            ErrorSuccessNotifier.AddSuccessMessage("Upload status: File uploaded!");
                        }
                        else
                        {
                            ErrorSuccessNotifier.AddErrorMessage("Upload status: The file has to be less than 16 mb!");
                        }
                    }
                    else
                    {
                        ErrorSuccessNotifier.AddErrorMessage("Upload status: Only JPEG files are accepted!");
                    }
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage("Upload status: The file could not be uploaded. The following error occured: " + ex.Message);
                }
            }
        }
        public void GridViewUsers_UpdateItem(string id)
        {
            var context = new AcademyDbContext();

            Forum.Models.ApplicationUser item = context.Users.Find(id);

            if (item == null)
            {
                ModelState.AddModelError("", String.Format("Item with id {0} was not found", id));
                return;
            }

            var editIndex = this.GridViewUsers.EditIndex;

            bool isLecturer = (this.GridViewUsers.Rows[editIndex].FindControl("CheckBoxIsLecturer") as CheckBox).Checked;

            if (isLecturer)
            {
                var lecturerRole = context.Roles.First(r => r.Name == "Lecturer");
                item.Roles.Clear();
                item.Roles.Add(new UserRole()
                {
                    Role = lecturerRole
                });
            }
            else
            {
                item.Roles.Clear();
            }

            TryUpdateModel(item);

            if (ModelState.IsValid)
            {
                context.SaveChanges();
                ErrorSuccessNotifier.AddSuccessMessage("User edited successfully.");
            }
            else
            {
                ErrorSuccessNotifier.AddErrorMessage("There was an error editing the user. Please try again.");
            }
        }
Ejemplo n.º 12
0
        protected void LinkButtonCreateBook_Command(object sender, CommandEventArgs e)
        {
            var title       = this.TextBoxAddBookTitle.Text;
            var author      = TextBoxAddBookAuthor.Text;
            var isbn        = TextBoxAddBookISBN.Text;
            var webSite     = TextBoxAddBookWebSite.Text;
            var description = TextBoxAddBookDescription.Text;
            var category    = DropDownListCategories.SelectedItem;
            var categoryId  = Convert.ToInt32(category.Value);
            var context     = new ApplicationDbContext();
            var dbCategory  = context.Categories.FirstOrDefault(c => c.CategoryId == categoryId);

            if (dbCategory != null)
            {
                var newBook = new Book()
                {
                    Title       = title,
                    Author      = author,
                    ISBN        = isbn,
                    WebSite     = webSite,
                    Description = description,
                    Category    = dbCategory
                };

                try
                {
                    context.Books.Add(newBook);
                    context.SaveChanges();
                    ErrorSuccessNotifier.AddSuccessMessage(string.Format("Book \"{0}\" created", title));
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex);
                }
            }
            else
            {
                ErrorSuccessNotifier.AddErrorMessage(string.Format("There isn't category {0} in database", category.Text));
            }

            Response.Redirect(Request.Url.AbsoluteUri);
        }
Ejemplo n.º 13
0
        protected void MainContent_LinkButtonConfirmDelete_Click(object sender, EventArgs e)
        {
            try
            {
                int selectedBookId           = int.Parse(this.TextBoxDeleteBookId.Text);
                ApplicationDbContext context = new ApplicationDbContext();
                var selectedBook             = context.Books.Find(selectedBookId);
                context.Books.Remove(selectedBook);
                context.SaveChanges();
                this.GridViewBooks.DataBind();

                this.MainContent_PanelDelete.Visible = false;

                ErrorSuccessNotifier.AddInfoMessage("You have successfully deleted book with title: " + selectedBook.Title);
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }
        }
Ejemplo n.º 14
0
        protected void OnButtonShowDeleteBookPanel_Command(object sender, CommandEventArgs e)
        {
            using (var context = new LibrarySystemEntities())
            {
                int bookId = Convert.ToInt32(e.CommandArgument);
                var book   = context.Books.Find(bookId);

                if (book != null)
                {
                    this.ShowDeleteBookPanel();
                    this.ButtonDeleteBook.CommandArgument = bookId.ToString();

                    this.TextBoxDeleteBookTitle.Text = book.Title;
                }
                else
                {
                    ErrorSuccessNotifier.AddErrorMessage("This book does not exist anymore");
                }
            }
        }
Ejemplo n.º 15
0
        protected void ButtonDeleteGroup_Command(object sender, CommandEventArgs e)
        {
            int groupId = Convert.ToInt32(e.CommandArgument);
            var context = new ApplicationDbContext();

            try
            {
                var selectedGroup = context.Groups.FirstOrDefault(g => g.GroupId == groupId);
                context.Groups.FirstOrDefault(g => g.GroupId == groupId).Messages.Clear();
                context.Groups.Remove(selectedGroup);
                context.SaveChanges();
                ErrorSuccessNotifier.AddSuccessMessage("Group deleted!");
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }

            Response.Redirect(Request.Url.AbsoluteUri);
        }
Ejemplo n.º 16
0
        public IQueryable <Group> GridViewJoinedGroups_GetData()
        {
            var context = new ApplicationDbContext();

            IQueryable <Group> groups = null;

            try
            {
                var currentUser = new ApplicationUser();
                currentUser = context.Users.Include("Groups")
                              .FirstOrDefault(u => u.UserName == User.Identity.Name);
                groups = currentUser.Groups.OrderBy(g => g.GroupId).AsQueryable();
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }

            return(groups);
        }
Ejemplo n.º 17
0
        public IQueryable <Group> GridViewAllGroups_GetData()
        {
            var context = new ApplicationDbContext();

            IQueryable <Group> allGroups = null;

            try
            {
                allGroups =
                    (from gr in context.Groups
                     where gr.Creator != User.Identity.Name && gr.Users.All(u => u.UserName != User.Identity.Name)
                     select gr).OrderBy(g => g.GroupId);
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }

            return(allGroups);
        }
Ejemplo n.º 18
0
        protected void ButtonJoinGroup_Command(object sender, CommandEventArgs e)
        {
            int groupId = Convert.ToInt32(e.CommandArgument);
            var context = new ApplicationDbContext();

            try
            {
                var selectedGroup = context.Groups.FirstOrDefault(g => g.GroupId == groupId);
                var currentUser   = new ApplicationUser();
                currentUser = context.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);
                selectedGroup.Users.Add(currentUser);
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }

            this.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            int categoryId;

            if (!int.TryParse(this.RouteData.Values["id"].ToString(), out categoryId))
            {
                ErrorSuccessNotifier.AddErrorMessage("Missing category id or category id is not a number");
                return;
            }

            Category category = this.data.Categories.GetById(categoryId);

            if (category == null)
            {
                ErrorSuccessNotifier.AddErrorMessage("Worng category id!");
                return;
            }

            this.category = category;
        }
Ejemplo n.º 20
0
        protected void OnBtnVote_Command(object sender, CommandEventArgs e)
        {
            var dbContext = new PollSystemEntities();
            int answerId  = Convert.ToInt32(e.CommandArgument);

            var answer = dbContext.Answers.Find(answerId);

            if (answer != null)
            {
                answer.Votes++;
                dbContext.SaveChanges();

                ErrorSuccessNotifier.AddInfoMessage("You voted for " + answer.Text);
                Response.Redirect("~/VotingResults.aspx?questionId=" + answer.QuestionId);
            }
            else
            {
                ErrorSuccessNotifier.AddErrorMessage("This answer does not exist anymore");
            }
        }
Ejemplo n.º 21
0
        protected void OnButtonCreateCategory_Command(object sender, CommandEventArgs e)
        {
            using (var context = new LibrarySystemEntities())
            {
                try
                {
                    string categoryName = this.TextBoxCreateCategoryName.Text.Trim();
                    if (categoryName == "")
                    {
                        ErrorSuccessNotifier.AddErrorMessage("The category cannot be empty");
                        return;
                    }

                    var existingCategory = context.Categories.FirstOrDefault(
                        cat => cat.Name.ToLower() == categoryName.ToLower());

                    if (existingCategory != null)
                    {
                        this.PanelCreateCategory.Visible = false;
                        ErrorSuccessNotifier.AddErrorMessage("This category already exists");
                        return;
                    }

                    var newCategory = new Category()
                    {
                        Name = categoryName
                    };

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

                    ErrorSuccessNotifier.AddSuccessMessage("Category created");
                    this.GridViewCategories.SetPageIndex(this.GridViewCategories.PageIndex);
                    this.PanelCreateCategory.Visible = false;
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex);
                }
            }
        }
Ejemplo n.º 22
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var searchText = Request.Params["q"];

            this.LiteralSearchTitle.Text = searchText;
            var searchTextToLower = searchText.ToLower();
            var context           = new ApplicationDbContext();

            try
            {
                var books = context.Books
                            .Where(x => x.Title.ToLower().Contains(searchTextToLower) || x.Author.ToLower().Contains(searchTextToLower))
                            .OrderBy(b => b.Title).ThenBy(t => t.Author);
                this.RepeaterSearchResults.DataSource = books.ToList();
                this.RepeaterSearchResults.DataBind();
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }
        }
Ejemplo n.º 23
0
        protected void SaveEdit_Command(object sender, CommandEventArgs e)
        {
            try
            {
                int categoryId = Convert.ToInt32(e.CommandArgument);

                Entities context  = new Entities();
                Category category = context.Categories.Find(categoryId);

                category.CategoryName = this.TextBox_CategoryName.Text != string.Empty ? this.TextBox_CategoryName.Text : null;
                context.SaveChanges();

                this.pageMode = Mode.View;
                ErrorSuccessNotifier.AddSuccessMessage("The category was edited successfully!");
            }
            catch (Exception ex)
            {
                this.pageMode = Mode.Edit;
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }
        }
Ejemplo n.º 24
0
        private bool ValidateISBN(string ISBN)
        {
            var isValid = true;

            if (string.IsNullOrEmpty(ISBN))
            {
                return(true);
            }
            else if (ISBN.Length != 17)
            {
                ErrorSuccessNotifier.AddErrorMessage("ISBN's length is exactly 17 symbols: 978-954-400-773-7");
                isValid = false;
            }
            else if (!Regex.IsMatch(ISBN, @"^[\d-]{17}$"))
            {
                ErrorSuccessNotifier.AddErrorMessage("ISBN consists only of digits and '-': 978-954-400-773-7");
                isValid = false;
            }

            return(isValid);
        }
Ejemplo n.º 25
0
        protected void OnButtonShowEditCategory_Command(object sender, CommandEventArgs e)
        {
            using (var context = new LibrarySystemEntities())
            {
                int categoryId = Convert.ToInt32(e.CommandArgument);
                var category   = context.Categories.Find(categoryId);

                if (category != null)
                {
                    this.PanelCreateCategory.Visible        = false;
                    this.PanelDeleteCategory.Visible        = false;
                    this.PanelEditCategory.Visible          = true;
                    this.TextBoxEditCategoryName.Text       = category.Name;
                    this.ButtonSaveCategory.CommandArgument = categoryId.ToString();
                }
                else
                {
                    ErrorSuccessNotifier.AddErrorMessage("This category does not exist anymore");
                }
            }
        }
Ejemplo n.º 26
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var context = new ApplicationDbContext();
            ICollection <Category> categories = null;

            try
            {
                categories = context.Categories.OrderBy(c => c.Title).ToList();
                if (categories == null || categories.Count == 0)
                {
                    (this.ListViewCategories.FindControl("NoResults") as Literal).Text = "No books in this category.";
                }
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }

            this.ListViewCategories.DataSource = categories;
            this.ListViewCategories.DataBind();
        }
Ejemplo n.º 27
0
        public void ListViewComments_InsertItem()
        {
            try
            {
                var db   = new NoticeboardEntities();
                var user = db.AspNetUsers.FirstOrDefault(u => u.UserName == this.User.Identity.Name);
                var cont = ((TextBox)this.FindControlRecursive(this, "TextBoxComment")).Text;
                if (cont.Length >= 5000)
                {
                    var ex = new Exception("Comment must be less than 5000 symbols!");
                    ErrorSuccessNotifier.AddErrorMessage(ex);
                    return;
                }

                var comment = new Comment
                {
                    Content     = cont,
                    PostId      = this.postId,
                    AspNetUser  = user,
                    CommentDate = DateTime.Now
                };
                db.Comments.Add(comment);
                try
                {
                    db.SaveChanges();
                    ErrorSuccessNotifier.AddSuccessMessage("Comment created successfully");
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex.Message);
                }

                var uPanel = (UpdatePanel)this.FindControlRecursive(this, "UpdatePanelComments");
                uPanel.Update();
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }
        }
        public void EditCategoryLV_InsertItem()
        {
            var newCategory = new Category();

            this.TryUpdateModel(newCategory);

            if (this.ModelState.IsValid == false)
            {
                ErrorSuccessNotifier.AddErrorMessage(CouldNotAddCategoryMsg);
                return;
            }

            if (this.db.Categories.Any(c => c.Name == newCategory.Name))
            {
                ErrorSuccessNotifier.AddErrorMessage(CategoryNameExistsMsg);
                return;
            }

            this.db.Categories.Add(newCategory);
            this.db.SaveChanges();
            ErrorSuccessNotifier.AddSuccessMessage(CategoryCreatedMsg);
        }
Ejemplo n.º 29
0
        protected void ButtonSave_Click(object sender, EventArgs e)
        {
            using (var context = new StichtiteForumEntities())
            {
                var commentId = Convert.ToInt32(this.Request.Params["commentId"]);

                try
                {
                    var comment = context.Comments.Find(commentId);
                    comment.Content = this.TextBoxCommentContent.Text;
                    context.SaveChanges();

                    ErrorSuccessNotifier.AddInfoMessage("Comment successfully edited.");
                    ErrorSuccessNotifier.ShowAfterRedirect = true;
                    this.Response.Redirect("Comments.aspx?postId=" + comment.PostId, false);
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex);
                }
            }
        }
Ejemplo n.º 30
0
        protected void SaveEditedCategory_Command(object sender, CommandEventArgs e)
        {
            //Edit question
            var textBoxEditCategory = this.FormViewEditCategory.FindControl("TextBoxEditCategory") as TextBox;
            var categoryTitle       = textBoxEditCategory.Text;
            var context             = new ApplicationDbContext();
            var categoryId          = Convert.ToInt32(e.CommandArgument);

            try
            {
                var category = context.Categories.FirstOrDefault(c => c.CategoryId == categoryId);
                category.Title = categoryTitle;
                context.SaveChanges();
                ErrorSuccessNotifier.AddSuccessMessage(string.Format("Category \"{0}\" created!", categoryTitle));
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }

            Response.Redirect(Request.Url.AbsoluteUri);
        }