public ViewModelBase()
 {
     connection                = new Connection();
     connectCommand            = new ConnectCommand(this);
     removeServiceCommand      = new RemoveServiceCommand(this);
     restartServiceCommand     = new RestartServiceCommand(this);
     updateServiceCommand      = new UpdateServiceCommand(this);
     upgradeApplicationCommand = new UpgradeApplicationCommand(this);
     deleteApplicationCommand  = new DeleteApplicationCommand(this);
     refreshCommand            = new RefreshCommand(this);
     Applications              = new ObservableCollection <ApplicationType>();
     AppGridEnable             = false;
     ServiceGridEnable         = false;
     SFPowerShell.Initialize();
     //ApplicationType ap = new ApplicationType("Id", "name", "TypeName", "version", "1");
     //Service s = new Service("SId", "SName", "SType", "SVersion", "1", "1");
     //ap.Services.Add(s);
     //Parameter p = new Parameter("keykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykey", "valuevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevalue");
     //ap.ApplicationParameters.Add(p);
     //Parameter p2 = new Parameter("key2", "value2");
     //ap.ApplicationParameters.Add(p2);
     //Applications.Add(ap);
     //ApplicationType ap2 = new ApplicationType("Id2", "name2", "TypeName2", "version2", "1");
     //Service s2 = new Service("SId2", "SName2", "SType2", "SVersion2", "1", "1");
     //ap2.Services.Add(s2);
     //Parameter p3 = new Parameter("key2", "value2");
     //ap2.ApplicationParameters.Add(p3);
     //Applications.Add(ap2);
 }
        public async Task <IActionResult> UpdateService(int serviceId, [FromBody] UpdateServiceRequest request)
        {
            var updateServiceCommand = new UpdateServiceCommand(serviceId, request);
            var result = await mediator.Send(updateServiceCommand);

            return(StatusCode((int)result.Code, result.Value));
        }
Beispiel #3
0
 public async Task UpdateService(
     [FromServices] UpdateServiceCommand command,
     [FromBody] ServiceInput input,
     [FromRoute] Guid serviceId
     )
 {
     await command.Execute(serviceId, input);
 }
Beispiel #4
0
        public async Task <IActionResult> UpdateService(Guid id, [FromBody] UpdateServiceCommand command)
        {
            ServiceView s = await mediator.Dispatch <UpdateServiceCommand, ServiceView>(
                command,
                User.GetUserId()
                );

            return(Ok(s));
        }
        public async void ServiceShouldThrowRefereceException()
        {
            var updatedService = new UpdateServiceCommand {
                Id = serviceId, Name = GConst.UpdatedName, IndustryId = GConst.InvalidId
            };

            var status = await Record.ExceptionAsync(async() => await sut.Handle(updatedService, CancellationToken.None));

            Assert.NotNull(status);
            Assert.Equal(string.Format(GConst.ReferenceExceptionMessage, GConst.Update, GConst.Service, serviceId, GConst.IndustryLower, GConst.InvalidId), status.Message);
        }
        public async void ServiceShouldThrowNotFoundException()
        {
            var updatedService = new UpdateServiceCommand {
                Id = GConst.InvalidId, Name = GConst.ValidName
            };

            var status = await Record.ExceptionAsync(async() => await sut.Handle(updatedService, CancellationToken.None));

            Assert.NotNull(status);
            Assert.Equal(string.Format(GConst.NotFoundExceptionMessage, GConst.Service, GConst.InvalidId), status.Message);
        }
