Пример #1
0
        public async Task <IActionResult> Create(CreateSongViewModel model)
        {
            if (ModelState.IsValid)
            {
                var songCreate = await _songService.GetSongCreateByIdAsync(model.SongCreateId);

                if (songCreate.CreatedById != GetUserId() || songCreate.SongCreated)
                {
                    return(RedirectToAction("InsufficientPermission", "Home"));
                }
                if (songCreate != null)
                {
                    if (songCreate.SongCreated)
                    {
                        return(RedirectToAction("Library", "Index"));
                    }
                    songCreate.IsPublic = model.IsPublic.ToLower() == "yes" ? true : false;
                    var songId = await _songService.CreateSongAsync(songCreate, GetUserId(), GetChurchId());

                    //Add related data to the newly created song, in this case, the composers and lyricists.
                    var contributors = songCreate.Contributors.Select(c => new SongContributor
                    {
                        ContributorId    = c.ContributorId,
                        SongId           = songId,
                        Role             = c.Role,
                        CreatedById      = GetUserId(),
                        LastModifiedById = GetUserId(),
                        DateCreated      = DateTime.Now,
                        DateLastModified = DateTime.Now
                    }).ToList();
                    await _songService.AddSongContributorsAsync(contributors);

                    await _libaryService.AddChurchSongAsync(GetChurchId(), songId, GetUserId());

                    await _songService.UpdateSongCreate_CreateSongTrueAsync(model.SongCreateId);

                    //await _songEditionService.CreateSongEditionAsync(new SongEdition {
                    //    SongId              = songId,
                    //    CreatedById         = GetUserId(),
                    //    LastModifiedById    = GetUserId(),
                    //    DateLastModified    = DateTime.Now,
                    //    DateCreated         = DateTime.Now,
                    //    IsDefault           = true,
                    //    CreatedByChurchId   = GetChurchId()
                    //});

                    return(RedirectToAction("CreateSuccess", new { id = songId }));
                }
            }
            return(RedirectToAction("Error", "Home"));
        }