示例#1
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            //Start nonsense

            //Added this nonsense so that I could remove the [Required]
            //parameter from the Speaker model class so that the hidden
            //divs don't throw exceptions on post. This prevents
            //null values from going into the speaker table

            List <Speaker> speakers = new List <Speaker>();

            for (int i = 0; i < 5; i++)
            {
                if (Sacrament_Plan.Speakers[i].Name != null && Sacrament_Plan.Speakers[i].Subject != null)
                {
                    speakers.Add(Sacrament_Plan.Speakers[i]);
                }
            }

            Sacrament_Plan.Speakers = speakers;

            //End nonsense

            _context.Sacrament_Plan.Add(Sacrament_Plan);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
示例#2
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            //Start nonsense

            // Added this so that null values aren't entered into the table. Had to add it here and remove
            // it from the model so that things don't break

            var planToUpdate = await _context.Sacrament_Plan.FindAsync(id);


            List <Speaker> speakers = new List <Speaker>();

            for (int i = 0; i < Sacrament_Plan.Speakers.Count; i++)
            {
                if (Sacrament_Plan.Speakers[i].Name != null && Sacrament_Plan.Speakers[i].Subject != null)
                {
                    speakers.Add(Sacrament_Plan.Speakers[i]);
                }
            }

            // If i don't do it this way, it gives some tracking DB error
            planToUpdate.Speakers         = speakers;
            planToUpdate.ClosingPrayer    = Sacrament_Plan.ClosingPrayer;
            planToUpdate.ClosingSong      = Sacrament_Plan.ClosingSong;
            planToUpdate.ConductingLeader = Sacrament_Plan.ConductingLeader;
            planToUpdate.IntermediateHymn = Sacrament_Plan.IntermediateHymn;
            planToUpdate.MeetingDate      = Sacrament_Plan.MeetingDate;
            planToUpdate.MusicalNumber    = Sacrament_Plan.MusicalNumber;
            planToUpdate.OpeningPrayer    = Sacrament_Plan.OpeningPrayer;
            planToUpdate.OpeningSong      = Sacrament_Plan.OpeningSong;
            planToUpdate.SacramentHymn    = Sacrament_Plan.SacramentHymn;


            //End nonsense

            _context.Attach(planToUpdate).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Sacrament_PlanExists(Sacrament_Plan.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
示例#3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Sacrament_Plan = await _context.Sacrament_Plan.FindAsync(id);

            if (Sacrament_Plan != null)
            {
                _context.Sacrament_Plan.Remove(Sacrament_Plan);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }