示例#1
0
        public async Task <IActionResult> Edit(int id, Autonomo autonomo)
        {
            if (!ModelState.IsValid)
            {
                AutonomoFormViewModel viewModel = new AutonomoFormViewModel {
                    Autonomo = autonomo
                };
                return(View(viewModel));
            }
            if (id != autonomo.Id)
            {
                return(BadRequest());
            }
            try
            {
                autonomo.EmpresaId = int.Parse(EmpresaId);
                await _autonomoService.UpdateAsync(autonomo);

                return(RedirectToAction(nameof(Index)));
            }
            catch (ApplicationException e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }
        }
示例#2
0
        public async Task <IActionResult> Create()
        {
            var empresas = await _empresaService.FindAllAsync();

            AutonomoFormViewModel viewModel = new AutonomoFormViewModel {
                Empresas = empresas
            };

            return(View(viewModel));
        }
示例#3
0
        public async Task <IActionResult> Create(Autonomo autonomo)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new AutonomoFormViewModel();
                return(View(viewModel));
            }
            autonomo.EmpresaId = int.Parse(EmpresaId);
            await _autonomoService.InsertAsync(autonomo);

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

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

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

            AutonomoFormViewModel viewModel = new AutonomoFormViewModel {
                Autonomo = obj
            };

            return(View(viewModel));
        }