Beispiel #7
0
        public async Task <IActionResult> Update([FromBody] UpdateServiceRequest request)
        {
            var command = new UpdateServiceCommand(request.ServiceId, request.Name, request.AllowHalfTime);
            var result  = await updateServiceService.Process(command);

            return(Ok(new ApiReturnItem <ServiceResult>
            {
                Item = result,
                Success = true
            }));
        }
        public async Task <IActionResult> UpdateService(string id, [FromBody] UpdateServiceCommand command)
        {
            try
            {
                command.Id = id;
                var result = await _mediator.Send(command);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        public async void ServiceShouldUpdateCorrect()
        {
            var updatedService = new UpdateServiceCommand {
                Id = serviceId, Name = GConst.ValidName, IndustryId = industryId
            };

            var status = Task <Unit> .FromResult(await sut.Handle(updatedService, CancellationToken.None));

            var resultId = context.Services.SingleOrDefault(x => x.Name == GConst.ValidName).Id;

            Assert.Equal(serviceId, resultId);
            Assert.Equal(GConst.SuccessStatus, status.Status.ToString());
            Assert.Equal(GConst.ValidCount, context.Services.Count());
        }
Beispiel #10
0
        public IResult Handler(UpdateServiceCommand command)
        {
            var service = new Service(command.Name, command.Description, command.Price);

            AddNotifications(service);

            if (service.Invalid)
            {
                return(new CommandResult(false, "Dados inválidos", null, Notifications));
            }

            var serviceCreated = _repository.Update(service);

            return(new CommandResult(true, "Dados salvo com sucesso", new ServiceUpdatedViewModel(serviceCreated.Id, service.Name), Notifications));
        }
Beispiel #11
0
        public List <string> UpdateService(string name, string serviceToUpdate, UpdateServiceCommand newService)
        {
            var inmateToUpdate = _inmates.FirstOrDefault(inmate => inmate.Name == name);
            var services       = inmateToUpdate.MyServices;

            for (var i = 0; i < services.Count; i++)
            {
                if (services[i] == serviceToUpdate)
                {
                    services[i] = newService.MyNewService;
                }
                else
                {
                    break;
                }
            }
            return(services);
        }
        public Task <HttpResponseMessage> Put([FromBody] dynamic body)
        {
            var service = _service.GetOneByName((string)body.name);

            if (service == null)
            {
                return(CreateResponse(HttpStatusCode.Ambiguous, service));
            }

            var commandService = new UpdateServiceCommand(
                id: Guid.Parse((string)body.id),
                name: (string)body.name,
                value: (float)body.value,
                description: (string)body.description
                );

            service = _service.Update(commandService);

            return(CreateResponse(HttpStatusCode.Created, service));
        }
        public async Task Handle(UpdateServiceCommand message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var service = await _serviceRepository.Get(message.Id);

            if (service == null)
            {
                return;
            }

            service.Name             = message.Name;
            service.Description      = message.Description;
            service.Price            = message.Price;
            service.Tags             = message.Tags;
            service.UpdateDateTime   = message.UpdateDateTime;
            service.PartialImagesUrl = message.Images;
            if (message.Occurrence != null)
            {
                service.Occurrence = new ServiceAggregateOccurrence
                {
                    Id        = Guid.NewGuid().ToString(),
                    Days      = message.Occurrence.Days,
                    StartDate = message.Occurrence.StartDate,
                    EndDate   = message.Occurrence.EndDate,
                    StartTime = message.Occurrence.StartTime,
                    EndTime   = message.Occurrence.EndTime
                };
            }

            await _serviceRepository.Update(service);

            _eventPublisher.Publish(new ServiceUpdatedEvent
            {
                Id = message.Id
            });
        }
        public async Task ShouldUpdateService()
        {
            var categoryIds = await AddCategories();

            var createCommand = new CreateServiceCommand
            {
                Address            = "Address",
                ContactEmail       = "*****@*****.**",
                ContactPhoneNumber = "099123456",
                Description        = "Description",
                Name         = "New Service",
                ServicePrice = "0",
                CategoryIds  = categoryIds.Select(s => s.ToString()).ToArray()
            };

            var serviceId = await SendAsync(createCommand);

            var updateCommand = new UpdateServiceCommand {
                Id                 = serviceId.ToString(),
                Address            = "New address",
                ContactEmail       = "*****@*****.**",
                ContactPhoneNumber = "099123456",
                Description        = "Description",
                Name               = "New Service",
                ServicePrice       = "0",
                CategoryIds        = categoryIds.Select(s => s.ToString()).ToArray()
            };

            await SendAsync(updateCommand);

            var getServicesQuery = new GetServiceQuery
            {
                ServiceId = serviceId
            };

            var result = await SendAsync(getServicesQuery);

            result.Address.Should().Be("New address");
        }
        public Service Update(UpdateServiceCommand command)
        {
            var service = _repository.GetOne(command.Id);

            if (!string.IsNullOrEmpty(command.Name))
            {
                service.ChangeName(command.Name);
            }
            if (!string.IsNullOrEmpty(command.Description))
            {
                service.changeDescripion(command.Description);
            }

            service.ChangeValue(command.Value);

            _repository.Update(service);

            if (Commit())
            {
                return(service);
            }

            return(null);
        }
        public async Task <ActionResult> Update([FromForm] UpdateServiceCommand command)
        {
            await Mediator.Send(command);

            return(NoContent());
        }
        public async Task <UpdateServiceValidationResult> Execute(UpdateServiceCommand command, string subject)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            if (string.IsNullOrWhiteSpace(subject))
            {
                throw new ArgumentNullException(nameof(subject));
            }

            var service = await _serviceRepository.Get(command.Id);

            if (service == null)
            {
                return(new UpdateServiceValidationResult(ErrorDescriptions.TheServiceDoesntExist));
            }

            var shop = await _shopRepository.Get(service.ShopId);

            if (shop == null)
            {
                return(new UpdateServiceValidationResult(ErrorDescriptions.TheShopDoesntExist));
            }

            if (shop.Subject != subject)
            {
                return(new UpdateServiceValidationResult(ErrorDescriptions.TheServiceCannotBeUpdatedByYou));
            }

            if (!IsValid(command.Name, 1, 50))
            {
                return(new UpdateServiceValidationResult(string.Format(ErrorDescriptions.TheParameterIsMandatoryAndShouldContainsBetween, Constants.DtoNames.Service.Name, 1, 50)));
            }

            if (!IsValid(command.Description, 1, 255))
            {
                return(new UpdateServiceValidationResult(string.Format(ErrorDescriptions.TheParameterIsMandatoryAndShouldContainsBetween, Constants.DtoNames.Service.Description, 1, 255)));
            }

            if (command.Occurrence == null)
            {
                return(new UpdateServiceValidationResult(string.Format(ErrorDescriptions.TheParameterIsMandatory, Constants.DtoNames.Service.Occurrence)));
            }

            if (command.Occurrence.Days == null || !command.Occurrence.Days.Any())
            {
                return(new UpdateServiceValidationResult(ErrorDescriptions.TheDaysAreNotValid));
            }

            if (command.Occurrence.StartDate == default(DateTime))
            {
                return(new UpdateServiceValidationResult(string.Format(ErrorDescriptions.TheParameterIsMandatory, Constants.DtoNames.Occurrence.StartDate)));
            }

            if (command.Occurrence.EndDate == default(DateTime))
            {
                return(new UpdateServiceValidationResult(string.Format(ErrorDescriptions.TheParameterIsMandatory, Constants.DtoNames.Occurrence.EndDate)));
            }

            if (command.Occurrence.StartDate > command.Occurrence.EndDate || command.Occurrence.EndDate < DateTime.UtcNow)
            {
                return(new UpdateServiceValidationResult(ErrorDescriptions.TheOccurrenceDatePeriodIsNotValid));
            }

            if (command.Occurrence.StartTime == default(TimeSpan))
            {
                return(new UpdateServiceValidationResult(string.Format(ErrorDescriptions.TheParameterIsMandatory, Constants.DtoNames.Occurrence.StartTime)));
            }

            if (command.Occurrence.EndTime == default(TimeSpan))
            {
                return(new UpdateServiceValidationResult(string.Format(ErrorDescriptions.TheParameterIsMandatory, Constants.DtoNames.Occurrence.EndTime)));
            }

            if (command.Occurrence.StartTime > command.Occurrence.EndTime)
            {
                return(new UpdateServiceValidationResult(ErrorDescriptions.TheOccurrenceTimePeriodIsNotValid));
            }

            if (command.Images != null)
            {
                foreach (var image in command.Images)
                {
                    Uri uri;
                    if (Uri.TryCreate(image, UriKind.Absolute, out uri) && (uri.Scheme == "http" || uri.Scheme == "https"))
                    {
                        continue;
                    }

                    try
                    {
                        var base64Encoded = image;
                        base64Encoded = base64Encoded.Substring(image.IndexOf(',') + 1);
                        base64Encoded = base64Encoded.Trim('\0');
                        Convert.FromBase64String(base64Encoded);
                    }
                    catch
                    {
                        return(new UpdateServiceValidationResult(ErrorDescriptions.TheProductImageCanBeUrlOrBase64Encoded));
                    }
                }
            }

            return(new UpdateServiceValidationResult());
        }
Beispiel #18
0
 public IActionResult Update([FromBody] UpdateServiceCommand service)
 {
     return Ok(_handler.Handler(service));
 }
        public IEnumerable <Inmate> UpdateServices(string name, string serviceToUpdate, UpdateServiceCommand newService)
        {
            var repo       = new InmateRepository();
            var services   = repo.UpdateService(name, serviceToUpdate, newService);
            var allInmates = repo.GetAll();

            return(allInmates);
        }
Beispiel #20
0
 public async Task <IActionResult> UpdateService(string serviceId, UpdateServiceCommand command)
 {
     return(Ok(await Mediator.Send(command)));
 }
 public UpdateServiceCommandValidatorTests()
 {
     this.updateValidator = new UpdateServiceCommandValidator();
     this.updateCommand   = new UpdateServiceCommand();
 }
        public async Task <ActionResult <Unit> > Update(int id, UpdateServiceCommand command)
        {
            command.Id = id;

            return(await Mediator.Send(command));
        }