Example #1
0
        public ConcretePartModel RegisterConcretePart(AddConcretePartDto dto)
        {
            return(ProtectedExecute <AddConcretePartDto, ConcretePartModel>(partDto =>
            {
                AdminService.CheckActiveAdmin(partDto.AdminSession);

                PartModel part = PartRepo.Get(partDto.PartId.GetValueOrDefault());
                if (part == null)
                {
                    throw new NotFoundException("part");
                }

                MaterialModel material = part.PossibleMaterials.FirstOrDefault(mat => mat.Id == partDto.MaterialId);
                if (material == null)
                {
                    throw new NotFoundException("possible material");
                }

                PartColorModel color = material.PossibleColors.FirstOrDefault(col => col.Id == partDto.ColorId);
                if (color == null)
                {
                    throw new NotFoundException("possible color");
                }

                if (partDto.ControllerMac == null && partDto.Amount == null)
                {
                    throw new NotFoundException("nor controller_mac neither amount");
                }

                if (partDto.ControllerMac == null && part.ConnectionHelpers.Count() != 0)
                {
                    throw new NotFoundException("controller mac for assigned connection helpers");
                }

                if (partDto.ControllerMac != null && part.ConnectionHelpers.Count() == 0)
                {
                    throw new NotFoundException("connection helpers to embed a controller");
                }

                if (partDto.ControllerMac != null && ConcretePartRepo.GetPartByMac(partDto.ControllerMac) != null)
                {
                    throw new ConflictException("mac address");
                }

                if (partDto.ControllerMac == null)
                {
                    ICollection <ConcretePartModel> created = new List <ConcretePartModel>();
                    ConcretePartModel model = Mapper.Map <AddConcretePartDto, ConcretePartModel>(partDto);

                    for (int i = 0; i < partDto.Amount.GetValueOrDefault(); ++i)
                    {
                        created.Add(ConcretePartRepo.Create(model));
                    }

                    return created.LastOrDefault();
                }

                return ConcretePartRepo.Create(Mapper.Map <AddConcretePartDto, ConcretePartModel>(partDto));
            }, dto));
        }
Example #2
0
        public ControllerConfigModel GetControllerConfig(ControllerPingDto pingDto)
        {
            ConcretePartModel part = ConcretePartRepo.GetPartByMac(pingDto.Mac);

            if (part == null)
            {
                throw new NotFoundException("concrete part with specified mac");
            }

            List <int> indicators = part.Part.ConnectionHelpers.Select(helper => helper.IndicatorPinNumber).ToList();
            List <int> readers    = part.Part.ConnectionHelpers.Aggregate(
                new List <int>(),
                (acc, helper) => acc.Append(helper.ReaderPinNumber).Append(helper.ReaderPinNumberOther).ToList()
                ).ToList();

            return(new ControllerConfigModel(indicators, readers));
        }
Example #3
0
 public SellPositionModel(float price, ConcretePartModel concretePart)
 {
     Price        = price;
     ConcretePart = concretePart;
 }