Exemple #1
0
        public async Task <IActionResult> Update(int id, UpdateInstructorCommand command)
        {
            command.InstructorId = id;
            await Mediator.Send(command);

            return(NoContent());
        }
Exemple #2
0
        public async Task <IActionResult> Edit(UpdateInstructorCommand command, string[] selectedCourses)
        {
            try
            {
                await Mediator.Send(command);

                return(RedirectToAction(nameof(Index)));
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists, " +
                                         "see your system administrator.");

                await PopulateAssignedCourseData(command.InstructorID.Value);

                return(View(new UpdateInstructorVM
                {
                    InstructorID = command.InstructorID.Value,
                    LastName = command.LastName,
                    FirstName = command.FirstName,
                    HireDate = command.HireDate,
                    OfficeLocation = command.OfficeLocation
                }));
            }
        }
        public async Task <IActionResult> Update([FromBody] UpdateInstructorCommand updateItem)
        {
            if (updateItem == null)
            {
                return(NotFound());
            }
            var result = await _updateInstructorCommand.Handle(updateItem, CancellationToken.None);

            return(Ok(result));
        }
Exemple #4
0
        public async Task <IActionResult> UpdateInstructor(UpdateInstructorCommand command)
        {
            Request.Headers.TryGetValue("Authorization", out var token);
            string role = await AuthHelper.GetRoleFromTokenAsync(token);

            if (role != "admin")
            {
                return(StatusCode(401, new { Error = "Unauthorized" }));
            }

            BaseResponse <int> result = (BaseResponse <int>) await Mediator.Send(command);

            return(!result.Success ? StatusCode(result.Error.StatusCode, result.Error) : Ok(result));
        }
Exemple #5
0
        public async Task <IActionResult> UpdateInstructor(Guid id, [FromBody] UpdateInstructorCommand command)
        {
            try
            {
                command.Id = id;
                var result = await _mediator.Send(command);

                return(NoContent());
            }
            catch (EntityNotFoundException e)
            {
                return(NotFound(e.Message));
            }
        }
 public async Task <ActionResult <int> > Put(UpdateInstructorCommand command)
 {
     return(await Execute(command, "You have successfully updated the instructor"));
 }
        public async Task <IActionResult> Update([FromBody] UpdateInstructorCommand command)
        {
            await Mediator.Send(command);

            return(NoContent());
        }
 public async Task <IActionResult> UpdateInstructor(UpdateInstructorCommand command)
 {
     return(Ok(await mediator.Send(command)));
 }