コード例 #1
0
        public async override Task <Guid> Execute(PadSeriesCreateCommand command, User?user)
        {
            var sizes = command.Sizes.Select(s => new PadSize(s.Diameter, s.Thickness)).OrderByDescending(s => s.Diameter).ToList();

            var colors = command.Pads.Select(c => {
                ProcessedImage?image = null;

                if (c.Image != null)
                {
                    var dataUrlImage = c.Image.Right(); // Crash and burn if Guid passed. (Theoretically) this should be impossible since they're new pads.
                    image            = imageProcessor.Process(dataUrlImage.Name, dataUrlImage.Data);
                }

                List <PadOption> options = new();

                foreach (var optionCreate in c.Options)
                {
                    PadOption option;

                    option = new PadOption(sizes[optionCreate.PadSizeIndex].Id);
                    option.PartNumbers.AddRange(optionCreate.PartNumbers.Select(pn => new PartNumber(pn.Id, pn.Value, pn.Notes)));
                    options.Add(option);
                }

                // Sort options
                options = options.OrderByDescending(o => sizes.Find(s => s.Id == o.PadSizeId) !.Diameter).ToList();

                return(new Pad(c.Name, c.Category, c.Material, c.Texture, c.Color, c.HasCenterHole, image, options));
            }).OrderBy(c => c.Name).ToList();


            var series = new PadSeries(
                command.Name,
                command.BrandId,
                command.PolisherTypes,
                sizes,
                colors
                );

            await spec.CheckAndThrow(series);

            await repo.Add(series);

            return(series.Id);
        }
コード例 #2
0
        public async override Task Execute(PadSeriesUpdateCommand command, User?user)
        {
            var series = await repo.FindById(command.Id) ?? throw new EntityNotFoundException();

            var origColors = series.Pads;


            series.Name          = command.Name;
            series.PolisherTypes = command.PolisherTypes;
            series.BrandId       = command.BrandId;

            series.Sizes = UpdatePadSizes(series.Sizes, command.Sizes);
            series.Pads  = UpdatePads(series.Sizes, series.Pads, command.Pads);


            await spec.CheckAndThrow(series);

            await repo.Update(series);
        }