protected void btnActiveOrDeactive_Command(object sender, CommandEventArgs e)
        {
            try
            {
                string id = Convert.ToString(e.CommandArgument);
                if (!string.IsNullOrEmpty(id))
                {
                    BlogPostCategoryBLL blogPostCategoryBLL = new BlogPostCategoryBLL();
                    DataTable           dt = blogPostCategoryBLL.GetById(Convert.ToInt32(QuaintSecurityManager.Decrypt(id)));
                    if (dt != null)
                    {
                        if (dt.Rows.Count > 0)
                        {
                            string             actionStatus     = "Updated";
                            BlogPostCategories blogPostCategory = new BlogPostCategories();
                            blogPostCategory.BlogPostCategoryId   = Convert.ToInt32(Convert.ToString(dt.Rows[0]["BlogPostCategoryId"]));
                            blogPostCategory.BlogPostCategoryCode = Convert.ToString(dt.Rows[0]["BlogPostCategoryCode"]);
                            blogPostCategory.Name        = Convert.ToString(dt.Rows[0]["Name"]);
                            blogPostCategory.Slag        = Convert.ToString(dt.Rows[0]["Slag"]);
                            blogPostCategory.Description = Convert.ToString(dt.Rows[0]["Description"]);
                            blogPostCategory.IsActive    = Convert.ToBoolean(Convert.ToString(dt.Rows[0]["IsActive"]));
                            blogPostCategory.CreatedDate = (string.IsNullOrEmpty(Convert.ToString(dt.Rows[0]["CreatedDate"]))) ? (DateTime?)null : Convert.ToDateTime(Convert.ToString(dt.Rows[0]["CreatedDate"]));
                            blogPostCategory.CreatedBy   = Convert.ToString(dt.Rows[0]["CreatedBy"]);
                            blogPostCategory.CreatedFrom = Convert.ToString(dt.Rows[0]["CreatedFrom"]);

                            blogPostCategory.UpdatedDate = DateTime.Now;
                            blogPostCategory.UpdatedBy   = UserInfo;
                            blogPostCategory.UpdatedFrom = StationInfo;

                            if (blogPostCategory.IsActive)
                            {
                                blogPostCategory.IsActive = false;
                                actionStatus = "Deactivated";
                            }
                            else
                            {
                                blogPostCategory.IsActive = true;
                                actionStatus = "Activated";
                            }

                            if (blogPostCategoryBLL.Update(blogPostCategory))
                            {
                                Alert(AlertType.Success, actionStatus + " successfully.");
                                LoadList();
                            }
                            else
                            {
                                Alert(AlertType.Error, "Failed to update.");
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                Alert(AlertType.Error, "Failed to process.");
            }
        }
コード例 #2
0
        private void SaveAndUpdate()
        {
            try
            {
                if (string.IsNullOrEmpty(txtName.Text))
                {
                    Alert(AlertType.Warning, "Enter blog post category name.");
                    txtName.Focus();
                }
                else
                {
                    QuaintLibraryManager lib = new QuaintLibraryManager();
                    string name        = Convert.ToString(txtName.Text);
                    string slug        = lib.ConvertToSlug(name);
                    string description = Convert.ToString(txtDescription.Text);

                    BlogPostCategoryBLL blogPostCategoryBLL = new BlogPostCategoryBLL();
                    if (this.ModelId > 0)
                    {
                        DataTable          dt = blogPostCategoryBLL.GetById(this.ModelId);
                        BlogPostCategories blogPostCategory = new BlogPostCategories();
                        blogPostCategory.BlogPostCategoryId   = Convert.ToInt32(Convert.ToString(dt.Rows[0]["BlogPostCategoryId"]));
                        blogPostCategory.BlogPostCategoryCode = Convert.ToString(dt.Rows[0]["BlogPostCategoryCode"]);
                        blogPostCategory.Name        = Convert.ToString(dt.Rows[0]["Name"]);
                        blogPostCategory.Slag        = Convert.ToString(dt.Rows[0]["Slag"]);
                        blogPostCategory.Description = Convert.ToString(dt.Rows[0]["Description"]);
                        blogPostCategory.IsActive    = Convert.ToBoolean(Convert.ToString(dt.Rows[0]["IsActive"]));
                        blogPostCategory.CreatedDate = (string.IsNullOrEmpty(Convert.ToString(dt.Rows[0]["CreatedDate"]))) ? (DateTime?)null : Convert.ToDateTime(Convert.ToString(dt.Rows[0]["CreatedDate"]));
                        blogPostCategory.CreatedBy   = Convert.ToString(dt.Rows[0]["CreatedBy"]);
                        blogPostCategory.CreatedFrom = Convert.ToString(dt.Rows[0]["CreatedFrom"]);

                        blogPostCategory.Name        = name.Trim();
                        blogPostCategory.Slag        = slug;
                        blogPostCategory.Description = description;

                        blogPostCategory.UpdatedDate = DateTime.Now;
                        blogPostCategory.UpdatedBy   = this.UserInfo;
                        blogPostCategory.UpdatedFrom = this.StationInfo;

                        if (blogPostCategoryBLL.Update(blogPostCategory))
                        {
                            this.MultiEntryDisallow = true;
                            Alert(AlertType.Success, "Updated successfully.");
                            ClearFields();
                        }
                        else
                        {
                            Alert(AlertType.Error, "Failed to update.");
                        }
                    }
                    else
                    {
                        BlogPostCategories blogPostCategory = new BlogPostCategories();
                        blogPostCategory.BlogPostCategoryCode = this.ModelCode;
                        blogPostCategory.Name        = name.Trim();
                        blogPostCategory.Slag        = slug;
                        blogPostCategory.Description = description;
                        blogPostCategory.IsActive    = true;
                        blogPostCategory.CreatedDate = DateTime.Now;
                        blogPostCategory.CreatedBy   = this.UserInfo;
                        blogPostCategory.CreatedFrom = this.StationInfo;

                        if (blogPostCategoryBLL.Save(blogPostCategory))
                        {
                            Alert(AlertType.Success, "Saved successfully.");
                            ClearFields();
                            GenerateCode();
                        }
                        else
                        {
                            Alert(AlertType.Error, "Failed to save.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Alert(AlertType.Error, ex.Message.ToString());
            }
        }