Example #1
0
        public async Task <IActionResult> Edit(int id, Membro membro)
        {
            if (!ModelState.IsValid)
            {
                var oscs = await _oscService.FindAllAsync();

                var viewModel = new OscFormViewModel {
                    Membro = membro, Oscs = oscs
                };
                return(View(viewModel));
            }

            if (id != membro.Id)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id não corresponde!" }));
            }
            try
            {
                await _membroService.UpdateAsync(membro);

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

            var viewModel = new OscFormViewModel {
                Oscs = oscs
            };

            return(View(viewModel));
        }
Example #3
0
        public async Task <IActionResult> Create(Membro membro)
        {
            if (!ModelState.IsValid)
            {
                var oscs = await _oscService.FindAllAsync();

                var viewModel = new OscFormViewModel {
                    Membro = membro, Oscs = oscs
                };
                return(View(viewModel));
            }

            await _membroService.InsertAsync(membro);

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

            var obj = await _membroService.FindByIdAsync(id.Value);

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

            List <Osc> oscs = await _oscService.FindAllAsync();

            OscFormViewModel viewModel = new OscFormViewModel {
                Membro = obj, Oscs = oscs
            };

            return(View(viewModel));
        }