コード例 #1
0
        public override async Task <AddLibraryRequest> HandleAsync(AddLibraryRequest command, CancellationToken cancellationToken = new CancellationToken())
        {
            command.Result = await _libraryRepository.AddLibrary(command.Library, cancellationToken);

            var account = await _accountRepository.GetAccountByEmail(command.Library.OwnerEmail, cancellationToken);

            if (account != null)
            {
                await _libraryRepository.AddAccountToLibrary(command.Result.Id, account.Id, Role.LibraryAdmin, cancellationToken);

                return(await base.HandleAsync(command, cancellationToken));
            }

            var invitationCode = Guid.NewGuid().ToString("N");

            await _accountRepository.AddInvitedAccount(
                command.Library.Name,
                command.Library.OwnerEmail,
                Role.LibraryAdmin,
                invitationCode,
                DateTime.Today.AddDays(7),
                command.Result.Id,
                cancellationToken);

            await _emailService.SendAsync(command.Library.OwnerEmail,
                                          $"Welcome to {command.Result.Name}",
                                          EmailTemplateProvider.GetLibraryAdminInvitationEmail(command.Result.Name, new Uri(new Uri(_settings.FrontEndUrl), _settings.RegisterPagePath + invitationCode).ToString()),
                                          _settings.EmailFrom,
                                          cancellationToken);

            return(await base.HandleAsync(command, cancellationToken));
        }
コード例 #2
0
 public IActionResult AddToLibrary(int bookid)
 {
     if (User.Identity.IsAuthenticated && accountRepository.Accounts.Any(u => u.Username == User.Identity.Name))
     {
         Accounts authenticatedAccount = accountRepository.Accounts.First(u => u.Username == User.Identity.Name);
         if (libraryRepository.BookLibraryExists(bookid, authenticatedAccount.AccountId))
         {
             TempData["ValidationState"] = "Book Exists in Library";
             return(RedirectToAction(TempData["ViewState"].ToString(), TempData["ControllerState"].ToString()));
         }
         else
         {
             TempData["ValidationState"] = null;
         }
         int libraryid = libraryRepository.GetID() + 1;
         if (libraryRepository.Library.Any(l => l.LibraryId == libraryid))
         {
             libraryid += 1;
         }
         libraryRepository.AddLibrary(new Library
         {
             /*LibraryId = libraryid,*/
             AccountId   = authenticatedAccount.AccountId,
             BookId      = bookid,
             Datecreated = DateTime.Now
         });
         return(RedirectToAction("Index", "Library"));
     }
     return(RedirectToAction("Index", "Home"));
 }
コード例 #3
0
        //[Authorize(Roles = "Admin")]
        public async Task <IActionResult> CreateLibrary([FromBody] LibraryForCreationDto libraryForCreation)
        {
            if (await _libraryRepository.LibraryExists(libraryForCreation.BookId, libraryForCreation.OfficeId))
            {
                var library = await _libraryRepository.GetLibrary(libraryForCreation.BookId, libraryForCreation.OfficeId);

                return(CreatedAtRoute(
                           "GetLibrary",
                           new { bookId = library.BookId, officeId = library.OfficeId },
                           library));
            }

            var libraryEntity = _mapper.Map <Library>(libraryForCreation);

            _libraryRepository.AddLibrary(libraryEntity);
            await _libraryRepository.Save();

            return(CreatedAtRoute(
                       "GetLibrary",
                       new { bookId = libraryEntity.BookId, officeId = libraryEntity.OfficeId },
                       libraryEntity));
        }
コード例 #4
0
        public override async Task <UpdateLibraryRequest> HandleAsync(UpdateLibraryRequest command, CancellationToken cancellationToken = new CancellationToken())
        {
            var result = await _libraryRepository.GetLibraryById(command.LibraryId, cancellationToken);

            if (result == null)
            {
                var library = command.Library;
                library.Id             = default(int);
                command.Result.Library = await _libraryRepository.AddLibrary(library, cancellationToken);

                command.Result.HasAddedNew = true;
            }
            else
            {
                command.Library.Id = command.LibraryId;
                await _libraryRepository.UpdateLibrary(command.Library, cancellationToken);

                command.Result.Library = command.Library;
            }

            return(await base.HandleAsync(command, cancellationToken));
        }