public async Task <ActionResult> Create3(MatchEditorViewModel viewModel, string Command)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            if (Command == "Previous")
            {
                TempData["Create2"] = viewModel;
                return(RedirectToAction("Create2"));
            }

            if (Command == "Save")
            {
                var competitionV = await DbProvider.GetCompetition((Guid)viewModel.CompetitionGuid, viewModel.ViewDate);

                var campaignGuid = competitionV.Competition.Campaigns.Single(c => c.StartDate <= viewModel.MatchDate && c.EndDate > viewModel.MatchDate).PrimaryKey;

                var newMatchV = viewModel.ToMatchV(UserId, UserId, campaignGuid);
                var newMatch  = new Match()
                {
                    PrimaryKey = viewModel.HeaderKey
                };

                DbProvider.Add(newMatch);
                DbProvider.Add(newMatchV);
                DbProvider.SaveChanges();

                return(RedirectToDetailsIndex(newMatch.PrimaryKey));
            }

            return(View(viewModel));
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            DbProvider db = new DbProvider();

            Console.WriteLine("Hello");
            int i = 1;

            while (i != 0)
            {
                Console.WriteLine("\nPlease choose the following...\n\t1 - query all \n\t2 - insert data\n\t0 - exit");
                i = Int32.Parse(Console.ReadLine());
                switch (i)
                {
                case 1:
                    foreach (var item in db.QueryAll())
                    {
                        Console.WriteLine(String.Format("{0}-{1}", item.Id, item.Name));
                    }
                    break;

                case 2:
                    string temp = "NewName" + new Random().Next(1000);
                    db.Add(temp);
                    Console.WriteLine(String.Format("{0} was added to list", temp));
                    break;

                default:
                    break;
                }
            }
        }
Beispiel #3
0
        public ActionResult Create(PersonEditorViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var personV = viewModel.ToPersonV(UserId, UserId);

            DbProvider.Add(Person.Create <Person>());
            DbProvider.Add(personV);
            DbProvider.SaveChanges();

            return(RedirectToDetailsIndex(personV.HeaderKey));
        }
        public async Task <ActionResult> ManageCampaignStages(CompetitionCampaignStagesViewModel viewModel)
        {
            await SetModelsByPrimaryKey(viewModel);

            foreach (var item in viewModel.ManageCampaignStageViewModels)
            {
                if (item.IsNew)
                {
                    if (!string.IsNullOrWhiteSpace(item.Description))
                    {
                        DbProvider.Add(new CampaignStage()
                        {
                            PrimaryKey  = Guid.NewGuid(),
                            CampaignKey = viewModel.SelectedCampaignKey,
                            StageOrder  = item.StageOrder,
                            Description = item.Description,
                            IsDefault   = item.IsDefault,
                            IsLeague    = item.IsLeague,
                            LegCount    = item.LegCount
                        });
                    }
                }
                else
                {
                    var campaignStage = await DbProvider.GetCampaignStage(item.PrimaryKey);

                    if (string.IsNullOrWhiteSpace(item.Description))
                    {
                        DbProvider.Remove(campaignStage);
                    }
                    else
                    {
                        campaignStage.StageOrder  = item.StageOrder;
                        campaignStage.Description = item.Description;
                        campaignStage.IsDefault   = item.IsDefault;
                        campaignStage.IsLeague    = item.IsLeague;
                        campaignStage.LegCount    = item.LegCount;
                    }
                }
            }

            DbProvider.SaveChanges();

            return(RedirectToAction("ManageCampaignStages", new { pk = viewModel.ShortPrimaryKey, hk = viewModel.ShortHeaderKey, ck = viewModel.SelectedCampaignKey.ToShortGuid() }));
        }
        public ActionResult Create(VenueEditorViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var venueV = viewModel.ToVenueV(UserId, UserId);

            DbProvider.Add(new Venue()
            {
                PrimaryKey = viewModel.HeaderKey
            });
            DbProvider.Add(venueV);
            DbProvider.SaveChanges();

            return(RedirectToDetailsIndex(venueV.HeaderKey));
        }
        public async Task <ActionResult> ManageCampaigns(CompetitionManageCampaignsViewModel viewModel)
        {
            await SetModelsByPrimaryKey(viewModel);

            foreach (var item in viewModel.ManageCampaignViewModels)
            {
                if (!item.IsNew)
                {
                    var campaign = await DbProvider.GetCampaign(item.CampaignKey);

                    if (campaign == null)
                    {
                        continue;
                    }

                    if (item.StartDate == null && item.EndDate == null)
                    {
                        DbProvider.Remove(campaign);
                    }
                    else
                    {
                        item.StartDate = campaign.StartDate;
                        item.EndDate   = campaign.EndDate;
                    }
                }
                else
                {
                    if (item.StartDate != null && item.EndDate != null)
                    {
                        DbProvider.Add(new Campaign()
                        {
                            PrimaryKey     = Guid.NewGuid(),
                            CompetitionKey = viewModel.HeaderKey,
                            StartDate      = (DateTime)item.StartDate,
                            EndDate        = (DateTime)item.EndDate
                        });
                    }
                }
            }
            DbProvider.SaveChanges();

            return(RedirectToAction("ManageCampaigns", new { pk = viewModel.ShortPrimaryKey }));
        }
