public async Task <IHttpActionResult> Put(UpdateZoneCommand command) { var response = await Bus.Send <UpdateZoneCommand, UpdateZoneCommandResponse>(command); return(Ok(response)); }
public void ShouldRequireValidZoneId() { var command = new UpdateZoneCommand { Id = 99, Title = "New Title" }; FluentActions.Invoking(() => SendAsync(command)).Should().Throw<NotFoundException>(); }
public async Task <ActionResult> Update(int id, UpdateZoneCommand command) { if (id != command.Id) { return(BadRequest()); } await Mediator.Send(command); return(NoContent()); }
public IActionResult UpdateZone(Guid id, [FromBody] UpdateZoneViewModel model) { var cmd = new UpdateZoneCommand(id, model.Name, model.Description, model.Channel, model.IsEnabled); var zone = _zoneService.UpdateZone(cmd); var newZone = new ZoneSummaryViewModel() { Id = zone.Id, Channel = zone.Channel, Description = zone.Description, IsEnabled = zone.IsEnabled, Name = zone.Name }; return(Created(newZone.Id.ToString(), newZone)); }
public ResultDto UpdateZone(long siteId, long id, ZoneDto zoneDto) { return(Result(() => { var command = new UpdateZoneCommand { SiteId = siteId, ZoneId = id, Title = zoneDto.Title, Name = zoneDto.Name, IsActive = zoneDto.IsActive, IsPublic = zoneDto.IsPublic, Description = zoneDto.Description, }; CommandDispatcher.Send(command); })); }
public async Task <UpdateZoneCommandResponse> Handle(UpdateZoneCommand command) { var city = await _cityRepository.FindAsync(command.CityId); if (city == null) { throw new DomainException("شهر یافت نشد"); } var zone = city.Zones.SingleOrDefault(p => p.Id == command.Id); if (zone == null) { throw new DomainException("منطقه یافت نشد"); } zone.Title = command.Title; return(new UpdateZoneCommandResponse()); }
public async Task ShouldRequireUniqueTitle() { var listId = await SendAsync(new CreateZoneCommand { Title = "New Zone" }); await SendAsync(new CreateZoneCommand { Title = "Other Zone" }); var command = new UpdateZoneCommand { Id = listId, Title = "Other Zone" }; FluentActions.Invoking(() => SendAsync(command)) .Should() .Throw<ValidationException>() .Where(ex => ex.Errors.ContainsKey("Title")) .And.Errors["Title"] .Should() .Contain("The specified title already exists."); }
public async Task ShouldUpdateZone() { var userId = await RunAsDefaultUserAsync(); var listId = await SendAsync(new CreateZoneCommand { Title = "New Zone" }); var command = new UpdateZoneCommand { Id = listId, Title = "Updated Zone Title" }; await SendAsync(command); var list = await FindAsync<Zone>(listId); list.Title.Should().Be(command.Title); list.LastModifiedBy.Should().NotBeNull(); list.LastModifiedBy.Should().Be(userId); list.LastModified.Should().NotBeNull(); list.LastModified.Should().BeCloseTo(DateTime.Now, 1000); }