//Get items
        public List <PolicyAirOtherGroupItemDataTableItem> GetPolicyAirOtherGroupItemDataTableItems(int policyGroupId, int policyOtherGroupHeaderId)
        {
            List <PolicyAirOtherGroupItemDataTableItem> policyAirOtherGroupItemDataTableItems = new List <PolicyAirOtherGroupItemDataTableItem>();

            PolicyAirOtherGroupItem           policyAirOtherGroupItem           = new PolicyAirOtherGroupItem();
            PolicyAirOtherGroupItemRepository policyAirOtherGroupItemRepository = new PolicyAirOtherGroupItemRepository();

            policyAirOtherGroupItem = policyAirOtherGroupItemRepository.GetPolicyAirOtherGroupItem(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)
                {
                    PolicyAirOtherGroupItemDataTableItem policyAirOtherGroupItemDataTableItem = new PolicyAirOtherGroupItemDataTableItem()
                    {
                        PolicyOtherGroupHeaderColumnNameId = item.PolicyOtherGroupHeaderColumnNameId,
                        PolicyOtherGroupHeaderColumnName   = item
                    };
                    policyAirOtherGroupItemDataTableItems.Add(policyAirOtherGroupItemDataTableItem);
                }
            }

            return(policyAirOtherGroupItemDataTableItems);
        }
        //Get items
        public List <PolicyAirOtherGroupItemDataTableItem> GetPolicyAirOtherGroupItemDataTableItems(int policyAirOtherGroupItemDataTableRowId, int policyOtherGroupHeaderId)
        {
            List <PolicyAirOtherGroupItemDataTableItem> policyAirOtherGroupItemDataTableItems = new List <PolicyAirOtherGroupItemDataTableItem>();

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

            //Get Completed Columns
            List <PolicyAirOtherGroupItemDataTableItem> policyAirOtherGroupItemDataTableItemsCompleted = new List <PolicyAirOtherGroupItemDataTableItem>();

            policyAirOtherGroupItemDataTableItemsCompleted = db.PolicyAirOtherGroupItemDataTableItems.Where(
                c => c.PolicyAirOtherGroupItemDataTableRowId == policyAirOtherGroupItemDataTableRowId
                ).ToList();

            foreach (PolicyAirOtherGroupItemDataTableItem policyAirOtherGroupItemDataTableItem in policyAirOtherGroupItemDataTableItemsCompleted)
            {
                policyAirOtherGroupItemDataTableItems.Add(policyAirOtherGroupItemDataTableItem);
                policyOtherGroupHeaderColumnNameIds.Add(policyAirOtherGroupItemDataTableItem.PolicyOtherGroupHeaderColumnNameId);
            }

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

            policyOtherGroupHeaderColumnNames = policyOtherGroupHeaderColumnNameRepository.GetIncompletePolicyOtherGroupHeaderColumnNames(
                policyOtherGroupHeaderId,
                policyOtherGroupHeaderColumnNameIds);

            foreach (PolicyOtherGroupHeaderColumnName item in policyOtherGroupHeaderColumnNames)
            {
                PolicyAirOtherGroupItemDataTableItem policyAirOtherGroupItemDataTableItem = new PolicyAirOtherGroupItemDataTableItem()
                {
                    PolicyOtherGroupHeaderColumnNameId = item.PolicyOtherGroupHeaderColumnNameId,
                    PolicyOtherGroupHeaderColumnName   = item
                };
                policyAirOtherGroupItemDataTableItems.Add(policyAirOtherGroupItemDataTableItem);
            }

            policyAirOtherGroupItemDataTableItems = policyAirOtherGroupItemDataTableItems.OrderBy(x => x.PolicyOtherGroupHeaderColumnName.DisplayOrder).ToList();

            return(policyAirOtherGroupItemDataTableItems);
        }
Exemplo n.º 3
0
        public ActionResult Edit(PolicyAirOtherGroupItemDataTableItemVM policyAirOtherGroupItemDataTableItemVM, FormCollection formCollection)
        {
            //Check Policy Exists
            PolicyGroup policyGroup = new PolicyGroup();

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

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

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

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

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

            policyAirOtherGroupItemDataTableItemVM.PolicyAirOtherGroupItemDataTableItems = policyAirOtherGroupItemDataTableItems;

            //Update Model From Form + Validate against DB
            try
            {
                UpdateModel <PolicyAirOtherGroupItemDataTableItemVM>(policyAirOtherGroupItemDataTableItemVM, "PolicyAirOtherGroupItemDataTableItemVM");
            }
            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
            {
                policyAirOtherGroupItemDataTableItemRepository.Edit(policyAirOtherGroupItemDataTableItemVM);
            }
            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 = policyAirOtherGroupItemDataTableItemVM.PolicyOtherGroupHeader.PolicyOtherGroupHeaderId, policyGroupId = policyAirOtherGroupItemDataTableItemVM.PolicyGroup.PolicyGroupId }));
        }