private void Edit(int id)
 {
     try
     {
         BlogPostBLL blogPostBLL = new BlogPostBLL();
         DataTable   dt          = blogPostBLL.GetById(id);
         if (dt != null)
         {
             if (dt.Rows.Count > 0)
             {
                 this.ModelId                      = Convert.ToInt32(Convert.ToString(dt.Rows[0]["BlogPostId"]));
                 this.ModelCode                    = Convert.ToString(dt.Rows[0]["BlogPostCode"]);
                 txtTitle.Text                     = Convert.ToString(dt.Rows[0]["Title"]);
                 this.ModelSlag                    = Convert.ToString(dt.Rows[0]["Slag"]);
                 txtDescription.Text               = Convert.ToString(dt.Rows[0]["Description"]);
                 txtPublishedDate.Text             = Convert.ToDateTime(Convert.ToString(dt.Rows[0]["PublishedDate"])).ToString("MM/dd/yyyy");
                 this.ModelAttachment              = (string.IsNullOrEmpty(Convert.ToString(dt.Rows[0]["Attachment"]))) ? string.Empty : Convert.ToString(dt.Rows[0]["Attachment"]);
                 ddlBlogPostCategory.SelectedValue = Convert.ToString(dt.Rows[0]["BlogPostCategoryId"]);
             }
         }
     }
     catch (Exception)
     {
         Alert(AlertType.Error, "Failed to edit.");
     }
 }