Beispiel #7
0
        public ActionResult Create(OrganisationEditorViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var organisationV = viewModel.ToOrganisationV(UserId, UserId);

            organisationV.EffectiveTo = Date.HighDate;
            DbProvider.Add(new Organisation()
            {
                PrimaryKey = organisationV.HeaderKey
            });
            DbProvider.Add(organisationV);
            DbProvider.SaveChanges();

            return(RedirectToDetailsIndex(organisationV.HeaderKey));
        }
Beispiel #8
0
        private Guid?AddImageData(HttpPostedFileBase imageData)
        {
            if (imageData == null)
            {
                return(null);
            }

            var imageBytes = imageData.ToBytes();

            var resourceGuid = Guid.NewGuid();
            var newResource  = new Resource()
            {
                PrimaryKey    = (Guid)resourceGuid,
                ResourceBytes = imageBytes
            };

            DbProvider.Add(newResource);

            return(resourceGuid);
        }
Beispiel #9
0
        public ActionResult Create(TeamEditorViewModel viewModel)
        {
            var validate = DoEditValidation(viewModel);

            if (validate != null)
            {
                return(validate);
            }

            var teamV = viewModel.ToTeamV(UserId, UserId);

            DbProvider.Add(new Team()
            {
                PrimaryKey = viewModel.HeaderKey
            });
            DbProvider.Add(teamV);
            DbProvider.SaveChanges();

            return(RedirectToDetailsIndex(teamV.PrimaryKey));
        }
        public ActionResult Create(CompetitionEditorViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var competitionV = viewModel.ToCompetitionV(UserId, UserId);

            competitionV.CampaignPeriodType  = PeriodType.Year;
            competitionV.CampaignPeriodValue = 1;

            DbProvider.Add(new Competition()
            {
                PrimaryKey = viewModel.HeaderKey
            });
            DbProvider.Add(competitionV);
            DbProvider.SaveChanges();

            return(RedirectToDetailsIndex(competitionV.HeaderKey));
        }
        public async Task <ActionResult> ManageLookupCampaignStages(CompetitionLookupCampaignStagesViewModel viewModel)
        {
            await SetModelsByPrimaryKey(viewModel);

            foreach (var item in viewModel.ManageLookupCampaignStageViewModels)
            {
                if (item.IsNew)
                {
                    if (item.ImportSite != null)
                    {
                        DbProvider.Add(new LookupCampaignStage()
                        {
                            PrimaryKey       = Guid.NewGuid(),
                            CampaignStageKey = viewModel.SelectedCampaignStageKey,
                            ImportSite       = (ImportSite)item.ImportSite,
                            LookupId         = item.LookupId
                        });
                    }
                }
                else
                {
                    var lookupCampaignStage = await DbProvider.GetLookupCampaignStage(item.PrimaryKey);

                    if (item.ImportSite == null)
                    {
                        DbProvider.Remove(lookupCampaignStage);
                    }
                    else
                    {
                        lookupCampaignStage.ImportSite = (ImportSite)item.ImportSite;
                        lookupCampaignStage.LookupId   = item.LookupId;
                    }
                }
            }

            DbProvider.SaveChanges();
            return(RedirectToAction("ManageLookupCampaignStages", new { pk = viewModel.ShortPrimaryKey, hk = viewModel.ShortHeaderKey, sk = viewModel.SelectedCampaignStageKey.ToShortGuid() }));
        }
        public async Task <ActionResult> ManageLookups(CompetitionManageLookupsViewModel viewModel)
        {
            foreach (var lookup in viewModel.LookupCompetitionViewModels)
            {
                var lookupEntity = await DbProvider.GetLookupCompetitionByPrimaryKey(lookup.PrimaryKey);

                if (lookupEntity != null)
                {
                    if (lookup.ImportSite == null)
                    {
                        DbProvider.Remove(lookupEntity);
                    }
                    else
                    {
                        lookupEntity.ImportSite = (ImportSite)lookup.ImportSite;
                        lookupEntity.LookupId   = lookup.LookupId.Trim();
                    }
                }
                else
                {
                    if (lookup.ImportSite != null)
                    {
                        DbProvider.Add(new LookupCompetition()
                        {
                            PrimaryKey      = Guid.NewGuid(),
                            ImportSite      = (ImportSite)lookup.ImportSite,
                            CompetitionGuid = lookup.CompetitionGuid,
                            LookupId        = lookup.LookupId.Trim()
                        });
                    }
                }
            }
            DbProvider.SaveChanges();

            return(RedirectToAction("ManageLookups", new { pk = viewModel.ShortPrimaryKey }));
        }
        public async Task <ActionResult> EditEvents(MatchPlayersEventsEditorViewModel viewModel)
        {
            await SetModelsByPrimaryKey(viewModel);

            if (viewModel.Team1MatchEventPersonViewModels != null)
            {
                foreach (var item in viewModel.Team1MatchEventPersonViewModels)
                {
                    var matchEvent = await DbProvider.GetMatchEventByPrimaryKey((Guid)item.PrimaryKey);

                    if (item.MatchEventInRunningType == null)
                    {
                        DbProvider.Remove(matchEvent);
                    }
                    else
                    {
                        UpdateMatchEvent(matchEvent, item);
                    }

                    DbProvider.SaveChanges();
                }
            }

            if (viewModel.Team2MatchEventPersonViewModels != null)
            {
                foreach (var item in viewModel.Team2MatchEventPersonViewModels)
                {
                    var matchEvent = await DbProvider.GetMatchEventByPrimaryKey((Guid)item.PrimaryKey);

                    if (item.MatchEventInRunningType == null)
                    {
                        DbProvider.Remove(matchEvent);
                    }
                    else
                    {
                        UpdateMatchEvent(matchEvent, item);
                    }

                    DbProvider.SaveChanges();
                }
            }

            if (viewModel.NewTeam1MatchEventPersonViewModel != null)
            {
                DbProvider.Add(new MatchEvent()
                {
                    PrimaryKey       = Guid.NewGuid(),
                    MatchVPrimaryKey = viewModel.PrimaryKey,
                    PersonPrimaryKey = (Guid)viewModel.NewTeam1MatchEventPersonViewModel.PersonPrimaryKey,
                    TeamPrimaryKey   = viewModel.VersionEntity.Team1Guid,
                    MatchEventType   = (MatchEventType)viewModel.NewTeam1MatchEventPersonViewModel.MatchEventInRunningType.ToMatchEventType(),
                    Minute           = viewModel.NewTeam1MatchEventPersonViewModel.Minute,
                    Extra            = viewModel.NewTeam1MatchEventPersonViewModel.Extra
                });

                DbProvider.SaveChanges();
            }

            if (viewModel.NewTeam2MatchEventPersonViewModel != null)
            {
                DbProvider.Add(new MatchEvent()
                {
                    PrimaryKey       = Guid.NewGuid(),
                    MatchVPrimaryKey = viewModel.PrimaryKey,
                    PersonPrimaryKey = (Guid)viewModel.NewTeam2MatchEventPersonViewModel.PersonPrimaryKey,
                    TeamPrimaryKey   = viewModel.VersionEntity.Team2Guid,
                    MatchEventType   = (MatchEventType)viewModel.NewTeam2MatchEventPersonViewModel.MatchEventInRunningType.ToMatchEventType(),
                    Minute           = viewModel.NewTeam2MatchEventPersonViewModel.Minute,
                    Extra            = viewModel.NewTeam2MatchEventPersonViewModel.Extra
                });

                DbProvider.SaveChanges();
            }

            return(RedirectToEditor("EditEvents", viewModel));
        }
        public async Task <ActionResult> Edit3(MatchEditorViewModel viewModel, string Command)
        {
            await SetModelsByPrimaryKey(viewModel);

            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            if (Command == "Previous")
            {
                TempData["MatchEditorViewModel"] = viewModel;
                return(RedirectToAction("Edit2"));
            }

            if (Command == "Save")
            {
                viewModel.MatchViewModels = viewModel.HeaderEntity.Versions.OrderByDescending(v => v.EffectiveFrom).ThenByDescending(v => v.IsActive).ToViewModels(DateTime.Now);

                var competitionV = await DbProvider.GetCompetition((Guid)viewModel.CompetitionGuid, viewModel.ViewDate);

                var campaignGuid = competitionV.Competition.Campaigns.Single(c => c.StartDate <= viewModel.MatchDate && c.EndDate > viewModel.MatchDate).PrimaryKey;

                var query = viewModel.HeaderEntity.GetApprovedVersionsByEffectiveDate <Match, MatchV>(Date.LowDate);

                if (query.Any())
                {
                    var entityV = query.Single();

                    if (viewModel.Equals(entityV))
                    {
                        ModelState.AddModelError(string.Empty, "No changes have been made.");
                        return(View(viewModel));
                    }

                    if (entityV.ModifiedUserId == UserId)
                    {
                        entityV.SetData(viewModel);
                        entityV.DateModified = DateTime.Now;

                        DbProvider.SaveChanges();
                        return(RedirectToEditor("Home", entityV));
                    }
                    else
                    {
                        entityV.IsActive = false;

                        var newEntityV = viewModel.ToMatchV(entityV.OwnerUserId, UserId, campaignGuid);
                        DbProvider.Add(newEntityV);

                        foreach (var matchEvent in entityV.MatchEvents)
                        {
                            var newMatchEvent = new MatchEvent()
                            {
                                PrimaryKey       = Guid.NewGuid(),
                                MatchVPrimaryKey = newEntityV.PrimaryKey,
                                TeamPrimaryKey   = matchEvent.TeamPrimaryKey,
                                PersonPrimaryKey = matchEvent.PersonPrimaryKey,
                                PositionType     = matchEvent.PositionType,
                                MatchEventType   = matchEvent.MatchEventType,
                                Minute           = matchEvent.Minute,
                                Extra            = matchEvent.Extra
                            };

                            DbProvider.Add(newMatchEvent);
                        }

                        DbProvider.SaveChanges();
                        return(RedirectToEditor("Home", newEntityV));
                    }
                }
            }

            return(View(viewModel));
        }
