예제 #1
0
 /// <summary>
 /// 创建工夹具类别(可用于修改?)
 /// </summary>
 /// <returns></returns>
 public ActionResult CreatFixture(string name)
 {
     //商量:除名字外,应该同时填写绝大部分类别信息
     //TODO:创建相应工夹具类别
     Models.Fixture fixture = new Models.Fixture
     {
         name = name,
     };
     return(View());
 }
예제 #2
0
        public async Task <IActionResult> CreateBatch([FromBody] List <FixtureParticipantsModel> model)
        {
            try
            {
                // create player dto from model and save if key is new
                bool dochange = false;
                foreach (var p in model)
                {
                    if (!_context.Fixtures.Any(x => x.Key == p.FixtureKey))
                    {
                        dochange = true;
                        var fixture = new Models.Fixture()
                        {
                            Key         = p.FixtureKey,
                            SeasonKey   = p.SeasonKey,
                            HomeClubKey = p.HomeClubKey,
                            AwayClubKey = p.AwayClubKey,
                            KickOffTime = p.KickOffTime,
                            FinalScore  = p.FinalScore,
                        };
                        _context.Fixtures.Add(fixture);
                        await _fixturebus.SendEvent(BuildNewFixtureEvent(p.FixtureKey, p.RegionKey, p.TournamentKey));
                    }
                    if (!_context.ClubFixtureAppearances.Any(x => x.FixtureKey == p.FixtureKey &&
                                                             x.ClubKey == p.HomeClubKey &&
                                                             x.IsHomeTeam))
                    {
                        dochange = true;
                        var homeassociation = new ClubFixtureAppearance()
                        {
                            ClubKey       = p.HomeClubKey,
                            SeasonKey     = p.SeasonKey,
                            FixtureKey    = p.FixtureKey,
                            GoalsScored   = p.HomeGoalsScored,
                            GoalsConceded = p.HomeGoalsConceded,
                            IsHomeTeam    = true
                        };
                        _context.ClubFixtureAppearances.Add(homeassociation);
                    }
                    if (!_context.ClubFixtureAppearances.Any(x => x.FixtureKey == p.FixtureKey &&
                                                             x.ClubKey == p.AwayClubKey &&
                                                             !x.IsHomeTeam))
                    {
                        dochange = true;
                        var awayassociation = new ClubFixtureAppearance()
                        {
                            ClubKey       = p.AwayClubKey,
                            SeasonKey     = p.SeasonKey,
                            FixtureKey    = p.FixtureKey,
                            GoalsScored   = p.AwayGoalsScored,
                            GoalsConceded = p.AwayGoalsConceded,
                            IsHomeTeam    = false
                        };
                        _context.ClubFixtureAppearances.Add(awayassociation);
                    }
                }
                if (dochange)
                {
                    await _context.SaveChangesAsync();
                }
                return(Ok());
            }
            catch (DbUpdateException pkex)
            {
                // TODO: we are seeing this occaisionally due to async processing from multiple instances
                //       its ok to swallow as we dont support data updates and if the key exists there is no need for dupe store

                return(Conflict($"A primary key violation occured while saving player data: { pkex.Message }"));
            }
        }