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;
            }
        }
Exemple #2
0
        public async Task TryInteract(StorageCellInteractionDto dto)
        {
            await Execute(async() => {
                using (UnitOfWork db = new UnitOfWork())
                {
                    StorageCellEntity storageCell = await db.GetRepo <StorageCellEntity>().Get(dto.StorageCellId.Value);
                    AccountEntity account         = await db.GetRepo <AccountEntity>().Get(dto.AccountId.Value);

                    StorageCellEventEntity storageCellEvent = new StorageCellEventEntity()
                    {
                        account_id      = account.id,
                        storage_cell_id = storageCell.id,
                        timespan        = DateTime.Now
                    };

                    NotPermittedException ex = null;

                    if (account.Roles.SelectMany(r => r.StorageCellPermissions).Any(m => m.id == storageCell.id))
                    {
                        storageCellEvent.log = $"Interaction with Storage cell #{storageCell.id} by Account #{account.id}: SUCCESS";
                    }
                    else
                    {
                        storageCellEvent.log = $"Interaction with Storage cell #{storageCell.id} by Account #{account.id}: ACCESS DENIED";
                        ex = new NotPermittedException(storageCellEvent.log);
                    }

                    await db.GetRepo <StorageCellEventEntity>().Create(storageCellEvent);
                    await db.Save();

                    if (ex != null)
                    {
                        throw ex;
                    }
                }
            });
        }
Exemple #3
0
        public async Task <StorageCellModel> Create(AuthorizedDto <StorageCellDto> dto)
        {
            return(await Execute(async() => {
                using (UnitOfWork db = new UnitOfWork())
                {
                    StorageCellEntity storageCellEntity = dto.Data.ToModel <StorageCellModel>().ToEntity <StorageCellEntity>();

                    await db.GetRepo <StorageCellEntity>().Create(storageCellEntity);
                    await db.Save();

                    StorageCellPrefabEntity prefab = await db.GetRepo <StorageCellPrefabEntity>().Get(storageCellEntity.storage_cell_prefab_id);

                    RoleEntity ownerRole = await RoleService.GetCompanyOwnerRole(prefab.company_id, db);
                    ownerRole.StorageCellPermissions.Add(storageCellEntity);

                    RoleEntity creatorRole = await RoleService.GetCompanyWorkerRole(dto.Session.UserId, db);
                    creatorRole?.StorageCellPermissions.Add(storageCellEntity);

                    await db.Save();

                    return storageCellEntity.ToModel <StorageCellModel>();
                }
            }));
        }