Beispiel #1
0
        public void CategoryLV_InsertItem()
        {
            var item = new BarterSystem.WebForms.Models.CategoryViewModel();

            TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                var itemData = new Category()
                {
                    Name = item.Name
                };
                data.Categories.Add(itemData);
                data.SaveChanges();
            }
        }
Beispiel #2
0
        // The id parameter name should match the DataKeyNames value set on the control
        public void CategoryLV_UpdateItem(int Id)
        {
            BarterSystem.WebForms.Models.CategoryViewModel item = null;
            var itemData = data.Categories.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 CategoryViewModel()
            {
                Name = itemData.Name
            };
            TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                itemData.Name = item.Name;
                data.SaveChanges();
                Notifier.Success("Category changed");
            }
        }