Exemplo n.º 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));
        }
Exemplo n.º 2
0
 public FurnitureItemModel RegisterFurnitureItem(AddFurnitureDto dto)
 {
     return(ProtectedExecute <AddFurnitureDto, FurnitureItemModel>(furnitureDto =>
     {
         AdminService.CheckActiveAdmin(furnitureDto.AdminSession);
         FurnitureItemModel model = Mapper.Map <AddFurnitureDto, FurnitureItemModel>(furnitureDto);
         return FurnitureRepo.Create(model);
     }, dto));
 }