コード例 #1
0
ファイル: GameServicesTest.cs プロジェクト: innerjoin/dog2go
        public void TestGetPartnerNotInitializedUser()
        {
            User partner = ParticipationService.GetPartner(null,
                                                           null);

            Assert.AreEqual(null, partner);
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "PSId,PTranspotation,POtherInput,POtherInput2,POtherInput3,PJobTrain,PEducationAssistance,PResidentialCare,PUtilities,PHousingEmergency,PHousingAssistance,PChildCare,PClothing,PFood,PSupplies,POther,POther2,POther3,PTotals,Region,Month,SubcontractorId,Year,SubmittedDate")] ParticipationService participationService)
        {
            if (ModelState.IsValid)
            {
                var dataexist = from s in db.ParticipationServices
                                where
                                s.SubcontractorId == participationService.SubcontractorId &&
                                s.Year == participationService.Year &&
                                s.Month == participationService.Month
                                select s;
                if (dataexist.Count() >= 1)
                {
                    ViewBag.error = "Data already exists. Please change the params or search in the Reports tab for the current Record.";
                }
                else
                {
                    participationService.PSId          = Guid.NewGuid();
                    participationService.SubmittedDate = DateTime.Now;
                    db.ParticipationServices.Add(participationService);
                    participationService.Region = db.SubContractors.Where(A => A.SubcontractorId == participationService.SubcontractorId).FirstOrDefault().Region;

                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }

            var datelist = Enumerable.Range(System.DateTime.Now.Year - 1, 5).ToList();

            ViewBag.Year            = new SelectList(datelist);
            ViewBag.SubcontractorId = new SelectList(db.SubContractors.OrderBy(a => a.OrgName), "SubcontractorId", "OrgName", participationService.SubcontractorId);
            return(View(participationService));
        }
コード例 #3
0
ファイル: GameHub.cs プロジェクト: innerjoin/dog2go
        private void NotifyActualPlayer(User user, List <HandCard> handCards, int tableId)
        {
            GameTable       actualGameTable = GameTableService.GetTable(Games, tableId);
            List <HandCard> validCards      = actualGameTable.CardServiceData.ProveCards(handCards, actualGameTable, user);
            IHubContext     context         = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();

            if (validCards.Find(card => card.IsValid) != null)
            {
                Task firstTask = context.Clients.Group(tableId.ToString(), user.ConnectionIds.ToArray()).broadcastSystemMessage(ServerMessages.InformOtherPlayer.Replace("{0}", user.Nickname), tableId, DateTime.Now.Ticks + GetMessageCounter());
                firstTask.Wait();
                actualGameTable.ActualParticipation = ParticipationService.GetParticipation(actualGameTable, user.Nickname);
                user.ConnectionIds.ForEach(cId =>
                {
                    Task task = context.Clients.Client(cId).broadcastSystemMessage(ServerMessages.NofityActualPlayer, actualGameTable.Identifier, DateTime.Now.Ticks + GetMessageCounter());
                    task.Wait();
                    ColorCode colorCode = GameTableService.GetColorCodeForUser(Games, GameTableService.AreAllEndFieldsUsedForColorCode(actualGameTable,
                                                                                                                                       GameTableService.GetColorCodeForUser(Games, user.Nickname, tableId)) ?
                                                                               ParticipationService.GetPartner(user, actualGameTable.Participations).Nickname : user.Nickname, tableId);
                    Clients.Client(cId).notifyActualPlayer(validCards, colorCode, tableId);
                });
            }
            else
            {
                NotifyNextPlayer("", actualGameTable);
            }
        }
コード例 #4
0
ファイル: GameServicesTest.cs プロジェクト: innerjoin/dog2go
        public void TestGetNextPlayerNotInitalizedGameTable()
        {
            GameTable table = MakeInitialGameTable;
            string    user  = ParticipationService.GetNextPlayer(null, "user1");

            Assert.AreEqual(true, user == null);
        }
コード例 #5
0
ファイル: GameServicesTest.cs プロジェクト: innerjoin/dog2go
        public void TestGetNextPlayerNonExistentUser()
        {
            GameTable table = MakeInitialGameTable;
            string    user  = ParticipationService.GetNextPlayer(table, "user5");

            Assert.AreEqual(true, user == null);
        }
コード例 #6
0
 public FormationController()
 {
     MyUser                 = new UserService();
     MyFormationService     = new FormationService();
     MyEnfantService        = new EnfantService();
     MyParticipationService = new ParticipationService();
     MyActiviteService      = new ActiviteService();
 }
コード例 #7
0
ファイル: GameServicesTest.cs プロジェクト: innerjoin/dog2go
        public void TestGetPartnerNotInitializedParticipation()
        {
            User user = new User("test_user", "4");

            User partner = ParticipationService.GetPartner(user,
                                                           null);

            Assert.AreEqual(null, partner);
        }
コード例 #8
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            ParticipationService participationService = db.ParticipationServices

                                                        .Include(a => a.Subcontractor)
                                                        .SingleOrDefault(a => a.PSId == id);

            db.ParticipationServices.Remove(participationService);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #9
0
ファイル: GameController.cs プロジェクト: innerjoin/dog2go
        private bool AddParticipantToTable(int tableId)
        {
            List <GameTable> gameTableList = GameRepository.Instance.Get();
            GameTable        gameTable     = gameTableList?.Find(table => table.Identifier.Equals(tableId));

            if (ParticipationService.IsAlreadyParticipating(gameTable, User.Identity.Name))
            {
                return(true);
            }
            return(ParticipationService.AddParticipation(gameTable, User.Identity.Name));
        }
コード例 #10
0
ファイル: GameHub.cs プロジェクト: innerjoin/dog2go
        // this method is not used yet, as initial card excchange has not been implemented
        public void ChooseCardExchange(HandCard selectedCard, int tableId)
        {
            GameTable actualGameTable = GameTableService.GetTable(Games, tableId);
            User      actualUser      = actualGameTable.Participations.Find(participation => participation.Participant.Identifier == Context.User.Identity.Name).Participant;

            actualGameTable.CardServiceData.CardExchange(actualUser, ref actualGameTable, selectedCard);
            User partnerUser = ParticipationService.GetPartner(actualUser, actualGameTable.Participations);

            partnerUser.ConnectionIds.ForEach(id =>
            {
                Clients.Client(id).exchangeCard(selectedCard);
            });
        }
コード例 #11
0
        public async Task ParticipationService_Add_ShouldExecuteWithSuccess()
        {
            // Arrange
            var participation        = participationValid;
            var participationRepo    = new Mock <IParticipationRepository>();
            var notificationRepo     = new Mock <INotificator>();
            var participationService = new ParticipationService(participationRepo.Object, notificationRepo.Object);

            // Act
            await participationService.Add(participation);

            // Assert
            Assert.True(participation.IsValid());
            participationRepo.Verify(r => r.Add(participation), Times.Once);
        }
コード例 #12
0
        public ActionResult Edit([Bind(Include = "PSId,PTranspotation,POtherInput,POtherInput2,POtherInput3,PJobTrain,PEducationAssistance,PResidentialCare,PUtilities,PHousingEmergency,PHousingAssistance,PChildCare,PClothing,PFood,PSupplies,POther,POther2,POther3,PTotals,Region,Month,SubcontractorId,Year,SubmittedDate")] ParticipationService participationService)
        {
            if (ModelState.IsValid)
            {
                participationService.SubmittedDate   = DateTime.Now;
                db.Entry(participationService).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            var datelist = Enumerable.Range(System.DateTime.Now.Year - 1, 5).ToList();

            ViewBag.Year            = new SelectList(datelist);
            ViewBag.SubcontractorId = new SelectList(db.SubContractors.OrderBy(a => a.OrgName), "SubcontractorId", "OrgName", participationService.SubcontractorId);
            return(View(participationService));
        }
コード例 #13
0
        public async Task ParticipationService_Add_ShouldExecuteWithFailAsync()
        {
            // Arrange
            var participation        = participationInvalid;
            var participationRepo    = new Mock <IParticipationRepository>();
            var notificationRepo     = new Mock <INotificator>();
            var participationService = new ParticipationService(participationRepo.Object, notificationRepo.Object);

            // Act
            await participationService.Add(participation);

            // Assert
            Assert.False(participation.IsValid());
            participationRepo.Verify(r => r.Add(participation), Times.Never);
            notificationRepo.Verify(r => r.Handle(It.IsAny <Notification>()), Times.AtLeastOnce);
        }
コード例 #14
0
ファイル: GameServicesTest.cs プロジェクト: innerjoin/dog2go
        public void TestGetNextPlayerCorrectlyInitialized()
        {
            GameTable table = MakeInitialGameTable;
            string    user2 = ParticipationService.GetNextPlayer(table, "user1");

            Assert.AreEqual(true, user2.Equals("user2"));
            string user3 = ParticipationService.GetNextPlayer(table, "user2");

            Assert.AreEqual(true, user3.Equals("user3"));
            string user4 = ParticipationService.GetNextPlayer(table, "user3");

            Assert.AreEqual(true, user4.Equals("user4"));
            string user1 = ParticipationService.GetNextPlayer(table, "user4");

            Assert.AreEqual(true, user1.Equals("user1"));
        }
コード例 #15
0
        public async override void Run()
        {
            if (this.IsShuttingDown || this.Pause)
            {
                return;
            }

            var db = new SportsSystemDbContext();

            var participationService = new ParticipationService(db);

            var representativeUsers = await participationService.GetDeniedUsersNotification();



            //Prepare Postal classes to work outside of ASP.NET request
            var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails"));
            var engines   = new ViewEngineCollection();

            engines.Add(new FileSystemRazorViewEngine(viewsPath));



            var emailService = new EmailService(engines);

            foreach (var competition in representativeUsers)
            {
                var email = new DeniedUsersNotifications
                {
                    ViewName        = "DeniedUsers",
                    From            = "*****@*****.**",
                    EndDate         = competition.EndDate,
                    CompetitionName = competition.CompetitionName,
                    Subject         = string.Format("رفع اشکالات مشخصات وارد شده {0}", competition.CompetitionName),
                    To                    = competition.Email,
                    FirstName             = competition.FirstName,
                    LastName              = competition.LastName,
                    University            = competition.University,
                    DeniedCompetitors     = competition.DeniedCompetitors,
                    DeniedTechnicalStaffs = competition.DeniedTechnicalStaffs
                };

                await emailService.SendAsync(email);
            }

            db.Dispose();
        }
コード例 #16
0
        // GET: ParticipationCost/Delete/5
        public ActionResult Delete(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ParticipationService participationService = db.ParticipationServices

                                                        .Include(a => a.Subcontractor)
                                                        .SingleOrDefault(a => a.PSId == id);

            if (participationService == null)
            {
                return(HttpNotFound());
            }
            return(View(participationService));
        }
コード例 #17
0
        // GET: ParticipationCost/Edit/5
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ParticipationService participationService = db.ParticipationServices.Find(id);

            if (participationService == null)
            {
                return(HttpNotFound());
            }

            var datelist = Enumerable.Range(System.DateTime.Now.Year - 1, 5).ToList();

            ViewBag.Year            = new SelectList(datelist);
            ViewBag.SubcontractorId = new SelectList(db.SubContractors.OrderBy(a => a.OrgName).Where(a => a.SubcontractorId == participationService.SubcontractorId), "SubcontractorId", "OrgName");
            return(View(participationService));
        }
コード例 #18
0
ファイル: GameServicesTest.cs プロジェクト: innerjoin/dog2go
        public void TestGetPartnerCorrectlyInitialized()
        {
            GameTable table = MakeInitialGameTable;
            User      user1 = table.Participations.Find(participation => participation.Participant.Nickname == "user1").Participant;
            User      user3 = table.Participations.Find(participation => participation.Participant.Nickname == "user3").Participant;

            User partner1 = ParticipationService.GetPartner(
                table.Participations.Find(participation => participation.Participant.Nickname == "user1").Participant,
                table.Participations);

            User partner3 = ParticipationService.GetPartner(
                table.Participations.Find(participation => participation.Participant.Nickname == "user3").Participant,
                table.Participations);

            if (user1.Identifier == partner3.Identifier && user3.Identifier == partner1.Identifier)
            {
                Assert.AreEqual(true, true);
            }
            else
            {
                Assert.AreEqual(true, false);
            }
        }
コード例 #19
0
ファイル: GameHub.cs プロジェクト: innerjoin/dog2go
        public GameTable ConnectToTable(int gameTableId)
        {
            lock (Locker)
            {
                GameTable       table   = GameTableService.GetTable(Games, gameTableId);
                string          curUser = Context.User.Identity.Name;
                List <HandCard> cards   = null;

                if (GameTableService.AlreadyConnected(table, curUser))
                {
                    Participation participation = ParticipationService.GetParticipation(table, curUser);

                    if (table.Participations.Count == GlobalDefinitions.NofParticipantsPerTable && !table.IsInitialized)
                    {
                        AllConnected(table);
                        Clients.Client(Context.ConnectionId).createGameTable(table, table.Identifier);
                    }
                    else
                    {
                        cards = table.CardServiceData?.GetActualHandCards(participation.Participant, table);
                        Task task = Clients.Client(Context.ConnectionId).backToGame(table, cards, table.Identifier);
                        task.Wait();
                    }
                    if (table.ActualParticipation == participation)
                    {
                        NotifyActualPlayer(participation.Participant, cards, table.Identifier);
                    }
                }
                else
                {
                    ParticipationService.AddParticipation(table, curUser);
                    Clients.Client(Context.ConnectionId).createGameTable(table);
                }
                return(table);
            }
        }
コード例 #20
0
 public void Clean()
 {
     _participationRepository = null;
     _sut = null;
 }
コード例 #21
0
ファイル: GameHub.cs プロジェクト: innerjoin/dog2go
        private void NotifyNextPlayer(string nextUserName, GameTable actualGameTable)
        {
            string nextPlayerNickname;

            if (string.IsNullOrWhiteSpace(nextUserName))
            {
                nextPlayerNickname = ParticipationService.GetNextPlayer(actualGameTable, Context.User.Identity.Name);
            }
            else
            {
                nextPlayerNickname = nextUserName;
            }
            User            nextUser       = UserRepository.Instance.Get().FirstOrDefault(user => user.Value.Nickname == nextPlayerNickname).Value;
            List <HandCard> cards          = actualGameTable.CardServiceData.GetActualHandCards(nextUser, actualGameTable);
            List <HandCard> validHandCards = actualGameTable.CardServiceData.ProveCards(cards, actualGameTable, nextUser);
            IHubContext     context        = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();

            actualGameTable.ActualParticipation = ParticipationService.GetParticipation(actualGameTable, nextUser.Nickname);
            Task task = context.Clients.Group(actualGameTable.Identifier.ToString(), nextUser.ConnectionIds.ToArray()).broadcastSystemMessage(ServerMessages.InformOtherPlayer.Replace("{0}", nextUser.Nickname), actualGameTable.Identifier, DateTime.Now.Ticks + GetMessageCounter());

            task.Wait();
            if (validHandCards.Count > 0 && validHandCards.Find(card => card.IsValid) == null)
            {
                if (!nextUser.CardDropped)
                {
                    context.Clients.Group(actualGameTable.Identifier.ToString(), nextUser.ConnectionIds.ToArray()).broadcastStateMessage(ServerMessages.NoValidCardAvailable.Replace("{0}", nextUser.Nickname), actualGameTable.Identifier, DateTime.Now.Ticks + GetMessageCounter());
                    nextUser.ConnectionIds.ForEach(id => context.Clients.Client(id).broadcastStateMessage(ServerMessages.YourCardsHaveBeenDropped, actualGameTable.Identifier, DateTime.Now.Ticks + GetMessageCounter()));
                }
            }

            nextUser.ConnectionIds.ForEach(id =>
            {
                if (validHandCards.Find(card => card.IsValid) != null)
                {
                    Task chatTask = context.Clients.Client(id).broadcastSystemMessage(ServerMessages.NofityActualPlayer, actualGameTable.Identifier, DateTime.Now.Ticks + GetMessageCounter());
                    chatTask.Wait();
                    ColorCode colorCode = GameTableService.GetColorCodeForUser(Games, GameTableService.AreAllEndFieldsUsedForColorCode(actualGameTable,
                                                                                                                                       GameTableService.GetColorCodeForUser(Games, nextUser.Nickname, actualGameTable.Identifier)) ?
                                                                               ParticipationService.GetPartner(nextUser, actualGameTable.Participations).Nickname : nextUser.Nickname, actualGameTable.Identifier);
                    Clients.Client(id).notifyActualPlayer(validHandCards, colorCode, actualGameTable.Identifier);
                }
                else
                {
                    actualGameTable.CardServiceData.RemoveAllCardsFromUser(actualGameTable, nextUser);
                    nextUser.CardDropped = true;
                    Clients.Client(id).dropCards(actualGameTable.Identifier);

                    if (actualGameTable.CardServiceData.ProveCardsCount % GlobalDefinitions.NofParticipantsPerTable != 0)
                    {
                        NotifyNextPlayer(ParticipationService.GetNextPlayer(actualGameTable, nextUser.Nickname), actualGameTable);
                        return;
                    }

                    if (!actualGameTable.CardServiceData.AreCardsOnHand(actualGameTable))
                    {
                        SendCardsForRound(actualGameTable);
                    }
                    else
                    {
                        NotifyNextPlayer(ParticipationService.GetNextPlayer(actualGameTable, nextUser.Nickname), actualGameTable);
                    }
                }
            });
        }
コード例 #22
0
 public EditModel(CompetitionService comptetionService, ParticipationService participationService, UserService userService)
 {
     _competitionService   = comptetionService;
     _participationService = participationService;
     _userService          = userService;
 }
コード例 #23
0
 public void Setup()
 {
     _participationRepository = new Mock <IParticipationRepository>();
     _sut    = new ParticipationService(_participationRepository.Object);
     _siteId = Guid.NewGuid();
 }