Пример #1
0
        public async Task <IActionResult> GetUser(int id)
        {
            var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (currentUserId != id)
            {
                return(Unauthorized());
            }
            var user = await _repo.GetUser(id);

            var userToReturn = _map.Map <UserForDetailedDto>(user);

            return(Ok(userToReturn));
        }
Пример #2
0
        public async override Task ProcessAsync(int dummy)
        {
            // _mcApi.Client.GetAsync()
            var user = await _repo.GetUser("paedelm");

            Console.WriteLine($"userid: {user.Id} knownAs:{user.KnownAs} lastactive:{user.LastActive}");
            PagedList <Mutation> pg = await _repo.GetMutationsForUserAccount(new Helpers.MutationParams {
                UserId = 1, AccountId = 1, PageNumber = 1, PageSize = 20
            });

            Console.WriteLine($"PageSize={pg.PageSize} en Count={pg.Count}");
            Console.WriteLine($"version={GetType().GetTypeInfo().Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>().Version}");
            foreach (var mut in pg)
            {
                Console.WriteLine($"{mut.Account.Accountname} - {mut.Amount} - {mut.Balance} - {mut.Created}");
            }
            string json = JsonConvert.SerializeObject(value: pg, formatting: Formatting.Indented, settings: new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            // Console.WriteLine($"json={json}");
            _logger.LogInformation("PollerProcess via logger");
            await Task.Run(() =>
            {
                //    logger.LogInformation("In de poller Process procedure"));
                Console.WriteLine($"In de poller Process procedure");
            });
        }
Пример #3
0
        public async Task <IActionResult> CreateInterest(int userId, int accountId, [FromBody] InterestForCreationDto interestForCreationDto)
        {
            var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (currentUserId != userId)
            {
                return(Unauthorized());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            interestForCreationDto.UserId    = userId;
            interestForCreationDto.AccountId = accountId;

            var account = await _repo.GetAccount(accountId);

            if (account == null || account.UserId != userId)
            {
                return(Unauthorized());
            }
            var user = await _repo.GetUser(userId);

            // eens kijken of de mapper zo slim is dat ie de sender informatie ook invult in messageToReturn
            // zelfs bij de sender info die nu ietsanders heet.
            var interest = _map.Map <Interest>(interestForCreationDto);

            account.Percentage = interest.Percentage;

            _repo.Add(interest);
            if (await _repo.SaveAll())
            {
                var interestToReturn = _map.Map <InterestForDetailedDto>(interest);
                return(CreatedAtRoute("GetInterest", new { id = interest.Id }, interestToReturn));
            }
            throw new Exception("Creating the mutation failed on save");
        }
Пример #4
0
        public async Task <IActionResult> CreateAccount(int userId, [FromBody] AccountForCreationDto accountForCreationDto)
        {
            var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (currentUserId != userId)
            {
                return(Unauthorized());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            accountForCreationDto.UserId = userId;


            if (await _repo.GetAccount(userId, accountForCreationDto.Accountname) != null)
            {
                return(BadRequest("Account already exists"));
            }

            var user = await _repo.GetUser(accountForCreationDto.UserId);

            // eens kijken of de mapper zo slim is dat ie de sender informatie ook invult in messageToReturn
            // zelfs bij de sender info die nu ietsanders heet.
            var account = _map.Map <Account>(accountForCreationDto);

            account.Balance = 0;
            _repo.Add(account);
            if (await _repo.SaveAll())
            {
                var accountToReturn = _map.Map <AccountForDetailedDto>(account);
                return(CreatedAtRoute("GetAccount", new { id = account.Id }, accountToReturn));
            }
            throw new Exception("Creating the account failed on save");
        }
Пример #5
0
        public async Task <IActionResult> CreateMutation(int userId, int accountId, [FromBody] MutationForCreationDto mutationForCreationDto)
        {
            var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (currentUserId != userId)
            {
                return(Unauthorized());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            mutationForCreationDto.UserId    = userId;
            mutationForCreationDto.AccountId = accountId;

            var account = await _repo.GetAccount(accountId);

            if (account == null || account.UserId != userId)
            {
                return(Unauthorized());
            }
            var user = await _repo.GetUser(userId);

            // eens kijken of de mapper zo slim is dat ie de sender informatie ook invult in messageToReturn
            // zelfs bij de sender info die nu ietsanders heet.
            var mutation = _map.Map <Mutation>(mutationForCreationDto);

            var lastMutation = await _repo.GetMutation(account.LastMutationCreated, userId, accountId);

            if (lastMutation == null)
            {
                mutation.Balance = mutation.Amount;
                mutation.PrevId  = -account.Id;
            }
            else
            {
                mutation.PrevId  = lastMutation.Id;
                mutation.Balance = lastMutation.Balance + mutation.Amount;
                var diffdays = (mutation.InterestDate - lastMutation.InterestDate).TotalDays;
                int nrdays   = (int)diffdays;
                if (lastMutation.InterestDate.AddDays(diffdays).DayOfYear != mutation.InterestDate.DayOfYear)
                {
                    nrdays += 1;
                }
                // zoek eerst nog de gemiddelde rente op dus alle percentages af totdat
                var interest = (nrdays / 365) * account.Percentage;
                account.CalculatedInterest += interest;
            }
            if (mutation.Percentage != 0.0)
            {
                account.Percentage = mutation.Percentage;
            }
            else
            {
                mutation.Percentage = account.Percentage;
            }
            account.Balance             = mutation.Balance;
            account.LastMutationCreated = mutation.Created;
            account.LastMutation        = mutation;

            _repo.Add(mutation);
            if (await _repo.SaveAll())
            {
                var mutationToReturn = _map.Map <MutationForDetailedDto>(mutation);
                ScheduleTable.StartProcess(schedulePollerProcess, 5000);
                return(CreatedAtRoute("GetMutation", new { id = mutation.Id }, mutationToReturn));
            }
            throw new Exception("Creating the mutation failed on save");
        }