Exemple #1
0
        public async Task <IActionResult> AddAccountVendor(AccountVendor vendor)
        {
            _dbContext.AccountVendors.Add(vendor);
            await _dbContext.SaveChangesAsync();

            return(Ok(vendor));
        }
        public async Task <Response> AddCategory([FromBody] Category category)
        {
            Guid userId = new Guid(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            category.CreatedBy = userId;
            category.CreatedOn = DateTime.Now;

            _context.Categories.Add(category);
            await _context.SaveChangesAsync();

            return(new Response(successMessage: "Category has been created!"));
        }
Exemple #3
0
        public async Task <Response> AddNewMoneyBox([FromBody] MoneyBox moneyBox)
        {
            Guid userId = new Guid(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            moneyBox.UserId    = userId;
            moneyBox.CreatedOn = DateTime.Now;

            _context.MoneyBoxes.Add(moneyBox);
            await _context.SaveChangesAsync();

            return(new Response(successMessage: "MoneyBoxes has been created!"));
        }
Exemple #4
0
        public async Task <Response> CreateIncome([FromBody] Income income)
        {
            Guid userId = new Guid(User.FindFirst(ClaimTypes.NameIdentifier).Value);
            User user   = await _context.Users.FirstOrDefaultAsync(u => u.Id == userId);

            income.CreatedBy = userId;
            income.CreatedOn = DateTime.Now;
            income.UserId    = userId;
            _context.Incomes.Add(income);
            await _context.SaveChangesAsync();

            return(new Response(successMessage: "Income has been created!"));
        }
        public async Task <Response> CreateExpense([FromBody] Expense expense)
        {
            Guid userId = new Guid(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            expense.UserId    = userId;
            expense.CreatedBy = userId;
            expense.CreatedOn = DateTime.Now;
            expense.Value     = expense.Value * (-1);
            _context.Expenses.Add(expense);
            await _context.SaveChangesAsync();

            return(new Response(successMessage: "Expense has been created!"));
        }
        public async Task <IActionResult> AddUser(User user)
        {
            // Note: AddUser() is an endpoint that exposes a user's TOTP secret.
            // To avoid abuse, be it unecessary, this check is enforced.
            if (!_dbContext.Users.Any(u => u.AccountId == user.AccountId))
            {
                // Generate TOTP secret based on account id and hash key.
                user.TOTPSecret = await GenerateUserTOTPSecretAsync(user.AccountId, _options.TOTPHashKey);

                _dbContext.Users.Add(user);
                await _dbContext.SaveChangesAsync();

                return(Ok(user));
            }
            else
            {
                return(BadRequest("User already exists."));
            }
        }
Exemple #7
0
        public async Task <Response> RegisterUser([FromBody] User user)
        {
            User userDb = await _context.Users.FirstOrDefaultAsync(u => u.Login == user.Login);

            if (userDb != null)
            {
                //Response.StatusCode = 400;
                return(new Models.Response(clientError: "User already exist.", statusCode: System.Net.HttpStatusCode.BadRequest));
            }

            user.CreatedOn = DateTime.Now;
            _context.Users.Add(user);
            await _context.SaveChangesAsync();

            return(new Models.Response(successMessage: "Success! You can log in now!"));
        }