Exemplo n.º 1
0
 public void AddPlayer(ITeam team, IList <IPerson> persons)
 {
     WithTransaction(() =>
     {
         foreach (var person in persons)
         {
             var assocation = team.AddPlayer(person);
             UnitOfWorks.Save(assocation);
         }
     });
 }
Exemplo n.º 2
0
 public void CreatePerson(string lastName, string firstName, string alias, string mail, bool canMailing, bool isMemberOfAssociation)
 {
     WithTransaction(() =>
     {
         var person        = Person.Create(lastName, firstName, alias);
         person.Mail       = mail;
         person.CanMailing = canMailing;
         person.IsMember   = isMemberOfAssociation;
         UnitOfWorks.Save(person);
     });
 }
Exemplo n.º 3
0
 private void WithTransaction(Action action)
 {
     try
     {
         UnitOfWorks.Begin();
         action();
         UnitOfWorks.Commit();
     }
     catch (Exception)
     {
         UnitOfWorks.Rollback();
         throw;
     }
 }
Exemplo n.º 4
0
        public void CreateTeam(IContest contest, string name, IList <IPerson> persons)
        {
            WithTransaction(() =>
            {
                var team = TeamFactory.Create(contest, name);
                UnitOfWorks.Save(team);

                foreach (var person in persons)
                {
                    var association = team.AddPlayer(person);
                    UnitOfWorks.Save(association);
                }
            });
        }
Exemplo n.º 5
0
 private T WithTransaction <T>(Func <T> action)
 {
     try
     {
         UnitOfWorks.Begin();
         var result = action();
         UnitOfWorks.Commit();
         return(result);
     }
     catch (Exception)
     {
         UnitOfWorks.Rollback();
         throw;
     }
 }
Exemplo n.º 6
0
        public void UpdateContest(IContest contest)
        {
            WithTransaction(() =>
            {
                UnitOfWorks.Save(contest.EliminationSetting.MatchSetting);
                UnitOfWorks.Save(contest.EliminationSetting);

                if (contest.QualificationSetting != null)
                {
                    UnitOfWorks.Save(contest.QualificationSetting.MatchSetting);
                    UnitOfWorks.Save(contest.QualificationSetting);
                }

                if (contest.ConsolingEliminationSetting != null)
                {
                    UnitOfWorks.Save(contest.ConsolingEliminationSetting.MatchSetting);
                    UnitOfWorks.Save(contest.ConsolingEliminationSetting);
                }
            });
        }
Exemplo n.º 7
0
        public IContest Create(CreateContestCmd cmd)
        {
            return(WithTransaction(() =>
            {
                var address = AddressFactory.Create(cmd.StreetNumber, cmd.Street, cmd.ZipCode, cmd.City);
                UnitOfWorks.Save(address);

                var areaType = cmd.Indoor ? AreaType.Indoor : AreaType.Outdoor;
                var physicalSettings = PhysicalSetting.Create(address, areaType, cmd.CountField);
                UnitOfWorks.Save(physicalSettings);

                var gameSetting = GameSettingFactory.Create(cmd.CountMinPlayerByTeam, cmd.CountMaxPlayerByTeam);
                UnitOfWorks.Save(gameSetting);

                var newContest = Domain.Games.Contest.Create(cmd.Date, physicalSettings, gameSetting);
                UnitOfWorks.Save(newContest.EliminationSetting.MatchSetting);
                UnitOfWorks.Save(newContest.EliminationSetting);
                UnitOfWorks.Save(newContest);

                return newContest;
            }));
        }
Exemplo n.º 8
0
        public void RemovePerson(IContest contest, IList <IPerson> persons)
        {
            WithTransaction(() =>
            {
                foreach (var person in persons)
                {
                    var team = person.GetTeam(contest);
                    if (team != null)
                    {
                        var association = team.RemovePlayer(person);
                        UnitOfWorks.Delete(association);

                        if (team.Members.Count != 0)
                        {
                            continue;
                        }

                        contest.UnRegister(team);
                        UnitOfWorks.Delete(team);
                    }
                    UnitOfWorks.Delete(person);
                }
            });
        }