// The id parameter name should match the DataKeyNames value set on the control
        public void AdminBarterVL_UpdateItem(int Id)
        {
            BarterSystem.WebForms.Models.BarterViewModel item = null;
            var itemData = data.Advertisments.Find(Id);

            if (itemData == null)
            {
                // The item wasn't found
                ModelState.AddModelError("", String.Format("Item with id {0} was not found", Id));
                return;
            }
            item = new BarterViewModel()
            {
                Id         = itemData.Id,
                Content    = itemData.Content,
                Status     = itemData.Status,
                CategoryId = itemData.CategoryId,
                Title      = itemData.Title,
                UserName   = itemData.User.UserName
            };
            TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                itemData.Content    = item.Content;
                itemData.Status     = item.Status;
                itemData.CategoryId = item.CategoryId;
                itemData.Title      = item.Title;
                data.SaveChanges();
                AdminBarterVL.DataBind();
                Notifier.Success("Item updated");
            }
        }
        protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (String.Equals(e.CommandName, "Approve"))
            {
                //TODO optimize this
                var id = int.Parse(
                    AdminBarterVL.DataKeys[e.Item.DisplayIndex]
                    .Value.ToString());
                new BarterObjectData().Aprove(id);
                Notifier.Success("Barter approved");
                DataBind();
            }
            else if (String.Equals(e.CommandName, "Disapprove"))
            {
                var id = int.Parse(
                    AdminBarterVL.DataKeys[e.Item.DisplayIndex]
                    .Value.ToString());
                //TODO optimize this
                new BarterObjectData().Disaprove(id);

                Notifier.Success("Barter rejected");
                DataBind();
            }
            else if (String.Equals(e.CommandName, "Sort"))
            {
                if (AdminBarterVL.SortExpression == e.CommandArgument.ToString() &&
                    AdminBarterVL.SortDirection == SortDirection.Ascending)
                {
                    AdminBarterVL.Sort(e.CommandArgument.ToString() + "DESC"
                                       , SortDirection.Descending);
                }
                else
                {
                    AdminBarterVL.Sort(e.CommandArgument.ToString()
                                       , SortDirection.Ascending);
                }
            }
        }