public async Task DeleteNotificationTestAsync()
        {
            //Assemble
            var helper  = new TestHelper();
            var mapper  = new Mapper();
            var options = new DbContextOptionsBuilder <AccountDbContext>()
                          .UseInMemoryDatabase("DeleteNotificationTestAsync")
                          .Options;

            using var assembleContext = new AccountDbContext(options);
            var deleteNotification = mapper.MapNotification(helper.Notifications[0]);

            assembleContext.Add(deleteNotification);
            assembleContext.SaveChanges();
            using var actContext = new AccountDbContext(options);
            var repo = new GenericRepository(actContext, new Mapper());

            // Act
            await repo.DeleteNotificationByIdAsync(deleteNotification.NotificationId);

            // Assert
            var notification = actContext.Notification.ToList();

            Assert.DoesNotContain(deleteNotification, notification);
        }
Esempio n. 2
0
 public virtual async Task Insert(T ob)
 {
     if (typeof(C) == typeof(AccountDbContext))
     {
         _accountdbContext.Add(ob);
         _accountdbContext.SaveChanges();
     }
 }
        public async Task <IActionResult> Create([Bind("AccountId,AccountName")] Account account)
        {
            if (ModelState.IsValid)
            {
                _context.Add(account);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(account));
        }
Esempio n. 4
0
        public async Task <IActionResult> ExternalLoginConfirmation(ExternalLoginViewModel model, string returnUrl = null)
        {
            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await _signInManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    throw new ApplicationException("Error loading external login information during confirmation.");
                }
                var user = new ApplicationUser {
                    UserName = model.Email.Split('@')[0], Email = model.Email
                };
                AccountDbContext dbUsers     = new AccountDbContext();
                Account          accountUser = new Account {
                    Login = model.Email.Split('@')[0], Email = model.Email, LastActivity = DateTime.Now, Status = true, UsedSocialNetwork = info.LoginProvider, ProviderKey = info.ProviderKey
                };
                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);

                    if (result.Succeeded)
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
                        dbUsers.Add(accountUser);
                        dbUsers.SaveChanges();
                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            ViewData["ReturnUrl"] = returnUrl;
            return(View(nameof(ExternalLogin), model));
        }
        public async Task DeleteProviderTestAsync()
        {
            //Assemble
            var helper  = new TestHelper();
            var mapper  = new Mapper();
            var options = new DbContextOptionsBuilder <AccountDbContext>()
                          .UseInMemoryDatabase("DeleteProviderTestAsync")
                          .Options;

            using var assembleContext = new AccountDbContext(options);
            var deleteProvider = mapper.MapProvider(helper.Providers[2]);

            assembleContext.Add(deleteProvider);
            assembleContext.SaveChanges();
            using var actContext = new AccountDbContext(options);
            var repo = new GenericRepository(actContext, new Mapper());
            // Act
            await repo.DeleteProviderAccountAsync(deleteProvider.ProviderId);

            // Assert
            var provider = actContext.ProviderAccount.ToList();

            Assert.DoesNotContain(deleteProvider, provider);
        }
Esempio n. 6
0
 public Result <TEntity> Add(TEntity entity)
 {
     dbContext.Add(entity);
     return(Result <TEntity> .Success());
 }
Esempio n. 7
0
        /// <summary>
        /// Add a Provider to the database.
        /// </summary>
        /// <param name="newAccount"></param>
        public void AddProviderAccountAsync(ProviderAccount newAccount)
        {
            var newEntity = _mapper.MapProvider(newAccount);

            _context.Add(newEntity);
        }