Example #1
0
        public ActionResult KeyPerformanceIndicators(int taskid, int id, FormCollection form)
        {
            List <Model.DTO.Appraisal.KPIComment> lst_update_comments = new List <Model.DTO.Appraisal.KPIComment>();
            List <Model.DTO.Appraisal.KPIComment> lst_delete_comments = new List <Model.DTO.Appraisal.KPIComment>();
            Dictionary <string, TempComment>      dict_comments       = new Dictionary <string, TempComment>();
            string message = string.Empty;

            dict_comments = FormCollectionToDictionary(form);

            foreach (KeyValuePair <string, TempComment> kv in dict_comments)
            {
                if (!string.IsNullOrEmpty(kv.Value.CommentContent.Trim()))
                {
                    Model.DTO.Appraisal.KPIComment obj_comment = new Model.DTO.Appraisal.KPIComment()
                    {
                        AppraisalKPI = new Model.DTO.Appraisal.KPI()
                        {
                            Id = Convert.ToInt32(kv.Key)
                        },
                        Comments  = kv.Value.CommentContent.Trim(),
                        Commentor = new Model.DTO.Core.Employee()
                        {
                            Id = CurrentUser.Id
                        },
                        CommentedTimestamp = DateTime.Now,
                        FormSaveOnly       = true
                    };
                    lst_update_comments.Add(obj_comment);
                }
                else
                {
                    if (!kv.Value.StrCommentID.Contains("NewComment"))
                    {
                        Model.DTO.Appraisal.KPIComment obj_comment = new Model.DTO.Appraisal.KPIComment()
                        {
                            Id = Int32.Parse(kv.Value.StrCommentID)
                        };
                        lst_delete_comments.Add(obj_comment);
                    }
                }
            }

            if (!Lib.Utility.Common.IsNullOrEmptyList(lst_update_comments) || !Lib.Utility.Common.IsNullOrEmptyList(lst_delete_comments))
            {
                if (Model.PMSModel.UpdateAppraisalKPIComment(lst_update_comments, lst_delete_comments, out message))
                {
                    //TempData["AlertMessage"] = "Appraisal information is saved.";
                    return(Redirect(Url.Content("~/Stage2Approval/CoreValues/" + taskid + "/" + id)));
                }
                else
                {
                    ViewData["appraisalid"]  = id;
                    TempData["AlertMessage"] = "Unable to save Appraisal information. Please try again or contact IT Department.";
                    return(View());
                }
            }
            else
            {
                return(Redirect(Url.Content("~/Stage2Approval/CoreValues/" + taskid + "/" + id)));
            }
        }
        public ActionResult KeyPerformanceIndicators(int taskid, int id, FormCollection form)
        {
            List<Model.DTO.Appraisal.KPIComment> lst_update_comments = new List<Model.DTO.Appraisal.KPIComment>();
            List<Model.DTO.Appraisal.KPIComment> lst_delete_comments = new List<Model.DTO.Appraisal.KPIComment>();
            Dictionary<string, TempComment> dict_comments = new Dictionary<string, TempComment>();
            string message = string.Empty;
            dict_comments = FormCollectionToDictionary(form);

            foreach (KeyValuePair<string, TempComment> kv in dict_comments)
            {
                if (!string.IsNullOrEmpty(kv.Value.CommentContent.Trim()))
                {
                    Model.DTO.Appraisal.KPIComment obj_comment = new Model.DTO.Appraisal.KPIComment()
                    {
                        AppraisalKPI = new Model.DTO.Appraisal.KPI() { Id = Convert.ToInt32(kv.Key) },
                        //Comments = kv.Value.CommentContent.Trim(),
                        Comments = Lib.Utility.Common.ReplaceLineBreaksForDatabase(Uri.UnescapeDataString(kv.Value.CommentContent.Trim())),
                        Commentor = new Model.DTO.Core.Employee() { Id = CurrentUser.Id },
                        CommentedTimestamp = DateTime.Now,
                        FormSaveOnly = true
                    };
                    lst_update_comments.Add(obj_comment);
                }
                else
                {
                    if (!kv.Value.StrCommentID.Contains("NewComment"))
                    {
                        Model.DTO.Appraisal.KPIComment obj_comment = new Model.DTO.Appraisal.KPIComment()
                        {
                            Id = Int32.Parse(kv.Value.StrCommentID)
                        };
                        lst_delete_comments.Add(obj_comment);
                    }
                }
            }
            if (!Lib.Utility.Common.IsNullOrEmptyList(lst_update_comments) || !Lib.Utility.Common.IsNullOrEmptyList(lst_delete_comments))
            {
                if (Model.PMSModel.UpdateAppraisalKPIComment(lst_update_comments, lst_delete_comments, out message))
                {
                    //TempData["AlertMessage"] = "Appraisal information is saved.";
                    return Redirect(Url.Content("~/Stage2Approval/CoreValues/" + taskid + "/" + id));
                }
                else
                {
                    ViewData["appraisalid"] = id;
                    TempData["AlertMessage"] = Resources.Resource.MSG_NEXT_FAIL;
                    return View();
                }
            }
            else
            {
                return Redirect(Url.Content("~/Stage2Approval/CoreValues/" + taskid + "/" + id));
            }
        }
        public static List<PMS.Model.DTO.Appraisal.KPIComment> GetKPICommentItemsToSave(string[] result, int commentorId, DateTime commentTimestamp, out List<PMS.Model.DTO.Appraisal.KPIComment> lst_comments, out List<PMS.Model.DTO.Appraisal.KPIComment> lst_delete_comments)
        {
            lst_comments = null;
            lst_delete_comments = null;
            if (!Lib.Utility.Common.IsNullOrEmptyList(result))
            {
                lst_comments = new List<Model.DTO.Appraisal.KPIComment>();
                lst_delete_comments = new List<Model.DTO.Appraisal.KPIComment>();
                foreach (string str_string in result)
                {
                    string[] kparray = str_string.Replace("\"", "").Split(',');
                    //string tmp_comment = kparray[1].Split(':')[1].Replace("}]", "").Trim().TrimEnd('\r', '\n').Replace("\\n", Environment.NewLine).Trim();
                    string tmp_comment = Lib.Utility.Common.ReplaceLineBreaksForDatabase(kparray[1].Split(':')[1].Replace("}]", "").Trim());
                    //string tmp_comment_id = Lib.Utility.Common.ReplaceLineBreaksForDatabase(kparray[2].Split(':')[1].Replace("}]", "").Trim());
                    string tmp_comment_id = kparray[2].Split(':')[1].Trim();
                    if (!string.IsNullOrEmpty(tmp_comment))
                    {
                        PMS.Model.DTO.Appraisal.KPIComment obj_comment = new Model.DTO.Appraisal.KPIComment()
                        {
                            AppraisalKPI = new Model.DTO.Appraisal.KPI() { Id = Convert.ToInt32(kparray[0].Split(':')[1]) },
                            Comments = tmp_comment,
                            FormSaveOnly = true,
                            Commentor = new Model.DTO.Core.Employee() { Id = commentorId },
                            CommentedTimestamp = commentTimestamp
                        };
                        lst_comments.Add(obj_comment);
                    }
                    else
                    {
                        if (!tmp_comment_id.Contains("NewComment"))
                        {
                            PMS.Model.DTO.Appraisal.KPIComment obj_comment = new Model.DTO.Appraisal.KPIComment()
                            {
                                Id = Int32.Parse(tmp_comment_id)
                            };
                            lst_delete_comments.Add(obj_comment);
                        }
                    }
                }
            }

            return lst_comments;
        }