예제 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CreditCardId,OperationCode,TimeStamp,WithdrawalAmount")] UserActionResult actionResult)
        {
            if (id != actionResult.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _actionResultService.EditActionResult(actionResult);
                }
                catch (InvalidOperationException)
                {
                    if (!ActionResultExists(actionResult.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(actionResult));
        }
 private UserActionResult ToUserActionResult(ITry <Unit, SignInError> t) =>
 t.Match(
     s => UserActionResult.Success(),
     e => e.Match(
         SignInError.InvalidCredentials, _ => UserActionResult.Error(UserMessages.InvalidCredentials()),
         SignInError.NoConnection, _ => UserActionResult.Error(UserMessages.NoConnection())
         )
     );
예제 #3
0
        public async Task DeleteActionResultById(int id)
        {
            UserActionResult userAction = await GetActionResultById(id);

            if (userAction != null)
            {
                await _userActionRepository.DeleteAsync(userAction);
            }
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("Id,CreditCardId,OperationCode,TimeStamp,WithdrawalAmount")] UserActionResult actionResult)
        {
            if (ModelState.IsValid)
            {
                await _actionResultService.EditActionResult(actionResult);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(actionResult));
        }
예제 #5
0
 private UserActionResult ToUserActionResult(ITry <Unit, SignUpError[]> t) =>
 t.Match(
     s => UserActionResult.Success(),
     e => e.First().Match(
         SignUpError.NoConnection, _ => UserActionResult.Error(UserMessages.NoConnection()),
         SignUpError.InvalidEmail, _ => Email.Invalidate().Pipe(u => UserActionResult.Error()),
         SignUpError.PasswordTooShort, _ => Password.Invalidate().Pipe(u => UserActionResult.Error()),
         SignUpError.AccountAlreadyExists, _ => UserActionResult.Error(UserMessages.AccountAlreadyExists())
         )
     );
예제 #6
0
 private IActionResult GetAuthenticatedActionResult(UserActionResult result)
 {
     if (result.User != null)
     {
         var token = GetJWTToken(result.User);
         return(GetActionResult(result, token));
     }
     else
     {
         return(GetActionResult(result));
     }
 }
예제 #7
0
        public void BlockAndUnblock()
        {
            // TODO - Unblock doesn't seem to actually do anything.  Skip this test for now so as not to block the workflow tests.  --Kris
            return;

            // Block user.
            UserActionResult res = reddit.Models.Users.BlockUser(new UsersBlockUserInput(name: "RedditDotNetBot"));

            // Unblock user (returns empty JSON).
            reddit.Models.Users.Unfriend(new UsersUnfriendInput("RedditDotNetBot", "t2_6vsit", "enemy"));

            Assert.IsNotNull(res);
        }
예제 #8
0
        public void Friendship()
        {
            // Add a friend.
            UserActionResult updateRes = reddit.Models.Users.UpdateFriend("RedditDotNetBot");

            // Get data on an existing friend.
            UserActionResult getRes = reddit.Models.Users.GetFriend("RedditDotNetBot");

            // It's just not working out.  Delete the friend and burn all their stuff.
            reddit.Models.Users.DeleteFriend("RedditDotNetBot");

            Assert.IsNotNull(updateRes);
            Assert.IsNotNull(updateRes.Name);
            Assert.IsTrue(updateRes.Name.Equals("RedditDotNetBot"));

            Assert.IsNotNull(getRes);
            Assert.IsNotNull(getRes.Name);
            Assert.IsTrue(getRes.Name.Equals("RedditDotNetBot"));
        }
예제 #9
0
        private IActionResult GetActionResult(UserActionResult result, string jwt = null)
        {
            if (result.Succeeded)
            {
                var user = new User
                {
                    Id           = result.User.Id,
                    Name         = result.User.UserName,
                    AvatarIconId = result.User.AvatarIconId,
                    DisplayName  = result.User.DisplayName
                };

                return(Ok(new { user, jwt }));
            }
            else
            {
                return(BadRequest(new { message = result.GetErrorsMessage() }));
            }
        }
예제 #10
0
        public async Task GetBuIdAsync_ShouldReturnNoAction()
        {
            using (var db = new ATMContext(TestOptions.TestDbContextOptions <ATMContext>()))
            {
                // Arrange
                await db.AddRangeAsync(ACTION_RESULTS);

                await db.SaveChangesAsync();

                UserActionResult expectedDbAction = null;
                int actionId = db.ActionResults.OrderBy(x => x.Id).Last().Id + 1;
                IRepository <UserActionResult> repository = new DBUserActionResultRepository(db);

                // Act
                var result = await repository.GetByIdAsync(actionId);

                // Assert
                Assert.Equal(expectedDbAction, result);
            }
        }
예제 #11
0
 public async Task EditActionResult(UserActionResult userAction)
 {
     await _userActionRepository.EditAsync(userAction);
 }
예제 #12
0
 public async Task AddActionResult(UserActionResult userAction)
 {
     await _userActionRepository.AddAsync(userAction);
 }
예제 #13
0
        public static UserActionResult ToUserActionResult(this IEnumerable <Exception> exceptions)
        {
            var message = exceptions.Select(e => e.Message).Aggregate((s1, s2) => $"{s1}{Environment.NewLine}{s2}");

            return(UserActionResult.Error(new UserMessage("Error", message)));
        }