Ejemplo n.º 1
0
        public async Task <int> CreateSongHymnalEditionAsync(AddSongToHymnalViewModel addSongToHymnalViewModel, string userId, int churchId)
        {
            var songHymnalEdition = new SongHymnalEdition
            {
                SongId            = addSongToHymnalViewModel.SongId,
                HymnalId          = addSongToHymnalViewModel.HymnalId,
                PageNumber        = addSongToHymnalViewModel.PageNumber,
                CopyrightYear     = addSongToHymnalViewModel.CopyrightYear,
                VoicingId         = addSongToHymnalViewModel.VoicingId,
                InstrumentationId = addSongToHymnalViewModel.InstrumentationId,
                IsDefault         = false,
                CreatedByChurchId = churchId,
                CreatedById       = userId,
                LastModifiedById  = userId,
                DateCreated       = DateTime.Now,
                DateLastModified  = DateTime.Now,
            };

            if (!string.IsNullOrWhiteSpace(addSongToHymnalViewModel.Contributors))
            {
                var contributors =
                    JsonConvert.DeserializeObject <List <ContributorIdAndRoleDTO> >($"[{addSongToHymnalViewModel.Contributors.Replace("}{", "},{")}]");

                songHymnalEdition.Contributors =
                    contributors.Select(c => new SongHymnalEditionContributor {
                    ContributorId = c.Id,
                    Role          = (ContributorRole)c.Role,
                }).ToList();
            }
            return(await _songEditionRepository.CreateSongHymnalEditionAsync(songHymnalEdition));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AddSongToHymnal(AddSongToHymnalViewModel model)
        {
            if (ModelState.IsValid)
            {
                await _songEditionService.CreateSongHymnalEditionAsync(model, GetUserId(), GetChurchId());

                return(RedirectToAction("Hymnal", new { id = model.HymnalId }));
            }
            model.HymnalName = (await _hymnalService.GetByIdAsync(model.HymnalId))?.Title;
            return(View(model));
        }