//private PregnancyDetails GetChecklistPregnancy(string dfn, string pregIen)
        //{
        //    PregnancyDetails returnVal = null;

        //    // *** First try the pregnancy ien passed in ***
        //    if (!string.IsNullOrWhiteSpace(pregIen))
        //    {
        //        PregnancyListResult pregResult = this.DashboardRepository.Pregnancy.GetPregnancies(dfn, pregIen);

        //        if (pregResult.Success)
        //            if (pregResult.Pregnancies != null)
        //                if (pregResult.Pregnancies.Count > 0)
        //                    returnVal = pregResult.Pregnancies[0];
        //    }

        //    // *** Then try to get the current/most-recent ***
        //    if (returnVal == null)
        //    {
        //        PregnancyResult pregResult = this.DashboardRepository.Pregnancy.GetCurrentOrMostRecentPregnancy(dfn);

        //        if (pregResult.Success)
        //            returnVal = pregResult.Pregnancy;
        //    }

        //    return returnVal;
        //}

        private ActionResult ClearAllItems()
        {
            ChecklistItemsResult getResult = this.DashboardRepository.Checklist.GetItems("", 1, 1000);

            if (getResult.Success)
            {
                BrokerOperationResult delResult = null;

                foreach (ChecklistItem item in getResult.Items)
                {
                    delResult = this.DashboardRepository.Checklist.DeleteItem(item.Ien);

                    if (!delResult.Success)
                    {
                        this.Error(delResult.Message);
                        break;
                    }
                }

                if (delResult != null)
                {
                    if (delResult.Success)
                    {
                        this.Information("Deleted all");
                    }
                }
            }

            return(RedirectToAction("Index", new { page = "1" }));
        }
        public ActionResult AddEdit(string ien)
        {
            ChecklistItemAddEdit model = new ChecklistItemAddEdit();

            if (!string.IsNullOrWhiteSpace(ien))
            {
                ChecklistItemsResult result = this.DashboardRepository.Checklist.GetItems(ien, 1, 1000);

                if (!result.Success)
                {
                    this.Error(result.Message);
                }
                else
                if (result.Items != null)
                {
                    if (result.Items.Count > 0)
                    {
                        model.Item = result.Items[0];

                        //if (model.Item.ItemType == DsioChecklistItemType.EducationItem)
                        //    model.EducationItemLink = model.Item.Link;

                        model.GetDueVals();
                    }
                }
            }

            model.EducationItemSelection = this.DashboardRepository.Education.GetItemSelection();

            return(View(model));
        }
        public ActionResult Index(string page)
        {
            // TODO: What kind of sorting/paging to allow
            // TODO: Can pass duedays to vista and always sort on that?
            // TODO: Will need better sort to handle paging in vista or can handle paging/sorting in repository (less efficient)

            ChecklistIndex model = new ChecklistIndex();

            int pageVal = this.GetPage(page);

            //ChecklistItemsResult result = this.DashboardRepository.Checklist.GetItems("", pageVal, ItemsPerPage);
            ChecklistItemsResult result = this.DashboardRepository.Checklist.GetItems("", 1, 1000);

            if (!result.Success)
            {
                this.Error(result.Message);
            }
            else
            {
                model.Items = result.Items;

                model.Items.Sort(delegate(ChecklistItem x, ChecklistItem y)
                {
                    int returnVal = 0;

                    returnVal = x.DueDays.CompareTo(y.DueDays);

                    if (returnVal == 0)
                    {
                        returnVal = x.ItemType.ToString().CompareTo(y.ItemType.ToString());
                    }

                    if (returnVal == 0)
                    {
                        returnVal = x.Category.CompareTo(y.Category);
                    }

                    if (returnVal == 0)
                    {
                        returnVal = x.Description.CompareTo(y.Description);
                    }

                    return(returnVal);
                });

                //model.Paging.SetPagingData(ItemsPerPage, pageVal, result.TotalResults);
                model.Paging.SetPagingData(1000, pageVal, result.TotalResults);
                model.Paging.BaseUrl = Url.Action("Index", new { @page = "" });
            }

            return(View(model));
        }