Beispiel #1
0
        public async Task <IHttpActionResult> Put(UpdateZoneCommand command)
        {
            var response = await
                           Bus.Send <UpdateZoneCommand, UpdateZoneCommandResponse>(command);

            return(Ok(response));
        }
Beispiel #2
0
        public void ShouldRequireValidZoneId() {
            var command = new UpdateZoneCommand {
                Id = 99,
                Title = "New Title"
            };

            FluentActions.Invoking(() => SendAsync(command)).Should().Throw<NotFoundException>();
        }
Beispiel #3
0
        public async Task <ActionResult> Update(int id, UpdateZoneCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }

            await Mediator.Send(command);

            return(NoContent());
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
 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());
        }
Beispiel #7
0
        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.");
        }
Beispiel #8
0
        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);
        }