public async Task OnGet()
        {
            Models.ScheduleSyncSpec spec = _dbContext.ScheduleSyncSpecs.Where(x => x.ID == SpecID && x.TeamSnapUserId == User.GetTeamSnapUserId()).FirstOrDefault();

            if (spec == null)
            {
                Message = $"Could not create exlusion!";
            }
            else
            {
                var exists = _dbContext.ScheduleSyncSpecExclusions.Where(x => x.ScheduleSyncSpecID == spec.ID && x.ExcludedDate == this.Date).Any();

                if (!exists)
                {
                    _dbContext.ScheduleSyncSpecExclusions.Add(new Models.ScheduleSyncExclusion()
                    {
                        ScheduleSyncSpecID = spec.ID, ExcludedDate = this.Date
                    });

                    _dbContext.SaveChanges();
                }

                Message = $"Created exclusion for {Date.ToShortDateString()}!";
            }
        }
Exemple #2
0
        public async Task <IActionResult> OnPost(long SelectedTeamSnapTeamId, string SelectedTwinRinksTeam, DateTime SelectedExpiresDate)
        {
            Models.ScheduleSyncSpec spec = new Models.ScheduleSyncSpec();

            spec.CreatedDate      = DateTime.UtcNow;
            spec.LastUpdated      = DateTime.UtcNow;
            spec.TeamSnapTeamId   = SelectedTeamSnapTeamId;
            spec.TeamSnapUserId   = User.GetTeamSnapUserId();
            spec.TeamSnapToken    = this.HttpContext.GetCurrentTeamSnapBearerToken();
            spec.TwinRinkTeamName = SelectedTwinRinksTeam;
            spec.Recipients       = this.User.GetTeamSnapUserEmail();

            var team = await tsApi.GetTeamAsync(SelectedTeamSnapTeamId);

            spec.TeamSnapTeamName = team.Name;

            spec.Expires = SelectedExpiresDate;

            _dbContext.Add(spec);

            await _dbContext.SaveChangesAsync();

            return(Redirect("/ScheduleSyncSpec"));
        }