public ActionResult exSearch(PostedItems postedItems)
        {
            string id             = (string)Session["itemTypeSession"];
            var    model          = new Search();
            var    selectedItems  = new List <checkBoxListModel>();
            var    selectedCards  = new List <cards>();
            var    postedItemsIds = new string[0];
            var    availItems     = new List <checkBoxListModel>();

            if (postedItems == null)
            {
                postedItems = new PostedItems();
            }

            if (postedItems.IDs != null && postedItems.IDs.Any())
            {
                postedItemsIds = postedItems.IDs;
            }
            if (postedItemsIds.Any())
            {
                selectedCards = applicationDAO.cardsForExtandedSearchList(postedItems.IDs, id).Where(cd => cd.published == true).Distinct().ToList();
                var claimsQuery = applicationDAO.selectedItemsForExtandedSearch(postedItems.IDs).ToList();
                int c           = 0;
                foreach (var i in claimsQuery)
                {
                    selectedItems.Add(new checkBoxListModel(c, i.ClaimValue, i.ClaimType));
                }
            }
            else
            {
                selectedCards = applicationDAO.getItemLayouts(id).Where(c => c.published == true).ToList();
            }



            var claims = applicationDAO.getAllCardClaims().Where(c => c.published == true);
            int count  = 0;

            foreach (var item in claims)
            {
                if (item.ClaimType != "TYPE")
                {
                    availItems.Add(new checkBoxListModel(count, item.ClaimValue, item.ClaimType));
                }
                count++;
            }
            model.availItems           = availItems;
            model.selectedItems        = selectedItems;
            model.postedItems          = postedItems;
            model.Cards                = selectedCards;
            Session["itemTypeSession"] = id;
            return(View(model));
        }
        // GET: cards/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            cards cards = await db.cards.FindAsync(id);

            if (cards == null)
            {
                return(HttpNotFound());
            }

            var         addCards      = new addCardModel();
            var         exSearch      = new Models.addCards.ExtandedSearchModel();
            var         availItems    = new List <checkBoxListModel>();
            var         selectedItems = new List <checkBoxListModel>();
            PostedItems postedItems   = new PostedItems();


            List <CARD_CLAIMS> cardClaims = applicationDAO.getCardClaims(cards.Id).ToList();

            postedItems.IDs = new string[cardClaims.Count];
            foreach (var i in cardClaims)
            {
                selectedItems.Add(new checkBoxListModel(i.ClaimValue, i.ClaimValue));
            }
            addCards.selectedItems = selectedItems;
            addCards.cards         = cards;

            //Select data for card claims check box list
            var claims = applicationDAO.getAllCardClaims();

            foreach (var item in claims)
            {
                if (item.ClaimType != "TYPE")
                {
                    availItems.Add(new checkBoxListModel(item.ClaimValue, item.ClaimValue));
                }
            }
            addCards.availItems = availItems;

            //Set item_type and layouts for this item_type
            var       types     = db.ITEM_TYPE.Where(c => c.Id == cards.ITEM_TYPE_ID).ToList();
            ITEM_TYPE item_type = new ITEM_TYPE();

            foreach (var i in types)
            {
                item_type = i;
            }
            Dictionary <int, string> layoutO = new Dictionary <int, string>();
            var layouts = db.layout.Where(c => c.ITEM_TYPE_ID == item_type.Id);

            foreach (var item in layouts)
            {
                string param = item.height + " " + item.width;
                layoutO.Add(item.Id, param);
            }
            ViewBag.layout_id    = new SelectList(layoutO, "Key", "Value", cards.layout_id);
            ViewBag.ITEM_TYPE_ID = new SelectList(db.ITEM_TYPE, "Id", "NAME", cards.ITEM_TYPE_ID);
            addCards.availItems  = availItems;
            return(View(addCards));
        }