public ActionResult GetWorkoversByQueryDate(GenericSearch search)
        {
            try
            {
                if (search.Year < 1)
                {
                    ViewBag.ErrorCode    = -1;
                    ViewBag.ErrorMessage = "Please provide a valid Report Year";
                    return(View("Report", new WellWorkoverViewModel
                    {
                        WellWorkOverReasons = new List <WellWorkOverReason>(),
                        Equipments = new List <Equipment>(),
                        Wells = new List <Well>(),
                        WellWorkOvers = new List <WellWorkover>(),
                        WellWorkoverReportObjects = new List <WellWorkoverReportObject>(),
                        YearList = GetYears(),
                        MonthList = GetMonths()
                    }));
                }

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

                else
                {
                    ViewBag.SearchPeriod = search.Year;
                }

                var txd = GetWorkoverObjects(PageNumber, ItemsPerPage, search);
                if (!txd.Any())
                {
                    return(View("Report", new WellWorkoverViewModel
                    {
                        WellWorkOverReasons = new List <WellWorkOverReason>(),
                        Equipments = new List <Equipment>(),
                        Wells = new List <Well>(),
                        WellWorkOvers = new List <WellWorkover>(),
                        WellWorkoverReportObjects = new List <WellWorkoverReportObject>(),
                        YearList = GetYears(),
                        MonthList = GetMonths()
                    }));
                }

                var txx = new WellWorkoverViewModel
                {
                    WellWorkOverReasons = new List <WellWorkOverReason>(),
                    Equipments          = new List <Equipment>(),
                    Wells                     = new List <Well>(),
                    WellWorkOvers             = new List <WellWorkover>(),
                    WellWorkoverReportObjects = txd,
                    YearList                  = GetYears(),
                    MonthList                 = GetMonths()
                };
                Session["_workRepoPage"]          = 1;
                Session["_workoverRepoGenSearch"] = search;
                return(View("Report", txx));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                ViewBag.ErrorMessage = "No record found";
                ViewBag.ErrorCode    = -1;
                return(View("Report", new WellWorkoverViewModel
                {
                    WellWorkOverReasons = new List <WellWorkOverReason>(),
                    Equipments = new List <Equipment>(),
                    Wells = new List <Well>(),
                    WellWorkOvers = new List <WellWorkover>(),
                    YearList = GetYears(),
                    MonthList = GetMonths()
                }));
            }
        }
        public ViewResult WellWorkovers(string returnMsg = null, int returnCode = 0)
        {
            try
            {
                var wellWorkOverReasonList = GetWellWorkoverReasons();

                if (!wellWorkOverReasonList.Any())
                {
                    ViewBag.Title = "Well Workover Reason SetUp";
                    return(View("~/Views/WellWorkOverReason/WellWorkOverReasons.cshtml", wellWorkOverReasonList));
                }

                var equipmentList = GetEquipmets();

                if (!equipmentList.Any())
                {
                    ViewBag.Edit  = 0;
                    ViewBag.Title = "Equipment SetUp";
                    var equipmentTypeList = new EquipmentTypeServices().GetAllOrderedEquipmentTypes() ?? new List <EquipmentType>();

                    if (!equipmentTypeList.Any())
                    {
                        ViewBag.Edit  = 0;
                        ViewBag.Title = "Equipment Type SetUp";
                        return(View("~/Views/EquipmentType/EquipmentTypes.cshtml", new List <EquipmentType>()));
                    }
                    return(View("~/Views/Equipment/Equipments.cshtml", Tuple.Create(equipmentTypeList, new List <Equipment>())));
                }

                var wells = GetWells();
                if (!wells.Any())
                {
                    ViewBag.Edit  = 1;
                    ViewBag.Title = "Well Set Up";
                    var wellTypeList = new WellTypeServices().GetAllOrderedWellTypes() ?? new List <WellType>();

                    if (!wellTypeList.Any())
                    {
                        ViewBag.Edit  = 0;
                        ViewBag.Title = "Well Type Set Up";
                        return(View("~/Views/WellType/WellTypes.cshtml", new List <WellType>()));
                    }

                    var companyList = new CompanyServices().GetAllOrderedCompanies() ?? new List <Company>();
                    if (!companyList.Any())
                    {
                        ViewBag.Edit  = 0;
                        ViewBag.Title = "Company SetUp";
                        return(View("~/Views/Company/Companies.cshtml", new List <Company>()));
                    }
                    var wellClassList = GetWellClasses();
                    if (!wellClassList.Any())
                    {
                        ViewBag.Edit  = 0;
                        ViewBag.Title = "well Class Set Up";
                        return(View("~/Views/WellClass/WellClasses.cshtml", wellClassList));
                    }

                    return(View("~/Views/Well/Wells.cshtml", new WellViewModel {
                        WellTypes = wellTypeList, Companies = companyList, WellClasses = wellClassList, Wells = new List <Well>()
                    }));
                }

                var yearList  = GetYears();
                var monthList = GetMonths();
                int dataCount;
                var wellWorkOvers = GetWellWorkovers(ItemsPerPage, PageNumber, out dataCount);

                if (!wellWorkOvers.Any())
                {
                    ViewBag.Edit  = 1;
                    ViewBag.Title = "Well Workover SetUp";

                    return(View(new WellWorkoverViewModel
                    {
                        WellWorkOverReasons = wellWorkOverReasonList,
                        Equipments = equipmentList,
                        WellObjects = wells,
                        WellWorkOvers = new List <WellWorkover>()
                    }));
                }

                var txx = new WellWorkoverViewModel
                {
                    WellWorkOverReasons = wellWorkOverReasonList,
                    Equipments          = equipmentList,
                    WellObjects         = wells,
                    WellWorkOvers       = wellWorkOvers
                };

                ViewBag.Title            = "Manage Well Workovers";
                Session["_workoverPage"] = 1;
                return(View(txx));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                var txx = new WellWorkoverViewModel
                {
                    WellWorkOverReasons = GetWellWorkoverReasons(),
                    Equipments          = GetEquipmets(),
                    WellObjects         = GetWells(),
                    WellWorkOvers       = new List <WellWorkover>()
                };

                ViewBag.Title = "Manage Well Workovers";
                return(View(txx));
            }
        }