Beispiel #15
0
        public async Task <ActionResult> Edit(CountryEditorViewModel viewModel, HttpPostedFileBase imageData)
        {
            await SetModelsByPrimaryKey(viewModel);

            viewModel.EditableViewModels = viewModel.VersionEntity.Country.GetEditableVersions(DateTime.Now);

            var validate = DoEditValidation(viewModel);

            if (validate != null)
            {
                return(validate);
            }

            var resourceGuid = AddImageData(imageData);

            if (resourceGuid != null)
            {
                viewModel.ResourceGuid = resourceGuid;
            }

            var query = viewModel.HeaderEntity.GetApprovedVersionsByEffectiveDate <Country, CountryV>(viewModel.EffectiveFrom);

            if (query.Any())
            {
                var entityV = query.Single();

                if (viewModel.Equals(entityV))
                {
                    ModelState.AddModelError(string.Empty, "No changes have been made.");
                    return(View(viewModel));
                }

                if (entityV.ModifiedUserId == UserId)
                {
                    entityV.SetData(viewModel);
                    entityV.DateModified = DateTime.Now;

                    DbProvider.SaveChanges();
                    SetSaveChangesMessage(SaveChangesMessageType.ChangesSaved);
                    return(RedirectToEditor("Summary", entityV));
                }
                else
                {
                    entityV.IsActive = false;

                    var newEntityV = viewModel.ToCountryV(entityV.OwnerUserId, UserId);
                    newEntityV.EffectiveTo = viewModel.EffectiveTo;

                    DbProvider.Add(newEntityV);
                    DbProvider.SaveChanges();
                    SetSaveChangesMessage(SaveChangesMessageType.ChangesSaved);
                    return(RedirectToEditor("Summary", newEntityV));
                }
            }
            else
            {
                if (viewModel.Equals(viewModel.VersionEntity))
                {
                    ModelState.AddModelError("EffectiveFrom", "Only the effective date has changed.");
                    return(View(viewModel));
                }

                var newEntityV = viewModel.ToCountryV(UserId, UserId);
                newEntityV.EffectiveTo = Date.HighDate;

                DbProvider.Add(newEntityV);
                (await DbProvider.GetCountry(viewModel.HeaderKey, viewModel.ViewDate)).Country.NormaliseVersionEffectiveDates <CountryV>();
                DbProvider.SaveChanges();
                SetSaveChangesMessage(SaveChangesMessageType.ChangesSaved);
                return(RedirectToEditor("Summary", newEntityV));
            }
        }
        public async Task <ActionResult> EditPlayers(MatchPlayersEditorViewModel viewModel)
        {
            await SetModelsByPrimaryKey(viewModel);

            var teamGuid    = viewModel.TeamNumber == 1 ? viewModel.VersionEntity.Team1Guid : viewModel.VersionEntity.Team2Guid;
            var matchEvents = viewModel.VersionEntity.MatchEvents.Where(m => m.TeamPrimaryKey == teamGuid);

            if (viewModel.VersionEntity.ModifiedUserId == UserId)
            {
                if (viewModel.MatchPersonViewModels != null)
                {
                    foreach (var item in viewModel.MatchPersonViewModels)
                    {
                        if (item.MatchEventStartType == null)
                        {
                            var query = from m in matchEvents
                                        where m.PersonPrimaryKey == item.PersonGuid
                                        select m;

                            if (query.Any())
                            {
                                var primaryKey = query.First().PrimaryKey;
                                var header     = await DbProvider.GetMatchEventByPrimaryKey(primaryKey);

                                for (var i = query.Count() - 1; i >= 0; i--)
                                {
                                    DbProvider.Remove(query.ElementAt(i));
                                }

                                DbProvider.Remove(header);
                            }
                        }
                        else
                        {
                            var query = from m in matchEvents
                                        where m.PersonPrimaryKey == item.PersonGuid &&
                                        (m.MatchEventType == MatchEventType.Substitute || m.MatchEventType == MatchEventType.Started)
                                        select m;

                            if (query.Any())
                            {
                                query.First().MatchEventType = (MatchEventType)item.MatchEventStartType.ToMatchEventType();
                                query.First().PositionType   = item.PositionType;
                            }
                        }
                    }
                }

                if (viewModel.NewMatchPersonViewModels != null)
                {
                    foreach (var item in viewModel.NewMatchPersonViewModels.Where(m => m.MatchEventStartType != null))
                    {
                        DbProvider.Add(new MatchEvent()
                        {
                            PrimaryKey       = Guid.NewGuid(),
                            MatchVPrimaryKey = viewModel.PrimaryKey,
                            PersonPrimaryKey = item.PersonGuid,
                            PositionType     = item.PositionType,
                            TeamPrimaryKey   = teamGuid,
                            MatchEventType   = (MatchEventType)item.MatchEventStartType.ToMatchEventType(),
                            Minute           = null,
                            Extra            = null
                        });
                    }
                }

                DbProvider.SaveChanges();

                return(RedirectToAction("EditPlayers", new { hk = viewModel.ShortHeaderKey, pk = viewModel.ShortPrimaryKey, tm = viewModel.TeamNumber }));
            }
            else
            {
                var previousVersion = await DbProvider.GetMatch(viewModel.VersionEntity.PrimaryKey, viewModel.VersionEntity.HeaderKey);

                var newMatchV = MatchV.CreateNewVersion <MatchV>(previousVersion.OwnerUserId, UserId);
                newMatchV.HeaderKey   = previousVersion.HeaderKey;
                newMatchV.DateCreated = previousVersion.DateCreated;
                newMatchV.SetData(previousVersion);

                foreach (var matchEvent in previousVersion.MatchEvents)
                {
                    var newMatchEvent = new MatchEvent()
                    {
                        PrimaryKey       = Guid.NewGuid(),
                        MatchVPrimaryKey = newMatchV.PrimaryKey,
                        TeamPrimaryKey   = matchEvent.TeamPrimaryKey,
                        PersonPrimaryKey = matchEvent.PersonPrimaryKey,
                        PositionType     = matchEvent.PositionType,
                        MatchEventType   = matchEvent.MatchEventType,
                        Minute           = matchEvent.Minute,
                        Extra            = matchEvent.Extra
                    };

                    DbProvider.Add(newMatchEvent);
                }

                DbProvider.SaveChanges();

                return(RedirectToAction("EditPlayers", new { hk = newMatchV.HeaderKey.ToShortGuid(), pk = newMatchV.PrimaryKey.ToShortGuid(), tm = viewModel.TeamNumber }));
            }
        }
