コード例 #1
0
        public async Task <IActionResult> Edit(EditViewModel viewModel)
        {
            var errors = await _taskEditViewModelValidator.Validate(viewModel);

            errors.ToList().ForEach(e => ModelState.AddModelError(e.Key, e.Value));

            if (ModelState.IsValid)
            {
                if (!User.IsOrganizationAdmin(viewModel.OrganizationId))
                {
                    return(Unauthorized());
                }

                var taskId = await _mediator.SendAsync(new EditTaskCommand { Task = viewModel });

                return(viewModel.Id == 0 ?
                       RedirectToAction(nameof(EventController.Details), "Event", new { id = viewModel.EventId }) :
                       RedirectToAction(nameof(Details), "Task", new { id = taskId }));
            }

            viewModel.CancelUrl = Url.Action(new UrlActionContext {
                Action = nameof(Details), Controller = "Task", Values = new { eventId = viewModel.EventId, id = viewModel.Id, area = "Admin" }
            });
            return(View(viewModel));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(EditViewModel model)
        {
            var errors = _taskDetailModelValidator.Validate(model);

            errors.ToList().ForEach(e => ModelState.AddModelError(e.Key, e.Value));

            if (ModelState.IsValid)
            {
                if (!User.IsOrganizationAdmin(model.OrganizationId))
                {
                    return(Unauthorized());
                }

                var taskId = await _mediator.SendAsync(new EditTaskCommandAsync { Task = model });

                return(model.Id == 0 ?
                       RedirectToAction(nameof(EventController.Details), "Event", new { id = model.EventId }) :
                       RedirectToAction(nameof(Details), "Task", new { id = taskId }));
            }

            return(View(model));
        }