Exemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync(bool?edit)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var newTalk = new Talk();

            if (await TryUpdateModelAsync <Talk>(
                    newTalk,
                    "talk",
                    i => i.MeetingID, i => i.MemberID, i => i.Topic))
            {
                _context.Talk.Add(newTalk);
                await _context.SaveChangesAsync();

                if (edit == true)
                {
                    return(RedirectToPage("../Talks/Details", new { id = newTalk.MeetingID }));
                }
                return(RedirectToPage("./Create", new { id = newTalk.MeetingID }));
            }

            if (edit == true)
            {
                return(RedirectToPage("../Talks/Details", new { id = newTalk.MeetingID }));
            }
            return(RedirectToPage("./Create", new { id = newTalk.MeetingID }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CallingExists(Calling.CallingID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            return(RedirectToPage("./Details", new { id = Member.ID }));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

            return(RedirectToPage("./Details", new { id = Talk.MeetingID }));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Member = await _context.Member
                     .Include(m => m.Talks)
                     .Include(m => m.Prayers)
                     .Include(m => m.CurrentCallings)
                     .FirstOrDefaultAsync(m => m.ID == id);

            if (Member != null)
            {
                try
                {
                    foreach (var talk in Member.Talks)
                    {
                        _context.Talk.Remove(talk);
                    }
                    foreach (var prayer in Member.Prayers)
                    {
                        _context.Prayer.Remove(prayer);
                    }
                    foreach (var calling in Member.CurrentCallings)
                    {
                        _context.CurrentCalling.Remove(calling);
                    }
                    _context.Member.Remove(Member);
                    await _context.SaveChangesAsync();

                    return(RedirectToPage("./Index"));
                }
                catch (Exception)
                {
                    Message = "Error Deleting Member. Try again.";
                    return(Page());
                }
            }
            Message = "Error Deleting Member. Try again.";
            return(Page());
        }
Exemplo n.º 8
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Meeting = await _context.Meeting
                      .Include(m => m.Calling)
                      .ThenInclude(m => m.CurrentCallings)
                      .ThenInclude(m => m.Member)
                      .Include(m => m.Prayers)
                      .ThenInclude(m => m.Member)
                      .Include(m => m.Talks)
                      .ThenInclude(m => m.Member)
                      .Include(m => m.SongSelections)
                      .ThenInclude(m => m.Song)
                      .FirstOrDefaultAsync(m => m.MeetingID == id);

            if (Meeting != null)
            {
                // remove the talks
                foreach (var item in Meeting.Talks)
                {
                    _context.Talk.Remove(item);
                }
                // remove the prayers
                foreach (var item in Meeting.Prayers)
                {
                    _context.Prayer.Remove(item);
                }
                // remove the songsSelections
                foreach (var item in Meeting.SongSelections)
                {
                    _context.SongSelection.Remove(item);
                }
                _context.Meeting.Remove(Meeting);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var talkToUpdate = await _context.Talk.FindAsync(id);

            if (await TryUpdateModelAsync <Talk>(
                    talkToUpdate,
                    "talk",
                    t => t.MemberID, t => t.TalkID, t => t.Topic))
            {
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Details", new { id = Talk.MeetingID }));
            }

            ViewData["MemberID"] = new SelectList(_context.Member, "ID", "FullName");
            return(Page());
        }
Exemplo n.º 10
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Calling = await _context.Calling.FirstOrDefaultAsync(m => m.CallingID == CurrentCalling.CallingID);

            Member = await _context.Member.FirstOrDefaultAsync(m => m.ID == CurrentCalling.MemberID);

            if (Calling.CallingGender != GenderCl.Both && Calling.CallingGender.ToString() != Member.MembersGender.ToString())
            {
                Message = "Member is wrong gender for this calling.";
                ViewData["CallingID"] = new SelectList(_context.Calling, "CallingID", "Display");
                ViewData["MemberID"]  = new SelectList(_context.Member, "ID", "FullName");
                return(Page());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CurrentCallingExists(CurrentCalling.CurrentCallingID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            Calling = await _context.Calling.FirstOrDefaultAsync(m => m.CallingID == CurrentCalling.CallingID);

            Member = await _context.Member.FirstOrDefaultAsync(m => m.ID == CurrentCalling.MemberID);

            if (Calling.CallingGender != GenderCl.Both && Calling.CallingGender.ToString() != Member.MembersGender.ToString())
            {
                Message = "Member is wrong gender for this calling.";
                ViewData["CallingID"] = new SelectList(_context.Calling, "CallingID", "Display", "CallingGender");
                ViewData["MemberID"]  = new SelectList(_context.Member, "ID", "FullName", "MembersGender");
                return(Page());
            }

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

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 12
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var emptyCalling = new Calling();

            if (await TryUpdateModelAsync <Calling>(
                    emptyCalling,
                    "calling",
                    s => s.CallingID, s => s.Title, s => s.Organization))
            {
                _context.Calling.Add(emptyCalling);
                await _context.SaveChangesAsync();

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



            return(Page());
        }
Exemplo n.º 13
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Song = await _context.Song
                   .Include(m => m.SongSelections)
                   .ThenInclude(m => m.Meeting)
                   .FirstOrDefaultAsync(m => m.SongID == id);

            if (Song != null)
            {
                foreach (var item in Song.SongSelections)
                {
                    _context.SongSelection.Remove(item);
                }
                _context.Song.Remove(Song);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 14
0
        public async Task <IActionResult> OnPostAsync(int?id, bool?edit)
        {
            if (!ModelState.IsValid)
            {
                PopulateBishopricSL(_context, Meeting.Calling);
                PopulatePrayersSLI(_context, Meeting);
                PopulateSongsSLI(_context, Meeting);
                Message = "There was an error updating Meeting";
                return(Page());
            }

            Message = ValidateMeetingInput(OpeningSong, ClosingSong, SacramentSong, OpeningPrayer, ClosingPrayer);

            if (Message != "")
            {
                PopulateBishopricSL(_context, Meeting.Calling);
                PopulatePrayersSLI(_context, Meeting);
                PopulateSongsSLI(_context, Meeting);

                return(Page());
            }



            // get meeting that needs to be updated
            var meetingToUpdate = await _context.Meeting
                                  .Include(m => m.SongSelections)
                                  .ThenInclude(m => m.Song)
                                  .Include(m => m.Prayers)
                                  .ThenInclude(m => m.Member)
                                  .FirstOrDefaultAsync(s => s.MeetingID == id);

            if (Meeting != null && Meeting.MeetingDate != meetingToUpdate.MeetingDate)

            {
                Message = "";
                var meetings = _context.Meeting;
                foreach (Meeting item in meetings)
                {
                    if (item.MeetingDate == Meeting.MeetingDate)
                    {
                        Message = "A meeting for this date already exists.";


                        PopulateBishopricSL(_context, Meeting.Calling);
                        PopulatePrayersSLI(_context, Meeting);
                        PopulateSongsSLI(_context, Meeting);

                        return(Page());
                    }
                }
            }
            // Add or remove songs to update Meeting.SongSelection
            UpdateSong(_context, meetingToUpdate, meetingToUpdate.SongSelections, SongPosition.Opening, OpeningSong);
            UpdateSong(_context, meetingToUpdate, meetingToUpdate.SongSelections, SongPosition.Sacrament, SacramentSong);
            UpdateSong(_context, meetingToUpdate, meetingToUpdate.SongSelections, SongPosition.Closing, ClosingSong);

            // Add or remove prayers to update Meeting.Prayer
            UpdatePrayer(_context, meetingToUpdate, meetingToUpdate.Prayers, PrayerPosition.Opening, OpeningPrayer);
            UpdatePrayer(_context, meetingToUpdate, meetingToUpdate.Prayers, PrayerPosition.Closing, ClosingPrayer);
            if (await TryUpdateModelAsync <Meeting>(
                    meetingToUpdate,
                    "meeting",
                    m => m.MeetingDate, m => m.CallingID))
            {
                await _context.SaveChangesAsync();
            }
            if (edit != null)
            {
                return(RedirectToPage("../Talks/Details", new { id = meetingToUpdate.MeetingID }));
            }
            return(RedirectToPage("../Talks/Create", new { id = meetingToUpdate.MeetingID }));
        }
Exemplo n.º 15
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                PopulateBishopricSL(_context, Meeting.Calling);
                PopulatePrayersSLI(_context, Meeting);
                PopulateSongsSLI(_context, Meeting);
                Message = "There was an error saving meeting.";
                return(Page());
            }

            Message = ValidateMeetingInput(OpeningSong, ClosingSong, SacramentSong, OpeningPrayer, ClosingPrayer);

            if (Message != "")
            {
                PopulateBishopricSL(_context, Meeting.Calling);
                PopulatePrayersSLI(_context, Meeting);
                PopulateSongsSLI(_context, Meeting);

                return(Page());
            }

            // Validation
            // Meeting date is not unique - "Meeting date already exists."
            if (Meeting != null)
            {
                Message = "";
                var meetings = _context.Meeting;
                foreach (Meeting item in meetings)
                {
                    if (item.MeetingDate == Meeting.MeetingDate)
                    {
                        Message = "A meeting for this date already exists.";


                        PopulateBishopricSL(_context, Meeting.Calling);
                        PopulatePrayersSLI(_context, Meeting);
                        PopulateSongsSLI(_context, Meeting);

                        return(Page());
                    }
                }
            }

            // if songs not null, check if int
            var newMeeting = new Meeting();

            // Add prayers
            if (OpeningPrayer != null || ClosingPrayer != null)
            {
                newMeeting.Prayers = new List <Prayer>();
                if (OpeningPrayer != null)
                {
                    var prayerToAddO = new Prayer
                    {
                        MemberID = int.Parse(OpeningPrayer),
                        Schedule = PrayerPosition.Opening
                    };
                    newMeeting.Prayers.Add(prayerToAddO);
                }
                if (ClosingPrayer != null)
                {
                    var prayerToAddC = new Prayer
                    {
                        MemberID = int.Parse(ClosingPrayer),
                        Schedule = PrayerPosition.Closing
                    };
                    newMeeting.Prayers.Add(prayerToAddC);
                }
            }

            // add songs
            if (OpeningSong != null || SacramentSong != null || ClosingSong != null)
            {
                newMeeting.SongSelections = new List <SongSelection>();
                if (OpeningSong != null)
                {
                    var songToAddO = new SongSelection
                    {
                        SongID   = int.Parse(OpeningSong),
                        Schedule = SongPosition.Opening
                    };
                    newMeeting.SongSelections.Add(songToAddO);
                }
                if (SacramentSong != null)
                {
                    var songToAddS = new SongSelection
                    {
                        SongID   = int.Parse(SacramentSong),
                        Schedule = SongPosition.Sacrament
                    };
                    newMeeting.SongSelections.Add(songToAddS);
                }
                if (ClosingSong != null)
                {
                    var songToAddC = new SongSelection
                    {
                        SongID   = int.Parse(ClosingSong),
                        Schedule = SongPosition.Closing
                    };
                    newMeeting.SongSelections.Add(songToAddC);
                }
            }

            try
            {
                if (await TryUpdateModelAsync <Meeting>(
                        newMeeting,
                        "Meeting",
                        i => i.MeetingDate,
                        i => i.CallingID))
                {
                    _context.Meeting.Add(newMeeting);
                    await _context.SaveChangesAsync();

                    //return RedirectToPage("./Index");
                    return(RedirectToPage("../Talks/Create", new { id = newMeeting.MeetingID }));
                }
            }
            catch (Exception)
            {
                PopulateBishopricSL(_context);
                PopulateSongsSLI(_context);
                PopulatePrayersSLI(_context);
                Message = "There was an error saving meeting.";
                return(RedirectToPage("./Create"));
            }

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