public async System.Threading.Tasks.Task <OperationResult <GameType> > CreateGameType(GameType gameType) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <GameType> >(() => { OperationResult <GameType> result = new OperationResult <GameType>(); try { if (IsInCompany()) { gameType.CompanyId = CurrentUser.CompanyId.Value; GameType newGameType = GameTypesRepository.CreateOrUpdate(gameType); if (newGameType.Id > 0) { result.SingleResult = newGameType; result.Result = true; } } } catch (Exception ex) { LoggingService.Log(ex); } return result; })); }
public async System.Threading.Tasks.Task <OperationResult <GameType> > GetGameTypes(int pageSize, int pageNumber, bool descending) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <GameType> >(() => { OperationResult <GameType> result = new OperationResult <GameType>(); try { if (IsInCompany()) { result.Count = GameTypesRepository.Count("CompanyId = @CompanyId", new { CompanyId = CurrentUser.CompanyId.Value }); if (result.Count > 0) { result.MultipleResult = GameTypesRepository.Search("CompanyId = @CompanyId", new { PageSize = pageSize, PageNumber = pageNumber, CompanyId = CurrentUser.CompanyId.Value }, descending); } result.Result = true; } } catch (Exception ex) { LoggingService.Log(ex); } return result; })); }
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 async System.Threading.Tasks.Task <OperationResult <MyGameReponseSingle> > GetMyGames(int pageSize, int pageNumber, bool descending) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <MyGameReponseSingle> >(() => { OperationResult <MyGameReponseSingle> result = new OperationResult <MyGameReponseSingle>(); try { result.Count = GamesRepository.Count("CreatorId = @CreatorId", new { CreatorId = CurrentUser.Id }); if (result.Count > 0) { List <MyGameReponseSingle> response = new List <MyGameReponseSingle>(); var games = GamesRepository.Search("CreatorId = @CreatorId", new { PageSize = pageSize, PageNumber = pageNumber, CreatorId = CurrentUser.Id }, descending); foreach (var game in games) { MyGameReponseSingle single = new MyGameReponseSingle(); single.Game = game; single.Playground = PlaygroundsRepository.Read(game.Playground); single.GameType = GameTypesRepository.Read(game.GameType); response.Add(single); } result.MultipleResult = response; } result.Result = true; } catch (Exception ex) { LoggingService.Log(ex); } return result; })); }
public async System.Threading.Tasks.Task <OperationResult <OrderResponse> > GetCompanyForOrder(int id) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <OrderResponse> >(() => { OperationResult <OrderResponse> result = new OperationResult <OrderResponse>(); try { var company = CompaniesRepository.Read(id); if (company != null) { company.OwnerId = Guid.Empty; company.Description = ""; company.LogoImage = ""; var playgrounds = PlaygroundsRepository.Search("CompanyId = @CompanyId", new { PageNumber = 1, PageSize = 100, CompanyId = company.Id }); var gameTypes = GameTypesRepository.Search("CompanyId = @CompanyId", new { PageNumber = 1, PageSize = 100, CompanyId = company.Id }); var equipment = EquipmentsRepository.Search("CompanyId = @CompanyId", new { PageNumber = 1, PageSize = 100, CompanyId = company.Id }); foreach (var equip in equipment) { equip.State = ""; } result.SingleResult = new OrderResponse { Company = company, Playgrounds = playgrounds, GameTypes = gameTypes, Equipment = equipment }; result.Result = true; } } catch (Exception ex) { LoggingService.Log(ex); } return result; })); }
public async System.Threading.Tasks.Task <OperationResult <GameType> > UpdateGameType(GameType gameType) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <GameType> >(() => { OperationResult <GameType> result = new OperationResult <GameType>(); try { if (IsInCompany(gameType.CompanyId)) { result.Result = GameTypesRepository.Update(gameType); } } 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(); }
public async System.Threading.Tasks.Task <OperationResult <GameType> > DeleteGameType(int id) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <GameType> >(() => { OperationResult <GameType> result = new OperationResult <GameType>(); try { GameType gameType = GameTypesRepository.Read(id); if (gameType != null) { if (IsInCompany(gameType.CompanyId)) { result.Result = GameTypesRepository.Delete(id); } } } catch (Exception ex) { LoggingService.Log(ex); } return result; })); }
public async System.Threading.Tasks.Task <OperationResult <MyGameReponseSingle> > GetMyGames(DateTime date, int pageSize, int pageNumber, bool descending) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <MyGameReponseSingle> >(() => { OperationResult <MyGameReponseSingle> result = new OperationResult <MyGameReponseSingle>(); try { DateTime startDate = new DateTime(date.Year, date.Month, date.Day, 0, 0, 0); DateTime endDate = new DateTime(date.Year, date.Month, date.Day, 23, 59, 59); result.Count = GamesRepository.Count("CreatorId = @CreatorId AND BeginDate BETWEEN @StartDate AND @EndDate", new { CreatorId = CurrentUser.Id, StartDate = startDate, EndDate = endDate }); if (result.Count > 0) { List <MyGameReponseSingle> response = new List <MyGameReponseSingle>(); var games = GamesRepository.Search("CreatorId = @CreatorId AND BeginDate BETWEEN @StartDate AND @EndDate", new { PageSize = pageSize, PageNumber = pageNumber, CreatorId = CurrentUser.Id, StartDate = startDate, EndDate = endDate }); foreach (var game in games) { MyGameReponseSingle single = new MyGameReponseSingle(); single.Game = game; single.Playground = PlaygroundsRepository.Read(game.Playground); single.GameType = GameTypesRepository.Read(game.GameType); response.Add(single); } result.MultipleResult = response; } result.Result = true; } catch (Exception ex) { LoggingService.Log(ex); } return result; })); }