//Get items
        public List <PolicyHotelOtherGroupItemDataTableItem> GetPolicyHotelOtherGroupItemDataTableItems(int policyGroupId, int policyOtherGroupHeaderId)
        {
            List <PolicyHotelOtherGroupItemDataTableItem> policyHotelOtherGroupItemDataTableItems = new List <PolicyHotelOtherGroupItemDataTableItem>();

            PolicyHotelOtherGroupItem           policyHotelOtherGroupItem           = new PolicyHotelOtherGroupItem();
            PolicyHotelOtherGroupItemRepository policyHotelOtherGroupItemRepository = new PolicyHotelOtherGroupItemRepository();

            policyHotelOtherGroupItem = policyHotelOtherGroupItemRepository.GetPolicyHotelOtherGroupItem(policyGroupId, policyOtherGroupHeaderId);

            //Get Columns
            List <PolicyOtherGroupHeaderColumnName>    policyOtherGroupHeaderColumnNames          = new List <PolicyOtherGroupHeaderColumnName>();
            PolicyOtherGroupHeaderColumnNameRepository policyOtherGroupHeaderColumnNameRepository = new PolicyOtherGroupHeaderColumnNameRepository();

            policyOtherGroupHeaderColumnNames = policyOtherGroupHeaderColumnNameRepository.GetPolicyOtherGroupHeaderColumnNames(policyOtherGroupHeaderId);

            if (policyOtherGroupHeaderColumnNames != null)
            {
                foreach (PolicyOtherGroupHeaderColumnName item in policyOtherGroupHeaderColumnNames)
                {
                    PolicyHotelOtherGroupItemDataTableItem policyHotelOtherGroupItemDataTableItem = new PolicyHotelOtherGroupItemDataTableItem()
                    {
                        PolicyOtherGroupHeaderColumnNameId = item.PolicyOtherGroupHeaderColumnNameId,
                        PolicyOtherGroupHeaderColumnName   = item
                    };
                    policyHotelOtherGroupItemDataTableItems.Add(policyHotelOtherGroupItemDataTableItem);
                }
            }

            return(policyHotelOtherGroupItemDataTableItems);
        }
        //Get items
        public List <PolicyHotelOtherGroupItemDataTableItem> GetPolicyHotelOtherGroupItemDataTableItems(int policyHotelOtherGroupItemDataTableRowId, int policyOtherGroupHeaderId)
        {
            List <PolicyHotelOtherGroupItemDataTableItem> policyHotelOtherGroupItemDataTableItems = new List <PolicyHotelOtherGroupItemDataTableItem>();

            List <int> policyOtherGroupHeaderColumnNameIds = new List <int>();

            //Get Completed Columns
            List <PolicyHotelOtherGroupItemDataTableItem> policyHotelOtherGroupItemDataTableItemsCompleted = new List <PolicyHotelOtherGroupItemDataTableItem>();

            policyHotelOtherGroupItemDataTableItemsCompleted = db.PolicyHotelOtherGroupItemDataTableItems.Where(
                c => c.PolicyHotelOtherGroupItemDataTableRowId == policyHotelOtherGroupItemDataTableRowId
                ).ToList();

            foreach (PolicyHotelOtherGroupItemDataTableItem policyHotelOtherGroupItemDataTableItem in policyHotelOtherGroupItemDataTableItemsCompleted)
            {
                policyHotelOtherGroupItemDataTableItems.Add(policyHotelOtherGroupItemDataTableItem);
                policyOtherGroupHeaderColumnNameIds.Add(policyHotelOtherGroupItemDataTableItem.PolicyOtherGroupHeaderColumnNameId);
            }

            //Get Empty Columns
            List <PolicyOtherGroupHeaderColumnName>    policyOtherGroupHeaderColumnNames          = new List <PolicyOtherGroupHeaderColumnName>();
            PolicyOtherGroupHeaderColumnNameRepository policyOtherGroupHeaderColumnNameRepository = new PolicyOtherGroupHeaderColumnNameRepository();

            policyOtherGroupHeaderColumnNames = policyOtherGroupHeaderColumnNameRepository.GetIncompletePolicyOtherGroupHeaderColumnNames(
                policyOtherGroupHeaderId,
                policyOtherGroupHeaderColumnNameIds);

            foreach (PolicyOtherGroupHeaderColumnName item in policyOtherGroupHeaderColumnNames)
            {
                PolicyHotelOtherGroupItemDataTableItem policyHotelOtherGroupItemDataTableItem = new PolicyHotelOtherGroupItemDataTableItem()
                {
                    PolicyOtherGroupHeaderColumnNameId = item.PolicyOtherGroupHeaderColumnNameId,
                    PolicyOtherGroupHeaderColumnName   = item
                };
                policyHotelOtherGroupItemDataTableItems.Add(policyHotelOtherGroupItemDataTableItem);
            }

            return(policyHotelOtherGroupItemDataTableItems);
        }
        public ActionResult Edit(PolicyHotelOtherGroupItemDataTableItemVM policyHotelOtherGroupItemDataTableItemVM, FormCollection formCollection)
        {
            //Check Policy Exists
            PolicyGroup policyGroup = new PolicyGroup();

            policyGroup = policyGroupRepository.GetGroup(policyHotelOtherGroupItemDataTableItemVM.PolicyGroup.PolicyGroupId);
            if (policyGroup == null)
            {
                ViewData["ActionMethod"] = "CreatePost";
                return(View("RecordDoesNotExistError"));
            }

            //Check PolicyOtherGroupHeader Exists
            PolicyOtherGroupHeader policyOtherGroupHeader = new PolicyOtherGroupHeader();

            policyOtherGroupHeader = policyOtherGroupHeaderRepository.GetPolicyOtherGroupHeader(policyHotelOtherGroupItemDataTableItemVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId);
            if (policyOtherGroupHeader == null)
            {
                ViewData["ActionMethod"] = "CreatePost";
                return(View("RecordDoesNotExistError"));
            }

            //We need to extract group from groupVM
            List <PolicyHotelOtherGroupItemDataTableItem> policyHotelOtherGroupItemDataTableItems = new List <PolicyHotelOtherGroupItemDataTableItem>();

            foreach (string item in formCollection)
            {
                if (item.StartsWith("PolicyOtherGroupHeaderColumnNameId"))
                {
                    PolicyHotelOtherGroupItemDataTableItem policyHotelOtherGroupItemDataTableItem = new PolicyHotelOtherGroupItemDataTableItem()
                    {
                        PolicyOtherGroupHeaderColumnNameId = Int32.Parse(item.Replace("PolicyOtherGroupHeaderColumnNameId_", "")),
                        TableDataItem = formCollection[item]
                    };
                    policyHotelOtherGroupItemDataTableItems.Add(policyHotelOtherGroupItemDataTableItem);
                }
            }
            if (policyHotelOtherGroupItemDataTableItems.Count() <= 0)
            {
                ViewData["Message"] = "ValidationError : missing item";;
                return(View("Error"));
            }

            policyHotelOtherGroupItemDataTableItemVM.PolicyHotelOtherGroupItemDataTableItems = policyHotelOtherGroupItemDataTableItems;

            //Update Model From Form + Validate against DB
            try
            {
                UpdateModel <PolicyHotelOtherGroupItemDataTableItemVM>(policyHotelOtherGroupItemDataTableItemVM, "PolicyHotelOtherGroupItemDataTableItemVM");
            }
            catch
            {
                string n = "";
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        n += error.ErrorMessage;
                    }
                }
                ViewData["Message"] = "ValidationError : " + n;
                return(View("Error"));
            }

            //Database Update
            try
            {
                policyHotelOtherGroupItemDataTableItemRepository.Edit(policyHotelOtherGroupItemDataTableItemVM);
            }
            catch (SqlException ex)
            {
                //Non-Unique Name
                if (ex.Message == "NonUniqueName")
                {
                    return(View("NonUniqueNameError"));
                }

                LogRepository logRepository = new LogRepository();
                logRepository.LogError(ex.Message);

                ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details";
                return(View("Error"));
            }

            ViewData["NewSortOrder"] = 0;
            return(RedirectToAction("List", new { id = policyHotelOtherGroupItemDataTableItemVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId, policyGroupId = policyHotelOtherGroupItemDataTableItemVM.PolicyGroup.PolicyGroupId }));
        }