public async System.Threading.Tasks.Task <OperationResult <EquipmentOrder> > CreateEquipmentOrder(EquipmentOrder equipment)
 {
     return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <EquipmentOrder> >(() =>
     {
         OperationResult <EquipmentOrder> result = new OperationResult <EquipmentOrder>();
         try
         {
             Game game = GamesRepository.Read(equipment.GameId);
             if (game != null)
             {
                 if (game.CreatorId == CurrentUser.Id || IsInCompany(game.CompanyId) || UserStore.IsInRole(CurrentUser, RoleNames.Admin))
                 {
                     EquipmentOrder created = EquipmentOrdersRepository.CreateOrUpdate(equipment);
                     if (created.Id > 0)
                     {
                         result.SingleResult = created;
                         result.Result = true;
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             LoggingService.Log(ex);
         }
         return result;
     }));
 }
 public async System.Threading.Tasks.Task <OperationResult <EquipmentOrder> > GetEquipmentOrders(int gameId, int pageSize, int pageNumber, bool descending)
 {
     return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <EquipmentOrder> >(() =>
     {
         OperationResult <EquipmentOrder> result = new OperationResult <EquipmentOrder>();
         try
         {
             Game game = GamesRepository.Read(gameId);
             if (game != null)
             {
                 if (game.CreatorId == CurrentUser.Id || IsInCompany(game.CompanyId) || UserStore.IsInRole(CurrentUser, RoleNames.Admin))
                 {
                     result.Count = EquipmentOrdersRepository.Count("GameId = @GameId", new { GameId = game.Id });
                     if (result.Count > 0)
                     {
                         result.MultipleResult = EquipmentOrdersRepository.Search("GameId = @GameId",
                                                                                  new { PageSize = pageSize, PageNumber = pageNumber, GameId = game.Id }, descending);
                     }
                     result.Result = true;
                 }
             }
         }
         catch (Exception ex)
         {
             LoggingService.Log(ex);
         }
         return result;
     }));
 }
Beispiel #3
0
        public async System.Threading.Tasks.Task <OperationResult <MyGameReponseSingle> > CreateMyGame(Game game)
        {
            return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <MyGameReponseSingle> >(() =>
            {
                OperationResult <MyGameReponseSingle> result = new OperationResult <MyGameReponseSingle>();
                try
                {
                    game.CreatorId = CurrentUser.Id;
                    Game newGame = GamesRepository.CreateOrUpdate(game);
                    if (newGame.Id > 0)
                    {
                        newGame.CreatorId = Guid.Empty;
                        MyGameReponseSingle single = new MyGameReponseSingle();

                        single.Playground = PlaygroundsRepository.Read(game.Playground);
                        single.GameType = GameTypesRepository.Read(game.GameType);
                        single.Game = newGame;
                        single.Orders = EquipmentOrdersRepository.Search("GameId = @GameId",
                                                                         new { PageSize = 1, PageNumber = 200, GameId = game.Id }, true);

                        result.SingleResult = single;

                        result.Result = true;
                    }
                }
                catch (Exception ex)
                {
                    LoggingService.Log(ex);
                }
                return result;
            }));
        }
        public static void Initialize(TestContext testContext)
        {
            IDbContext context = new DbContext();

            IRepository <Certificate, int>    certificatesRepository    = new CertificateRepository(context);
            IRepository <Company, int>        companiesRepository       = new CompaniesRepository(context);
            IRepository <Equipment, int>      equipmentsRepository      = new EquipmentRepository(context);
            IRepository <Event, int>          eventsRepository          = new EventsRepository(context);
            IRepository <Game, int>           gamesRepository           = new GamesRepository(context);
            IRepository <GameType, int>       gameTypesRepository       = new GameTypesRepository(context);
            IRepository <News, int>           newsRepository            = new NewsRepository(context);
            IRepository <Operation, int>      operationsRepository      = new OperationsRepository(context);
            IRepository <Playground, int>     playgroundsRepository     = new PlaygroundsRepository(context);
            IRepository <Task, int>           tasksRepository           = new TasksRepository(context);
            IRepository <EquipmentOrder, int> equipmentOrdersRepository = new EquipmentOrdersRepository(context);
            UserStore <IdentityUser>          userStore = new UserStore <IdentityUser>(context);
            RoleStore <IdentityRole>          roleStore = new RoleStore <IdentityRole>(context);

            _loggingService = new TestLoggingService();

            _manager = new PaintballManager(context,
                                            certificatesRepository,
                                            companiesRepository,
                                            equipmentsRepository,
                                            eventsRepository,
                                            gamesRepository,
                                            gameTypesRepository,
                                            newsRepository,
                                            operationsRepository,
                                            playgroundsRepository,
                                            equipmentOrdersRepository,
                                            tasksRepository,
                                            userStore,
                                            roleStore,
                                            _loggingService
                                            );

            _firstUser = _manager.UserStore.Users.FirstOrDefault();
        }