public object Get()
        {
            IList <EmailArticle> lstEmailArticle = new List <EmailArticle>();

            DataTable dtEmailArticle = DataBase.DBService.ExecuteCommand(SELECT_ALL);

            ///DataTable dtEmailArticle = getDummyArticleData();
            foreach (DataRow dr in dtEmailArticle.Rows)
            {
                EmailArticle emailArticle = new EmailArticle();
                emailArticle.ID                = dr.Field <int>("ID");
                emailArticle.GroupId           = dr.Field <int>("GroupId");
                emailArticle.GroupName         = dr.Field <string>("GroupName");
                emailArticle.Title             = dr.Field <string>("Title");
                emailArticle.ContentFilePath   = dr.Field <string>("ContentPath");
                emailArticle.Description       = dr.Field <string>("Description");
                emailArticle.CreatedOn         = dr.Field <DateTime>("CreatedOn");
                emailArticle.CreatedBy         = dr.Field <int>("CreatedBy");
                emailArticle.UpdatedOn         = dr.Field <DateTime>("UpdatedOn");
                emailArticle.UpdatedBy         = dr.Field <int>("UpdatedBy");
                emailArticle.UpdatedByUserName = dr.Field <string>("UpdatedByUserName");

                lstEmailArticle.Add(emailArticle);
            }
            return(lstEmailArticle);
        }
        private void updateEmailArticleInfo()
        {
            try
            {
                FinancialPlanner.Common.JSONSerialization jsonSerialization = new FinancialPlanner.Common.JSONSerialization();
                string apiurl = string.Empty;

                EmailArticle article = new EmailArticle()
                {
                    GroupName         = cmbGroup.Text,
                    Title             = txtArticleTitle.Text,
                    ContentFilePath   = txtArticleContentPath.Text,
                    Description       = txtArticleDesc.Text,
                    CreatedOn         = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")),
                    CreatedBy         = Program.CurrentUser.Id,
                    UpdatedOn         = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")),
                    UpdatedBy         = Program.CurrentUser.Id,
                    UpdatedByUserName = Program.CurrentUser.UserName,
                    MachineName       = System.Environment.MachineName
                };

                if (txtArticleTitle.Tag == null)
                {
                    apiurl = Program.WebServiceUrl + "/" + ADD_EMAILARTICLE_API;
                }
                else
                {
                    apiurl     = Program.WebServiceUrl + "/" + UPDATE_EMAILARTICLE_API;
                    article.ID = int.Parse(txtArticleTitle.Tag.ToString());
                }

                string DATA = jsonSerialization.SerializeToString <EmailArticle>(article);

                WebClient client = new WebClient();
                client.Headers["Content-type"] = "application/json";
                client.Encoding = Encoding.UTF8;
                string json = client.UploadString(apiurl, "POST", DATA);

                if (json != null)
                {
                    var resultObject = jsonSerialization.DeserializeFromString <Result>(json);
                    if (resultObject.IsSuccess)
                    {
                        MessageBox.Show("Record save successfully.", "Record Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        loadArticleFormWithData();
                        btnSaveArticleInfo.Enabled = false;
                        displayArtilceTreeView(_dtArticle);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to save record.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void Update(EmailArticle emailArticle)
        {
            updateGroupDetail(emailArticle);
            DataBase.DBService.ExecuteCommand(
                string.Format(UPDATE_EMAILARTICLE_QUERY, emailArticle.GroupId,
                              emailArticle.Title,
                              emailArticle.ContentFilePath,
                              emailArticle.Description,
                              emailArticle.UpdatedOn.ToString("yyyy-MM-dd hh:mm:ss"),
                              emailArticle.UpdatedBy, emailArticle.ID));

            Activity.ActivitiesService.Add(ActivityType.UpdateEmailArticle, EntryStatus.Success,
                                           Source.Client, emailArticle.UpdatedByUserName, emailArticle.Title, emailArticle.MachineName);
        }
        private void updateGroupDetail(EmailArticle emailArticle)
        {
            string groupId = DataBase.DBService.ExecuteCommandScalar(string.Format(SELECT_ID_BY_NAME, emailArticle.GroupName));

            if (!string.IsNullOrEmpty(groupId))
            {
                emailArticle.GroupId = int.Parse(groupId);
            }
            else
            {
                DataBase.DBService.ExecuteCommand(
                    string.Format(INSERT_EMAILGROUP_QUERY, emailArticle.GroupName));
                groupId = DataBase.DBService.ExecuteCommandScalar(string.Format(SELECT_ID_BY_NAME, emailArticle.GroupName));
                emailArticle.GroupId = int.Parse(groupId);
            }
        }
        public void Delete(EmailArticle emailArticle)
        {
            DataBase.DBService.ExecuteCommand(
                string.Format(DELETE_EMAILARTICLE_QUERY, emailArticle.ID));

            string count = DataBase.DBService.ExecuteCommandScalar(
                string.Format(SELECT_COUNT_BY_GROUPID, emailArticle.GroupId));

            if (int.Parse(count) == 0)
            {
                DataBase.DBService.ExecuteCommand(
                    string.Format(DELETE_EMAILGROUP, emailArticle.GroupId));
            }

            Activity.ActivitiesService.Add(ActivityType.DeleteEmailArticle, EntryStatus.Success,
                                           Source.Client, emailArticle.UpdatedByUserName, emailArticle.Title, emailArticle.MachineName);
        }
        public Result Delete(EmailArticle emailArticle)
        {
            var result = new Result();

            try
            {
                EmailArticleService emailArticleService = new EmailArticleService();
                emailArticleService.Delete(emailArticle);
                result.IsSuccess = true;
            }
            catch (Exception ex)
            {
                result.IsSuccess     = false;
                result.ExceptionInfo = ex;
            }
            return(result);
        }
        private EmailArticle convertSelectedRowDataToEmailArticle()
        {
            EmailArticle article = new EmailArticle();

            if (trvArticle.SelectedNode.Tag != null)
            {
                DataRow dr = getSelectedDataRow(int.Parse(trvArticle.SelectedNode.Tag.ToString()));
                if (dr != null)
                {
                    article.ID                = int.Parse(dr.Field <string>("ID"));
                    article.GroupId           = int.Parse(dr.Field <string>("GroupID"));
                    article.GroupName         = dr.Field <string>("GroupName");
                    article.Title             = dr.Field <string>("Title");
                    article.ContentFilePath   = dr.Field <string>("ContentFilePath");
                    article.Description       = dr.Field <string>("Description");
                    article.UpdatedByUserName = Program.CurrentUser.UserName;
                    article.MachineName       = System.Environment.MachineName;
                }
            }
            return(article);
        }
        private void removeRecord(TreeNode selectedNode)
        {
            try
            {
                FinancialPlanner.Common.JSONSerialization jsonSerialization = new FinancialPlanner.Common.JSONSerialization();
                string apiurl = Program.WebServiceUrl + "/" + DETELE_EMAILARATICLE_API;

                EmailArticle article = convertSelectedRowDataToEmailArticle();

                string DATA = jsonSerialization.SerializeToString <EmailArticle>(article);

                WebClient client = new WebClient();
                client.Headers["Content-type"] = "application/json";
                client.Encoding = Encoding.UTF8;
                string json = client.UploadString(apiurl, "POST", DATA);

                if (json != null)
                {
                    var resultObject = jsonSerialization.DeserializeFromString <Result>(json);
                    if (resultObject.IsSuccess)
                    {
                        MessageBox.Show("Record deleted successfully.", "Delete", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        trvArticle.SelectedNode.Remove();
                        DataRow[] dr = _dtArticle.Select("ID =" + article.ID);
                        if (dr.Count() > 0)
                        {
                            dr[0].Delete();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to delete record.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }