public ActionResult GetWellCompletionsByQueryDateDate(GenericSearch search)
        {
            try
            {
                if (search.Year < 1)
                {
                    ViewBag.ErrorCode    = -1;
                    ViewBag.ErrorMessage = "Please provide a valid Report Year";
                    return(View("Report", new WellCompletionViewModel
                    {
                        WellCompletionTypes = new List <WellCompletionType>(),
                        Wells = new List <Well>(),
                        Equipments = new List <Equipment>(),
                        WellCompletions = new List <WellCompletion>(),
                        WellCompletionReportObjects = new List <WellCompletionReportObject>(),
                        MonthList = GetMonths(),
                        YearList = GetYears()
                    }));
                }

                var txd = GetWellCompletionStaticReports(ItemsPerPage, PageNumber, search);
                if (!txd.Any())
                {
                    ViewBag.ErrorMessage = "No record found";
                    ViewBag.ErrorCode    = -1;

                    if (search.Month < 1)
                    {
                        ViewBag.SearchPeriod = search.Year;
                    }
                    if (search.Month > 0)
                    {
                        ViewBag.SearchPeriod = Enum.GetName(typeof(MonthList), search.Month) + "/" + search.Year;
                    }

                    return(View("Report", new WellCompletionViewModel
                    {
                        WellCompletionTypes = new List <WellCompletionType>(),
                        Wells = new List <Well>(),
                        Equipments = new List <Equipment>(),
                        WellCompletions = new List <WellCompletion>(),
                        WellCompletionReportObjects = new List <WellCompletionReportObject>(),
                        MonthList = GetMonths(),
                        YearList = GetYears()
                    }));
                }
                ViewBag.SearchPeriod = Enum.GetName(typeof(MonthList), search.Month) + "/" + search.Year;
                var txx = new WellCompletionViewModel
                {
                    WellCompletionTypes = new List <WellCompletionType>(),
                    Wells                       = new List <Well>(),
                    Equipments                  = new List <Equipment>(),
                    WellCompletions             = new List <WellCompletion>(),
                    WellCompletionReportObjects = txd,
                    MonthList                   = GetMonths(),
                    YearList                    = GetYears()
                };
                Session["_wellCompRepoGenSearch"] = search;
                Session["_wellCompRepoPage"]      = 1;
                return(View("Report", txx));
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = "No record found";
                ViewBag.ErrorCode    = -1;
                ViewBag.SearchPeriod = Enum.GetName(typeof(MonthList), search.Month) + "/" + search.Year;
                return(View("Report", new WellCompletionViewModel
                {
                    WellCompletionTypes = new List <WellCompletionType>(),
                    Wells = new List <Well>(),
                    Equipments = new List <Equipment>(),
                    WellCompletions = new List <WellCompletion>(),
                    WellCompletionReportObjects = new List <WellCompletionReportObject>(),
                    MonthList = GetMonths(),
                    YearList = GetYears()
                }));
            }
        }
        public ActionResult WellCompletions()
        {
            try
            {
                var wellCompletionTypeList = GetWellCompletionTypes();

                if (!wellCompletionTypeList.Any())
                {
                    return(RedirectToAction("WellCompletionTypes", "WellCompletionType"));
                }

                var equipmentList = GetEquipments();

                if (!equipmentList.Any())
                {
                    return(RedirectToAction("Equipments", "Equipment"));
                }

                var wells = GetWells();
                if (!wells.Any())
                {
                    return(RedirectToAction("Wells", "Well"));
                }

                int dataCount;
                var wellCompletions = GetWellComletions(ItemsPerPage, PageNumber, out dataCount);

                if (!wellCompletions.Any())
                {
                    ViewBag.Edit  = 1;
                    ViewBag.Title = "Well Completion SetUp";
                    return(View(new WellCompletionViewModel
                    {
                        WellCompletionTypes = wellCompletionTypeList,
                        WellObjects = wells,
                        Equipments = equipmentList,
                        WellCompletions = new List <WellCompletion>(),
                        MonthList = GetMonths(),
                        YearList = GetYears()
                    }));
                }


                var txx = new WellCompletionViewModel
                {
                    WellCompletionTypes = wellCompletionTypeList,
                    WellObjects         = wells,
                    Equipments          = equipmentList,
                    WellCompletions     = wellCompletions,
                    MonthList           = GetMonths(),
                    YearList            = GetYears()
                };
                Session["_wellCompPage"] = 1;
                ViewBag.Title            = "Manage Well Completions";
                return(View(txx));
            }
            catch (Exception ex)
            {
                ViewBag.ErrorCode    = -1;
                ViewBag.ErrorMessage =
                    "An unknown error was encountered. Well Copletion list could not be retrieved.";
                return(View(new WellCompletionViewModel
                {
                    WellCompletionTypes = GetWellCompletionTypes(),
                    WellObjects = GetWells(),
                    Equipments = GetEquipments(), WellCompletions = new List <WellCompletion>(),
                    MonthList = GetMonths(),
                    YearList = GetYears()
                }));
            }
        }