Beispiel #2
0
        protected void btnActiveOrDeactive_Command(object sender, CommandEventArgs e)
        {
            try
            {
                string id = Convert.ToString(e.CommandArgument);
                if (!string.IsNullOrEmpty(id))
                {
                    BlogPostBLL blogPostBLL = new BlogPostBLL();
                    DataTable   dt          = blogPostBLL.GetById(Convert.ToInt32(QuaintSecurityManager.Decrypt(id)));
                    if (dt != null)
                    {
                        if (dt.Rows.Count > 0)
                        {
                            string    actionStatus = "Updated";
                            BlogPosts blogPost     = new BlogPosts();
                            blogPost.BlogPostId         = Convert.ToInt32(Convert.ToString(dt.Rows[0]["BlogPostId"]));
                            blogPost.BlogPostCode       = Convert.ToString(dt.Rows[0]["BlogPostCode"]);
                            blogPost.Title              = Convert.ToString(dt.Rows[0]["Title"]);
                            blogPost.Slag               = Convert.ToString(dt.Rows[0]["Slag"]);
                            blogPost.Description        = Convert.ToString(dt.Rows[0]["Description"]);
                            blogPost.PublishedDate      = Convert.ToDateTime(Convert.ToString(dt.Rows[0]["PublishedDate"]));
                            blogPost.Attachment         = Convert.ToString(dt.Rows[0]["Attachment"]);
                            blogPost.IsActive           = Convert.ToBoolean(Convert.ToString(dt.Rows[0]["IsActive"]));
                            blogPost.BlogPostCategoryId = Convert.ToInt32(Convert.ToString(dt.Rows[0]["BlogPostCategoryId"]));
                            blogPost.CreatedDate        = (string.IsNullOrEmpty(Convert.ToString(dt.Rows[0]["CreatedDate"]))) ? (DateTime?)null : Convert.ToDateTime(Convert.ToString(dt.Rows[0]["CreatedDate"]));
                            blogPost.CreatedBy          = Convert.ToString(dt.Rows[0]["CreatedBy"]);
                            blogPost.CreatedFrom        = Convert.ToString(dt.Rows[0]["CreatedFrom"]);

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

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

                            if (blogPostBLL.Update(blogPost))
                            {
                                Alert(AlertType.Success, actionStatus + " successfully.");
                                LoadList();
                            }
                            else
                            {
                                Alert(AlertType.Error, "Failed to update.");
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                Alert(AlertType.Error, "Failed to process.");
            }
        }
        private void SaveAndUpdate()
        {
            try
            {
                if (string.IsNullOrEmpty(txtTitle.Text))
                {
                    Alert(AlertType.Warning, "Enter title.");
                    txtTitle.Focus();
                }
                else if (ddlBlogPostCategory.SelectedIndex < 1)
                {
                    Alert(AlertType.Warning, "Select blog post category.");
                    ddlBlogPostCategory.Focus();
                }
                else if (string.IsNullOrEmpty(txtPublishedDate.Text))
                {
                    Alert(AlertType.Warning, "Select published date.");
                    txtPublishedDate.Focus();
                }
                else
                {
                    QuaintLibraryManager lib    = new QuaintLibraryManager();
                    string   title              = Convert.ToString(txtTitle.Text);
                    string   slag               = lib.ConvertToSlug(title);
                    int      blogPostCategoryId = Convert.ToInt32(ddlBlogPostCategory.SelectedValue);
                    DateTime publishedDate      = Convert.ToDateTime(txtPublishedDate.Text);
                    string   description        = Convert.ToString(txtDescription.Text);
                    string   attachment         = string.Empty;
                    if (fuAttachment.HasFile)
                    {
                        attachment = UploadAttachment();
                    }
                    else
                    {
                        attachment = this.ModelAttachment;
                    }

                    BlogPostBLL blogPostBLL = new BlogPostBLL();
                    if (this.ModelId > 0)
                    {
                        DataTable dt       = blogPostBLL.GetById(this.ModelId);
                        BlogPosts blogPost = new BlogPosts();
                        blogPost.BlogPostId         = Convert.ToInt32(Convert.ToString(dt.Rows[0]["BlogPostId"]));
                        blogPost.BlogPostCode       = Convert.ToString(dt.Rows[0]["BlogPostCode"]);
                        blogPost.Title              = Convert.ToString(dt.Rows[0]["Title"]);
                        blogPost.Slag               = Convert.ToString(dt.Rows[0]["Slag"]);
                        blogPost.Description        = Convert.ToString(dt.Rows[0]["Description"]);
                        blogPost.PublishedDate      = Convert.ToDateTime(Convert.ToString(dt.Rows[0]["PublishedDate"]));
                        blogPost.Attachment         = Convert.ToString(dt.Rows[0]["Attachment"]);
                        blogPost.IsActive           = Convert.ToBoolean(Convert.ToString(dt.Rows[0]["IsActive"]));
                        blogPost.BlogPostCategoryId = Convert.ToInt32(Convert.ToString(dt.Rows[0]["BlogPostCategoryId"]));
                        blogPost.CreatedDate        = (string.IsNullOrEmpty(Convert.ToString(dt.Rows[0]["CreatedDate"]))) ? (DateTime?)null : Convert.ToDateTime(Convert.ToString(dt.Rows[0]["CreatedDate"]));
                        blogPost.CreatedBy          = Convert.ToString(dt.Rows[0]["CreatedBy"]);
                        blogPost.CreatedFrom        = Convert.ToString(dt.Rows[0]["CreatedFrom"]);

                        blogPost.Title              = title.Trim();
                        blogPost.Slag               = slag;
                        blogPost.Description        = description;
                        blogPost.PublishedDate      = publishedDate;
                        blogPost.Attachment         = attachment;
                        blogPost.BlogPostCategoryId = blogPostCategoryId;

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

                        if (blogPostBLL.Update(blogPost))
                        {
                            this.MultiEntryDisallow = true;
                            Alert(AlertType.Success, "Updated successfully.");
                            ClearFields();
                        }
                        else
                        {
                            Alert(AlertType.Error, "Failed to update.");
                        }
                    }
                    else
                    {
                        BlogPosts blogPost = new BlogPosts();
                        blogPost.BlogPostCode       = this.ModelCode;
                        blogPost.Title              = title;
                        blogPost.Slag               = slag;
                        blogPost.BlogPostCategoryId = blogPostCategoryId;
                        blogPost.Attachment         = attachment;
                        blogPost.PublishedDate      = publishedDate;
                        blogPost.Description        = description;
                        blogPost.IsActive           = true;
                        blogPost.CreatedDate        = DateTime.Now;
                        blogPost.CreatedBy          = this.UserInfo;
                        blogPost.CreatedFrom        = this.StationInfo;

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