public async Task <IActionResult> CreateProductTier([FromRoute, ResourcePermissions(SecurableResourceType.Product, Permission.Change)] long id, [FromBody] TierCreationOptions productTier)
        {
            if (id == 0)
            {
                ModelState.AddModelError(ErrorResponses.InvalidId, string.Empty);
            }
            if (productTier == null)
            {
                ModelState.AddModelError(ErrorResponses.MissingBody, string.Empty);
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // This is a three-step operation (because the tier characteristic values need to be interpreted)
            // First, get the list of characteristics (and their associated data types)
            // Second, perform the conversion from a string/object into a usable form
            // Third, perform the upload
            var suppliedCharacteristicValues = await parseProductCharacteristicsAsync(id, productTier.CharacteristicValues);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var tierModel = new Tier()
            {
                Name       = productTier.Name,
                ExternalId = productTier.ExternalId,
                StartDate  = productTier.StartDate,
                EndDate    = productTier.EndDate,
                Product    = new Product()
                {
                    Id = id
                },
                Visible         = productTier.Visible,
                Characteristics = suppliedCharacteristicValues
            };

            var currentUser = await CurrentUserRetriever.GetCurrentUserAsync();

            // Create the tier, then pass the details along to a GetTierById command to populate the full details
            var createTierCommand   = new Jibberwock.Persistence.DataAccess.Commands.Products.CreateTier(Logger, currentUser, HttpContext.TraceIdentifier, WebApiConfiguration.Authorization.DefaultServiceId, null, tierModel);
            var auditedTierCreation = await createTierCommand.Execute(SqlServerDataSource);

            var getCreatedTierCommand = new Jibberwock.Persistence.DataAccess.Commands.Products.GetTier(Logger, currentUser, auditedTierCreation.Result);
            var resultantTier         = await getCreatedTierCommand.Execute(SqlServerDataSource);

            return(Created(string.Empty, resultantTier));
        }
        public async Task <IActionResult> GetSingleProductTier([FromRoute, ResourcePermissions(SecurableResourceType.Product, Permission.Read)] long id, [FromRoute] long tierId)
        {
            if (id == 0)
            {
                ModelState.AddModelError(ErrorResponses.InvalidId, string.Empty);
            }
            if (tierId == 0)
            {
                ModelState.AddModelError(ErrorResponses.InvalidId, string.Empty);
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var currentUser = await CurrentUserRetriever.GetCurrentUserAsync();

            var getTierCommand = new Jibberwock.Persistence.DataAccess.Commands.Products.GetTier(Logger, currentUser, new Tier()
            {
                Id = tierId, Product = new Product()
                {
                    Id = id
                }
            });
            var tier = await getTierCommand.Execute(SqlServerDataSource);

            if (tier == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(tier));
            }
        }