Exemplo n.º 1
0
        private void UpdateStorageCellPlacements(
            CompanyEntity company, ICollection <StorageCellEntity> storageCells,
            ICollection <StorageCellPlacementDto> storageCellPlacements
            )
        {
            foreach (StorageCellPlacementDto storageCellPlacement in storageCellPlacements)
            {
                StorageCellEntity storageCellEntity = storageCells.FirstOrDefault(
                    pi => pi.id == storageCellPlacement.StorageCellId.Value
                    );

                ManufactoryEntity manufactoryPlacement = GetManufactoryByPoint(
                    company, storageCellPlacement.X.Value, storageCellPlacement.Y.Value
                    );

                if (manufactoryPlacement == null)
                {
                    throw new PlacementException();
                }

                storageCellEntity.manufactory_id = manufactoryPlacement.id;
                storageCellEntity.x = storageCellPlacement.X;
                storageCellEntity.y = storageCellPlacement.Y;
            }
        }
Exemplo n.º 2
0
        private void UpdatePipelineItemPlacements(
            CompanyEntity company, ICollection <PipelineItemEntity> pipelineItems,
            ICollection <PipelineItemPlacementDto> pipelineItemPlacements
            )
        {
            foreach (PipelineItemPlacementDto pipelineItemPlacement in pipelineItemPlacements)
            {
                PipelineItemEntity pipelineItemEntity = pipelineItems.FirstOrDefault(
                    pi => pi.id == pipelineItemPlacement.PipelineItemId.Value
                    );

                ManufactoryEntity manufactoryPlacement = GetManufactoryByPoint(
                    company, pipelineItemPlacement.X.Value, pipelineItemPlacement.Y.Value
                    );

                if (manufactoryPlacement == null)
                {
                    throw new PlacementException();
                }

                pipelineItemEntity.manufactory_id = manufactoryPlacement.id;
                pipelineItemEntity.x = pipelineItemPlacement.X;
                pipelineItemEntity.y = pipelineItemPlacement.Y;
            }
        }
Exemplo n.º 3
0
 public bool IsPointInsideManufactory(ManufactoryEntity manufactory, double x, double y)
 {
     return(IntersectionService.CheckInside(
                (x, y), manufactory.ManufactoryPlanPoints.Select(
                    p => (p.CompanyPlanUniquePoint.x, p.CompanyPlanUniquePoint.y)
                    ).ToArray()
                ));
 }
Exemplo n.º 4
0
        public async Task TryCheckout(CheckoutDto dto)
        {
            await Execute(async() => {
                using (UnitOfWork db = new UnitOfWork())
                {
                    CheckPointEntity checkPoint = await db.GetRepo <CheckPointEntity>().Get(dto.CheckPointId.Value);
                    AccountEntity account       = await db.GetRepo <AccountEntity>().Get(dto.AccountId.Value);

                    if (dto.CurrentManufactoryId.Value != checkPoint.Manufactory1Id && dto.CurrentManufactoryId.Value != checkPoint.Manufactory2Id)
                    {
                        DataValidationException exception = new DataValidationException();

                        exception.Add(
                            typeof(CheckoutDto), nameof(CheckoutDto.CurrentManufactoryId),
                            $"{nameof(CheckoutDto.CurrentManufactoryId)} must be one of manufactories associated with check point"
                            );

                        throw exception;
                    }

                    CheckPointEventEntity checkPointEvent = new CheckPointEventEntity()
                    {
                        account_id     = account.id,
                        check_point_id = checkPoint.id,
                        is_direct      = checkPoint.Manufactory1Id == dto.CurrentManufactoryId.Value,
                        timespan       = DateTime.Now
                    };

                    ManufactoryEntity targetManufactory = checkPointEvent.is_direct ? checkPoint.Manufactory2 : checkPoint.Manufactory1;
                    NotPermittedException ex            = null;

                    if (account.Roles.SelectMany(r => r.ManufactoryPermissions).Any(m => m.id == targetManufactory.id))
                    {
                        checkPointEvent.log = $"Checkout to Manufactory #{targetManufactory.id} via Check Point ${checkPoint.id} by Account #{account.id}: SUCCESS";
                    }
                    else
                    {
                        checkPointEvent.log = $"Checkout to Manufactory #{targetManufactory.id} via Check Point ${checkPoint.id} by Account #{account.id}: ACCESS DENIED";
                        ex = new NotPermittedException(checkPointEvent.log);
                    }

                    await db.GetRepo <CheckPointEventEntity>().Create(checkPointEvent);
                    await db.Save();

                    if (ex != null)
                    {
                        throw ex;
                    }
                }
            });
        }