public async Task <ScheduleResponseModel> PutSchedule( int scheduleId, [FromForm] ScheduleRequestModel model, CancellationToken cancellationToken ) { cancellationToken.ThrowIfCancellationRequested(); var command = new UpdateScheduleCommand( scheduleId, model.SubjectId, model.TeacherId, model.StartTime, model.Duration, model.LessonType, model.AudienceNumber ); await _mediator.Send(command, cancellationToken); var query = new FindScheduleByIdQuery(scheduleId); var schedule = await _mediator.Send(query, cancellationToken); var response = _mapper.Map <ScheduleResponseModel>(schedule); return(response); }
public async Task <IActionResult> EditWorker(string id, [FromBody] WorkerDto worker) { try { var updateWorkerDataCommand = new UpdateWorkerDataCommand { Id = id, FirstName = worker.FirstName, LastName = worker.LastName }; var result = await _mediator.Send(updateWorkerDataCommand); var updateScheduleCommand = new UpdateScheduleCommand { Id = id, Schedule = worker.Schedule }; result = await _mediator.Send(updateScheduleCommand); var uploadImageCommand = new UploadImageCommand { Id = id, ImageSource = worker.ImageSource }; result = await _mediator.Send(uploadImageCommand); await _userService.UpdateUserAsync(id, worker.UserEmail, worker.UserPhoneNumber); return(Ok()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <IActionResult> Update([FromBody] UpdateScheduleCommand command) { command.ManagerId = User.Identity.Name; await mediator.Send(command); return(Ok()); }
public async Task ShouldUpdateSchedule() { var userId = await RunAsDefaultUserAsync(); var command = new CreateScheduleCommand { Title = "Tasks", Note = "Note", ScheduleType = ScheduleType.Daily, UserId = "1" }; var itemId = await SendAsync(command); var updateCommand = new UpdateScheduleCommand { Id = itemId, Title = "Updated Item Title" }; await SendAsync(command); var item = await FindAsync <Schedule>(itemId); item.Title.Should().Be(updateCommand.Title); item.LastModifiedBy.Should().NotBeNull(); item.LastModifiedBy.Should().Be(userId); item.LastModified.Should().NotBeNull(); item.LastModified.Should().BeCloseTo(DateTime.Now, 1000); }
public async Task <IActionResult> Update(int id, [FromBody] UpdateScheduleCommand command) { if (command == null || command.Id != id) { return(BadRequest()); } return(Ok(await _mediator.Send(command))); }
public async Task <ActionResult> Update(int id, UpdateScheduleCommand command) { if (id != command.Id) { return(BadRequest()); } await Mediator.Send(command); return(NoContent()); }
public void ShouldRequireValidScheduleId() { var command = new UpdateScheduleCommand { Id = 99, Title = "New Title" }; FluentActions.Invoking(() => SendAsync(command)).Should().Throw <NotFoundException>(); }
public async Task <IActionResult> Update([FromBody] UpdateScheduleRequest request) { var command = new UpdateScheduleCommand(request.ScheduleId, request.Day, request.Hour, request.CustomerId, request.ServiceId); var result = await updateScheduleService.Process(command); return(Ok(new ApiReturnItem <ScheduleResult> { Item = result, Success = true })); }
public async Task <IActionResult> UpdateSchedule(string id, [FromBody] UpdateScheduleCommand command) { try { command.Id = id; var result = await _mediator.Send(command); return(Ok()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IActionResult UpdateSchedule(Guid scheduleId, [FromBody] AddScheduleViewModel model) { var cmd = new UpdateScheduleCommand(scheduleId, model.Name, model.Description, model.ScheduleType, model.Days, model.StartDate, model.StartTime, model.Duration, model.EnabledUntil, model.IsEnabled, model.ZoneIds); var sched = _scheduleService.UpdateSchedule(cmd); var newschedule = new ScheduleSummaryViewModel() { Id = sched.Id, Name = sched.Name, Description = sched.Description, ScheduleType = sched.ScheduleType, Days = sched.Days, Duration = sched.Duration, EnabledUntil = sched.EnabledUntil, IsEnabled = sched.IsEnabled, StartDate = sched.StartDate, StartTime = sched.StartTime, ZoneIds = sched.ZoneIds }; return(Created(newschedule.Id.ToString(), newschedule)); }
public async Task Patch(long id, [FromBody] ScheduleInputModel input) { var command = new UpdateScheduleCommand(id, input, UserId); await _mediator.Send(command); }