// opens a view to updates an individual repair
        public ActionResult UpdateRepair(string upc)
        {
            RepairStatusView item = new RepairStatusView();
            Trello           t    = new Models.Trello();
            var cards             = t.GetCards(SessionVariables.CurrentLocation.ToString());

            foreach (var card in cards)
            {
                if (card.name == upc)
                {
                    item.ItemUpc  = card.name;
                    item.Comments = t.GetCardComments(card.id);
                    var checklists = t.GetChecklists(card.id);
                    var checklist  = checklists.Last().checkItems;
                    item.Checklist = new List <Models.Trello.CheckItemView>();
                    foreach (var checkitem in checklist)
                    {
                        Trello.CheckItemView civ = new Models.Trello.CheckItemView();
                        civ.id          = checkitem.id;
                        civ.name        = checkitem.name;
                        civ.nameData    = checkitem.nameData;
                        civ.pos         = checkitem.pos;
                        civ.idChecklist = checkitem.idChecklist;
                        if (checkitem.state == "complete")
                        {
                            civ.state = true;
                        }
                        else
                        {
                            civ.state = false;
                        }
                        item.Checklist.Add(civ);
                    }
                    item.RequestDate = checklists.Last().name;
                    item.DueDate     = card.due;
                    foreach (var b in t.GetBoards())
                    {
                        if (b.id == card.idBoard)
                        {
                            item.ItemLocation = b.name;
                        }
                    }
                }
            }
            return(View(item));
        }
        // GET: tb_ItemRepair
        public ActionResult Index()
        {
            // get active repairs for current location
            Trello t     = new Trello();
            var    cards = new List <Trello.Card>();

            cards = t.GetCards(SessionVariables.CurrentLocation.ToString());

            // populate a view model by inserting cards
            List <RepairStatusView> view = new List <RepairStatusView>();

            // compile list of cards with active due date, sort by date due
            foreach (var card in cards)
            {
                if (card.due != null && card.dueComplete == false)
                {
                    RepairStatusView repair = new RepairStatusView();
                    repair.ItemUpc = card.name;

                    var checklists = t.GetChecklists(card.id);
                    //repair.Checklist = checklists.First().checkItems;

                    var checklist = checklists.Last().checkItems;
                    repair.Checklist = new List <Models.Trello.CheckItemView>();
                    foreach (var checkitem in checklist)
                    {
                        Trello.CheckItemView civ = new Models.Trello.CheckItemView();
                        civ.id          = checkitem.id;
                        civ.name        = checkitem.name;
                        civ.nameData    = checkitem.nameData;
                        civ.pos         = checkitem.pos;
                        civ.idChecklist = checkitem.idChecklist;
                        if (checkitem.state == "complete")
                        {
                            civ.state = true;
                        }
                        else
                        {
                            civ.state = false;
                        }
                        repair.Checklist.Add(civ);
                    }

                    repair.RequestDate = checklists.Last().name;
                    repair.DueDate     = Convert.ToDateTime(card.due).Date;
                    foreach (var b in t.GetBoards())
                    {
                        if (b.id == card.idBoard)
                        {
                            repair.ItemLocation = b.name;
                        }
                    }

                    var comments = t.GetCardComments(card.id);
                    if (repair.Comments == null)
                    {
                        repair.Comments = new List <Models.Trello.Comment>();
                    }
                    foreach (var comment in comments)
                    {
                        if (Convert.ToDateTime(repair.RequestDate) <= Convert.ToDateTime(comment.date) && !comment.text.StartsWith("CLOSED"))
                        {
                            repair.Comments.Add(comment);
                        }
                    }

                    view.Add(repair);
                }
            }

            if (TempData["message"] != null)
            {
                ViewBag.Message = TempData["message"];
            }

            return(View(view));
        }