Exemplo n.º 1
0
        public IActionResult RecordLabelDetails(int Id)
        {
            var model = new RecordLabelDetailsViewModel();

            model.RecordLabel                   = _recordLabelManager.GetOne(filter: x => x.Id == Id, includeProperties: $"{nameof(RecordLabel.User)},{nameof(RecordLabel.RecordLabelArtists)}.{nameof(Artist)}.{nameof(Artist.User)}");
            model.PagingModelArtists            = new PagingModel <Artist>();
            model.PagingModelArtists.PagingList = model.RecordLabel.RecordLabelArtists.Select(x => x.Artist).Take(MBoxConstants.initialTakeHomeLists).ToList();
            return(View(model));
        }
        public IActionResult AddNewArtist(InviteViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var recordLabel = _recordLabelManager.GetOne(filter: x => x.Id == CurrentLoggedUserId, includeProperties: $"{nameof(User)}");

            if (recordLabel == null)
            {
                return(View(model));
            }

            if (_recordLabelManager.GetNumberOfArtists(CurrentLoggedUserId) >= MBoxConstants.MaximumArtistsAllowed)
            {
                ModelState.AddModelError("Email", "Artist limit (50) reached. Cannot add new artist.");
                return(View(model));
            }

            var response = _userManager.CreateUser(model.Name, model.Email, Role.Artist);

            if (response == null)
            {
                ModelState.AddModelError("EMail", "Email already exists");
                return(View(model));
            }
            var user = response.Result;

            _artistsManager.Create(new Artist {
                User = user, RecordLabelArtists = new List <RecordLabelArtist> {
                    new RecordLabelArtist {
                        RecordLabel = recordLabel
                    }
                }
            }, CurrentLoggedUserId);
            _artistsManager.Save();
            var code        = _userManager.GeneratePasswordResetTokenAsync(user).Result;
            var callbackUrl = Url.ResetPasswordCallbackLink(user.Id.ToString(), code, Request.Scheme);

            _emailsManager.PrepareSendMail(EmailTemplateType.InvitedArtist, model.Email, callbackUrl);

            return(View("SuccessfullyInvitedArtist"));
        }