Exemplo n.º 1
0
        public async Task <MKit_Kit> GetKitDetailAsync(string userId, long projectSnapshotId, int thumbnailSize)
        {
            using var log = BeginFunction(nameof(KitMicroService), nameof(GetKitDetailAsync), userId, projectSnapshotId, thumbnailSize);
            try
            {
                //await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false);

                var entry = await ProjectMicroService.GetProjectAsync(projectSnapshotId).ConfigureAwait(false);

                if (entry == null)
                {
                    log.Result(null);
                    return(null);
                }

                log.Message("Project entry retrieved.");

                var kit = ProjectLibraryKitUtility.CreateKit(entry);

                log.Message("Kit created.");

                var result = Create.MKit_Kit(kit, entry.Name, entry.ProjectId, null, thumbnailSize, InventoryMicroService);

                log.Result(result);
                return(result);
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }
Exemplo n.º 2
0
        public async Task <MKit_UpdateSpecificationResponse> UpdateKitSpecificationAsync(string userId, Guid projectId, MKit_KitSpecificationUpdate specificationUpdate)
        {
            using var log = BeginFunction(nameof(KitMicroService), nameof(UpdateKitSpecificationAsync), userId, projectId, specificationUpdate);
            try
            {
                await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false);

                var entry = await ProjectMicroService.GetProjectAsync(projectId).ConfigureAwait(false);

                var kit           = ProjectLibraryKitUtility.CreateKit(entry);
                var specification = kit.KitSpecification.Clone();
                var standardSizes = kit.Design.GetStandardSizes();

                var serviceErrorBuilder = new ServiceErrorBuilder();
                UpdateSpecification(specification, specificationUpdate, standardSizes, serviceErrorBuilder);

                kit.KitSpecification = specification;

                if (serviceErrorBuilder.ServiceError != null)
                {
                    serviceErrorBuilder.AddPageError("Kit not updated.");
                    var result = new MKit_UpdateSpecificationResponse()
                    {
                        ServiceError = serviceErrorBuilder.ServiceError
                    };
                    log.Result(result);
                    return(result);
                }
                else
                {
                    var data = ProjectLibraryKitUtility.CreateProjectSpecification(kit);

                    _ = await ProjectMicroService.UpdateProjectAsync(projectId, data, GetUtcNow()).ConfigureAwait(false);

                    var result = new MKit_UpdateSpecificationResponse();
                    log.Result(result);
                    return(result);
                }
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }
Exemplo n.º 3
0
        public async Task <MKit_Kit> GetKitDetailPreviewAsync(string userId, Guid projectId, int thumbnailSize, MKit_KitSpecificationUpdate specificationUpdate)
        {
            using var log = BeginFunction(nameof(KitMicroService), nameof(GetKitDetailPreviewAsync), userId, projectId, thumbnailSize, specificationUpdate);
            try
            {
                await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false);

                var entry = await ProjectMicroService.GetProjectAsync(projectId).ConfigureAwait(false);

                if (entry == null)
                {
                    log.Result(null);
                    return(null);
                }

                var kit           = ProjectLibraryKitUtility.CreateKit(entry);
                var specification = kit.KitSpecification.Clone();
                var standardSizes = kit.Design.GetStandardSizes();

                var serviceErrorBuilder = new ServiceErrorBuilder();
                UpdateSpecification(specification, specificationUpdate, standardSizes, serviceErrorBuilder);

                kit.KitSpecification = specification;

                var result = Create.MKit_Kit(kit, entry.Name, entry.ProjectId, null, thumbnailSize, InventoryMicroService);
                if (serviceErrorBuilder.ServiceError != null)
                {
                    serviceErrorBuilder.AddPageError("One or more input values are incorrect.");
                    result.ServiceError = serviceErrorBuilder.ServiceError;
                }

                log.Result(result);
                return(result);
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }