Exemplo n.º 1
0
        public async Task <IActionResult> UpdateExpense(SplitExpenseVM viewModel, int id)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            //Hämta currentUser
            var myUser = await userManager.GetUserAsync(HttpContext.User);

            User currentUser = mysticoContext.GetUserByAspUserId(myUser.Id);

            //Hämta specifikt expense som ska ändras
            var myExpense = mysticoContext.GetExpenseById(id);

            //OM jag inte är inköpare ==> skickas till overview
            if (myExpense.PurchaserId != currentUser.Id && (myExpense.PurchaserId < 32 || myExpense.PurchaserId > 47))
            {
                return(RedirectToAction(nameof(SplitController.Details), nameof(SplitController).Replace("Controller", ""), new { id = myExpense.EventId }));
            }

            await mysticoContext.UpdateExpense(myExpense, viewModel);

            return(RedirectToAction(nameof(SplitController.Details), nameof(SplitController).Replace("Controller", ""), new { id = myExpense.EventId }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Expense(int id)
        {
            //Hämta currentUser
            var myUser = await userManager.GetUserAsync(HttpContext.User);

            User currentUser = mysticoContext.GetUserByAspUserId(myUser.Id);

            //Hämta event från databasen som currentUser är med i...
            var myEvents = mysticoContext.GetActiveEventsByUserId(currentUser.Id);

            //Hämta valutor från databasen
            List <Currency> allCurrencies = mysticoContext.GetAllCurrencies();

            var viewModel = new SplitExpenseVM();

            viewModel.CurrencyItem = Library.ConvertCurrencyToSelectListItem(allCurrencies);
            viewModel.EventItem    = Library.ConvertEventToSelectListItem(myEvents);
            viewModel.Date         = DateTime.Today.ToString("u").Replace(" 00:00:00Z", "");

            if (myEvents.Count() == 0)
            {
                viewModel.HasOpenEvent = false;
            }

            if (id != 0)
            {
                viewModel.SelectedEvent = id;
            }

            return(View(viewModel));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Expense(SplitExpenseVM viewModel)
        {
            if (!ModelState.IsValid)
            {
                var myUser = await userManager.GetUserAsync(HttpContext.User);

                User currentUser = mysticoContext.GetUserByAspUserId(myUser.Id);

                viewModel.CurrencyItem = Library.ConvertCurrencyToSelectListItem(mysticoContext.GetAllCurrencies());
                viewModel.EventItem    = Library.ConvertEventToSelectListItem(mysticoContext.GetActiveEventsByUserId(currentUser.Id));
                viewModel.Date         = DateTime.Today.ToString("u").Replace(" 00:00:00Z", "");
                return(View(viewModel));
            }

            var expenseId = await mysticoContext.CreateExpense(viewModel);

            mysticoContext.CreatePayerForExpense(viewModel.FriendIds, expenseId);

            return(RedirectToAction(nameof(SplitController.Overview), nameof(SplitController).Replace("Controller", ""), new { id = viewModel.SelectedEvent }));
        }