Beispiel #17
0
        public async Task <ActionResult> Edit(OrganisationEditorViewModel viewModel)
        {
            await SetModelsByPrimaryKey(viewModel);

            viewModel.EditableViewModels = viewModel.VersionEntity.Organisation.GetEditableVersions(DateTime.Now);

            var validate = DoEditValidation(viewModel);

            if (validate != null)
            {
                return(validate);
            }

            var query = viewModel.HeaderEntity.GetApprovedVersionsByEffectiveDate <Organisation, OrganisationV>(viewModel.EffectiveFrom);

            if (query.Any())
            {
                var entityV = query.Single();

                if (viewModel.Equals(entityV))
                {
                    ModelState.AddModelError(string.Empty, "No changes have been made.");
                    return(View(viewModel));
                }

                if (entityV.ModifiedUserId == UserId)
                {
                    entityV.SetData(viewModel);
                    entityV.DateModified = DateTime.Now;

                    DbProvider.SaveChanges();
                    SetSaveChangesMessage(SaveChangesMessageType.ChangesSaved);
                    return(RedirectToAction("Summary", new { hk = entityV.HeaderKey.ToShortGuid(), pk = entityV.PrimaryKey.ToShortGuid() }));
                }
                else
                {
                    entityV.IsActive = false;

                    var newEntityV = viewModel.ToOrganisationV(entityV.OwnerUserId, UserId);
                    newEntityV.EffectiveTo = viewModel.EffectiveTo;

                    DbProvider.Add(newEntityV);

                    DbProvider.SaveChanges();
                    SetSaveChangesMessage(SaveChangesMessageType.ChangesSaved);
                    return(RedirectToAction("Summary", new { hk = newEntityV.HeaderKey.ToShortGuid(), pk = newEntityV.PrimaryKey.ToShortGuid() }));
                }
            }
            else
            {
                if (viewModel.Equals(viewModel.VersionEntity))
                {
                    ModelState.AddModelError("EffectiveFrom", "Only the effective date has changed.");
                    return(View(viewModel));
                }

                var newEntityV = viewModel.ToOrganisationV(UserId, UserId);
                newEntityV.EffectiveTo = Date.HighDate;

                DbProvider.Add(newEntityV);
                viewModel.HeaderEntity.NormaliseVersionEffectiveDates <OrganisationV>();

                DbProvider.SaveChanges();
                SetSaveChangesMessage(SaveChangesMessageType.ChangesSaved);
                return(RedirectToAction("Summary", new { hk = newEntityV.HeaderKey.ToShortGuid(), pk = newEntityV.PrimaryKey.ToShortGuid() }));
            }
        }
        public async Task <ActionResult> ManageTeamLookups(CountryManageTeamLookupsViewModel viewModel)
        {
            await SetModelsByPrimaryKey(viewModel);

            foreach (var teamLookupViewModel in viewModel.TeamLookupsViewModels)
            {
                var espnLookup = await DbProvider.GetLookupTeam(teamLookupViewModel.TeamKey, ImportSite.Espn);

                if (espnLookup != null)
                {
                    if (string.IsNullOrWhiteSpace(teamLookupViewModel.EspnLookupId))
                    {
                        DbProvider.Remove(espnLookup);
                    }
                    else
                    {
                        espnLookup.LookupId = teamLookupViewModel.EspnLookupId;
                    }
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(teamLookupViewModel.EspnLookupId))
                    {
                        DbProvider.Add(new LookupTeam()
                        {
                            PrimaryKey = Guid.NewGuid(),
                            TeamGuid   = teamLookupViewModel.TeamKey,
                            ImportSite = ImportSite.Espn,
                            LookupId   = teamLookupViewModel.EspnLookupId
                        });
                    }
                }

                var soccerbaseLookup = await DbProvider.GetLookupTeam(teamLookupViewModel.TeamKey, ImportSite.Soccerbase);

                if (soccerbaseLookup != null)
                {
                    if (string.IsNullOrWhiteSpace(teamLookupViewModel.SoccerbaseLookupId))
                    {
                        DbProvider.Remove(soccerbaseLookup);
                    }
                    else
                    {
                        soccerbaseLookup.LookupId = teamLookupViewModel.SoccerbaseLookupId;
                    }
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(teamLookupViewModel.SoccerbaseLookupId))
                    {
                        DbProvider.Add(new LookupTeam()
                        {
                            PrimaryKey = Guid.NewGuid(),
                            TeamGuid   = teamLookupViewModel.TeamKey,
                            ImportSite = ImportSite.Soccerbase,
                            LookupId   = teamLookupViewModel.SoccerbaseLookupId
                        });
                    }
                }
            }
            DbProvider.SaveChanges();

            return(RedirectToAction("ManageTeamLookups", new { hk = viewModel.ShortHeaderKey, dt = viewModel.ViewDate.ToUrlString() }));
        }