/// <summary>
        /// Executes the request asynchronously based on input properties..
        /// </summary>
        /// <param name="input">Required input properties to create a Platform.</param>
        /// <returns></returns>
        public async Task <PlatformResponse> ExecuteAsync(CreatePlatformInput input)
        {
            var platformResponse = new PlatformResponse();

            try
            {
                Log.Information("Creating Platform [{Name}]...", input?.Name);
                var platformToCreate = Mapper.Map <CreatePlatformInput, Domain.Platform.Entities.Platform>(input);
                var createdPlatform  = await Repository.CreateAsync(platformToCreate);

                if (createdPlatform == null)
                {
                    var exception = new Exception($"Failed to create Platform [{platformToCreate.Name}].");
                    Log.Error(exception, EXCEPTION_MESSAGE_TEMPLATE, exception.Message);
                    HandleErrors(platformResponse, exception);
                }
                else
                {
                    platformResponse.Platform   = createdPlatform;
                    platformResponse.StatusCode = 200;

                    Log.Information("Created Platform [{Name}]", platformResponse.Platform.Name);
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception, "Failed to create Platform [{Name}].", input?.Name);
                HandleErrors(platformResponse, exception);
            }
            return(platformResponse);
        }
        public void Valid()
        {
            var createPlatformInput = new CreatePlatformInput
            {
                Name        = "Platformy",
                ReleaseDate = DateTime.Now.AddDays(-20)
            };

            var platform = Mapper.Map <Domain.Platform.Entities.Platform>(createPlatformInput);

            platform.Should().NotBeNull();
            platform.Name.Should().Be(createPlatformInput.Name);
            platform.ReleaseDate.Should().Be(createPlatformInput.ReleaseDate);
        }
Пример #3
0
        /// <summary>
        /// Execute the Request based on the input propreties.
        /// </summary>
        /// <param name="input">Input properties required to create a Platform.</param>
        /// <returns></returns>
        public PlatformResponse Execute(CreatePlatformInput input)
        {
            var platformResponse = new PlatformResponse();

            try
            {
                Log.Information("Creating Platform [{Name}]...", input?.Name);
                var platformToCreate = Mapper.Map <CreatePlatformInput, Domain.Platform.Entities.Platform>(input);
                var createdPlatform  = Repository.Create(platformToCreate);

                platformResponse.Platform   = createdPlatform;
                platformResponse.StatusCode = 200;

                Log.Information("Created Platform [{Name}]", createdPlatform.Name);
            }
            catch (Exception exception)
            {
                Log.Error(exception, "Failed to create Platform [{Name}]", input?.Name);
                HandleErrors(platformResponse, exception);
            }
            return(platformResponse);
        }
Пример #4
0
 public IActionResult Post(CreatePlatformInput input)
 {
     return(ExecuteAndHandleRequest(() => RequestAggregate.CreatePlatformRequest.Execute(input)));
 }
 public async Task <IActionResult> Post(CreatePlatformInput input)
 {
     return(await ExecuteAndHandleRequestAsync(() => RequestAsyncAggregate.CreatePlatformRequestAsync.ExecuteAsync(input)));
 }