Beispiel #1
0
        public async Task <IActionResult> Edit(Guid id, ItemCategoriesCreateEditViewModel vm)
        {
            if (id != vm.Id)
            {
                return(BadRequest(new MessageDTO("Id and vm.id do not match")));
            }

            if (!await _bll.ItemCategories.ExistsAsync(vm.Id, User.UserGuidId()))
            {
                return(NotFound(new MessageDTO($"Item category with this id {id} not found")));
            }

            vm.AppUserId = User.UserGuidId();

            if (ModelState.IsValid)
            {
                await _bll.ItemCategories.UpdateAsync(_mapper.Map(vm));

                await _bll.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            vm.CategorySelectList =
                new SelectList(await _bll.Categories.GetAllAsync(), nameof(CategoryBLL.Id), nameof(CategoryBLL.Description), vm.CategoryId);


            return(View(vm));
        }
Beispiel #2
0
        // GET: ItemCategories/Create
        public async Task <IActionResult> Create()
        {
            var vm = new ItemCategoriesCreateEditViewModel
            {
                CategorySelectList = new SelectList(await _bll.Categories.GetAllAsync(), nameof(CategoryBLL.Id), nameof(CategoryBLL.Description)),
                ItemSelectList     = new SelectList(await _bll.Items.GetAllAsync(User.UserGuidId()), nameof(ItemBLL.Id), nameof(ItemBLL.Description))
            };

            return(View(vm));
        }
Beispiel #3
0
        public async Task <IActionResult> Create(ItemCategoriesCreateEditViewModel vm)
        {
            vm.AppUserId = User.UserGuidId();

            if (ModelState.IsValid)
            {
                var bllEntity = _mapper.Map(vm);
                _bll.ItemCategories.Add(bllEntity);
                await _bll.SaveChangesAsync();

                vm.Id = bllEntity.Id;
                return(RedirectToAction(nameof(Index)));
            }

            vm.CategorySelectList =
                new SelectList(await _bll.Categories.GetAllAsync(), nameof(CategoryBLL.Id), nameof(CategoryBLL.Description), vm.CategoryId);
            vm.ItemSelectList = new SelectList(await _bll.Items.GetAllAsync(User.UserGuidId()), nameof(ItemBLL.Id), nameof(ItemBLL.Description), vm.ItemId);

            return(View(vm));
        }