Exemple #1
0
        public virtual ActionResult Create(ItemCreateStartVM vm)
        {
            try
            {
                Item item = Mapper.Map<ItemCreateVM, Item>(vm.Item);

                using (var ctx = new Desert.DAL.Context())
                {
                    ItemType type = ctx.ItemTypes.Single(x => x.Id == vm.Item.TypeId);
                    item.Type = type;

                    ctx.Items.Add(item);
                    ctx.SaveChanges();
                }

                return RedirectToAction(ActionNames.Index);
            }
            catch
            {
                this.ModelState.AddModelError("", "error");

                vm.Types = GetItemTypesSelectList(vm.Item.TypeId);

                return View(vm);
            }
        }
Exemple #2
0
        public virtual ActionResult Delete(Guid id)
        {
            ItemShowVM vm = null;

            using (var ctx = new Desert.DAL.Context())
            {
                var item = ctx.Items.Include("Type").Single(x => x.Id == id);

                vm = Mapper.Map<Item, ItemShowVM>(item);
            }

            return View(vm);
        }
Exemple #3
0
        public virtual ActionResult Delete(Guid id, FormCollection form)
        {
            try
            {
                using (var ctx = new Desert.DAL.Context())
                {
                    var item = ctx.Items.Single(x => x.Id == id);
                    ctx.Items.Remove(item);
                    ctx.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                ModelState.AddModelError("", "error");
                return View();
            }
        }
Exemple #4
0
 private SelectList GetItemTypesSelectList(object selectedValue)
 {
     using (var ctx = new Desert.DAL.Context())
     {
         return GetItemTypesSelectList(ctx, selectedValue);
     }
 }
Exemple #5
0
        public virtual ActionResult Index()
        {
            IList<ItemShowVM> list = null;

            using (var ctx = new Desert.DAL.Context())
            {
                var items = from p in ctx.Items.Include("Type")
                            orderby p.Code
                            select p;

                list = Mapper.Map<IEnumerable<Item>, IList<ItemShowVM>>(items);
            }

            return View(list);
        }
Exemple #6
0
        public virtual ActionResult Edit(ItemEditStartVM vm)
        {
            try
            {
                using (var ctx = new Desert.DAL.Context())
                {
                    Item item = ctx.Items.Include("Type")
                        .Single(x => x.Id == vm.Item.Id);

                    ItemType type = ctx.ItemTypes
                        .Single(x => x.Id == vm.Item.TypeId);

                    Mapper.Map<ItemEditVM, Item>(vm.Item, item);
                    item.Type = type;

                    ctx.SaveChanges();
                }

                return RedirectToAction(ActionNames.Index);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError("", "error");

                vm.Types = GetItemTypesSelectList(vm.Item.TypeId);

                return View(vm);
            }
        }
Exemple #7
0
        public virtual ActionResult Edit(Guid id)
        {
            ItemEditStartVM vm = new ItemEditStartVM();

            using (var ctx = new Desert.DAL.Context())
            {
                Item item = ctx.Items.Include("Type").Single(x => x.Id == id);

                vm.Item = Mapper.Map<Item, ItemEditVM>(item);

                vm.Types = GetItemTypesSelectList(ctx, vm.Item.TypeId);
            }

            return View(vm);
        }