コード例 #1
0
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id não informado!" }));
            }

            var obj = await _inventarioService.FindByIdAsync(EmpresaId, id.Value);

            if (obj == null)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id não encontrado!" }));
            }

            if (obj.Status == StatusInventario.Processado)
            {
                return(RedirectToAction(nameof(Error), new { message = "Inventário já processado!" }));
            }

            var viewModel = new InventarioFormViewModel {
                Inventario = obj
            };

            return(View(viewModel));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, Inventario inventario)
        {
            if (!ModelState.IsValid)
            {
                var centrosDeCustos = await _centroDeCustoService.FindAllAsync(EmpresaId);

                var funcionarios = await _funcionarioService.FindAllAsync(EmpresaId);

                var viewModel = new InventarioFormViewModel {
                    Inventario = inventario, CentrosDeCustos = centrosDeCustos, Funcionarios = funcionarios
                };
                return(View(viewModel));
            }
            if (id != inventario.Id)
            {
                return(BadRequest());
            }
            try
            {
                await _inventarioService.UpdateAsync(inventario);

                return(RedirectToAction(nameof(Create), "InventariosItens", new { inventarioId = inventario.Id }));
            }
            catch (ApplicationException e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id não informado!" }));
            }

            var obj = await _inventarioService.FindByIdAsync(EmpresaId, id.Value);

            if (obj == null)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id não encontrado!" }));
            }

            if (obj.Status == StatusInventario.Processado)
            {
                return(RedirectToAction(nameof(Error), new { message = "Inventário já processado!" }));
            }

            var centrosDeCustos = await _centroDeCustoService.FindAllAsync(EmpresaId);

            var funcionarios = await _funcionarioService.FindAllAsync(EmpresaId);

            var viewModel = new InventarioFormViewModel {
                Inventario = obj, CentrosDeCustos = centrosDeCustos, Funcionarios = funcionarios
            };

            return(View(viewModel));
        }
コード例 #4
0
        public async Task <IActionResult> Create()
        {
            var centrosDeCustos = await _centroDeCustoService.FindAllAsync(EmpresaId);

            var funcionarios = await _funcionarioService.FindAllAsync(EmpresaId);

            var viewModel = new InventarioFormViewModel {
                CentrosDeCustos = centrosDeCustos, Funcionarios = funcionarios
            };

            return(View(viewModel));
        }
コード例 #5
0
        public async Task <IActionResult> Create(Inventario inventario)
        {
            if (!ModelState.IsValid)
            {
                var centrosDeCustos = await _centroDeCustoService.FindAllAsync(EmpresaId);

                var funcionarios = await _funcionarioService.FindAllAsync(EmpresaId);

                var viewModel = new InventarioFormViewModel {
                    CentrosDeCustos = centrosDeCustos, Funcionarios = funcionarios, Inventario = inventario
                };
                return(View(viewModel));
            }
            await _inventarioService.InsertAsync(inventario);

            return(RedirectToAction(nameof(Create), "InventariosItens", new { inventarioId = inventario.Id }));
        }
コード例 #6
0
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id não infomado!" }));
            }

            var obj = await _inventarioService.FindByIdAsync(EmpresaId, id.Value);

            if (obj == null)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id não encontrado!" }));
            }

            var inventarioItens = await _inventarioItemService.FindByInventarioIdAsync(EmpresaId, int.Parse(id.ToString()));

            var viewModel = new InventarioFormViewModel {
                Inventario = obj, InventarioItens = inventarioItens
            };

            return(View(viewModel));
        }