Ejemplo n.º 1
0
        public IActionResult Save(GoalModel goal)
        {
            var userID = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (!ModelState.IsValid)
            {
                var viewModel = new GoalFormViewModel
                {
                    Goal = goal,
                    DefaultCurrencySymbol = _accountService.GetUserDefaultCurrencySymbol(userID)
                };

                return(View("GoalForm", viewModel));
            }

            if (goal.ID == 0)
            {
                _goalService.AddGoal(goal);
            }
            else
            {
                _goalService.UpdateGoal(goal);
            }

            return(RedirectToAction("MainPage", "Transaction"));
        }
Ejemplo n.º 2
0
        public IActionResult Save(GoalFormViewModel goalFormViewModel)
        {
            if (!ModelState.IsValid)
            {
                var categories = _categoriesService.GetCategories().ToList();
                goalFormViewModel.Categories = categories;

                return(View("GoalForm", goalFormViewModel));
            }

            if (goalFormViewModel.Goal.Id == 0)
            {
                goalFormViewModel.Goal.UserId = Convert.ToInt32(User.FindFirstValue(ClaimTypes.NameIdentifier));
                _goalsService.AddNewGoal(goalFormViewModel.Goal);
                _goalsService.Save();
            }
            else
            {
                var goalInDb = _goalsService.GetGoal(goalFormViewModel.Goal.Id);
                goalInDb.Title         = goalFormViewModel.Goal.Title;
                goalInDb.Description   = goalFormViewModel.Goal.Description;
                goalInDb.StartDate     = goalFormViewModel.Goal.StartDate;
                goalInDb.CategoryId    = goalFormViewModel.Goal.CategoryId;
                goalInDb.UserId        = Convert.ToInt32(User.FindFirstValue(ClaimTypes.NameIdentifier));
                goalInDb.IsComplete    = _goalsService.IsGoalCompleted(goalFormViewModel.Goal.IsComplete, goalFormViewModel.Goal.DateCompleted);
                goalInDb.DateCompleted = goalFormViewModel.Goal.DateCompleted;

                _goalsService.Save();
            }

            return(RedirectToAction("Index", "Goals"));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This action will create a new goal.
        /// </summary>
        /// <returns>A view to create goals</returns>
        public IActionResult CreateGoal()
        {
            var newGoal = new GoalFormViewModel()
            {
                Goal       = new Goal(),
                Categories = _categoriesService.GetCategories().ToList()
            };

            return(View("GoalForm", newGoal));
        }
Ejemplo n.º 4
0
        public IActionResult Edit(int id)
        {
            var goal = _goalService.GetGoal(id);

            var viewModel = new GoalFormViewModel
            {
                Goal = goal,
                DefaultCurrencySymbol = goal.Currency.Symbol
            };

            return(View("GoalForm", viewModel));
        }
Ejemplo n.º 5
0
        public ActionResult Edit(int id)
        {
            string UserGuid = User.Identity.GetUserId();
            var    goal     = _context.Goals.SingleOrDefault(g => g.Id == id);

            var viewModel = new GoalFormViewModel
            {
                Goal        = goal,
                DefCurrency = _context.Users.SingleOrDefault(u => u.Id == UserGuid).DefCurrency
            };

            return(View("GoalForm", viewModel));
        }
Ejemplo n.º 6
0
        public ActionResult AddDebt()
        {
            string UserGuid = User.Identity.GetUserId();

            var goal = new Goal
            {
                Type   = 2, /*Взять в долг*/
                UserId = UserGuid
            };

            var viewModel = new GoalFormViewModel
            {
                Goal        = goal,
                DefCurrency = _context.Users.SingleOrDefault(u => u.Id == UserGuid).DefCurrency
            };

            return(View("GoalForm", viewModel));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// This action will help to bring a view to
        /// update the selected goal.
        /// </summary>
        /// <param name="id">Goal ID</param>
        /// <returns>A view to Update goals.</returns>
        public IActionResult UpdateGoal(int id)
        {
            var goal       = _goalsService.GetGoal(id);
            var categories = _categoriesService.GetCategories().ToList();

            var goalFormViewModel = new GoalFormViewModel()
            {
                Goal       = goal,
                CategoryId = goal.CategoryId,
                Categories = categories
            };

            if (goal == null)
            {
                return(BadRequest("Goal Not Found!"));
            }

            return(View("GoalForm", goalFormViewModel));
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> TeamGoalsForm()
        {
            var user = await _userService.GetUser();

            var goals = _context.TeamGoals.Where(g => g.Team.Id == user.Team.Id).ToList();
            GoalFormViewModel viewModel = new GoalFormViewModel
            {
                Goals = goals
            };

            if (goals.Count != 0)
            {
                return(View(viewModel));
            }
            else
            {
                return(View());
            }
        }
Ejemplo n.º 9
0
        public IActionResult Add(byte type)
        {
            var userID          = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var defaultCurrency = _accountService.GetUserDefaultCurrency(userID);

            var goal = new GoalModel
            {
                Type       = type,
                UserID     = userID,
                CurrencyID = defaultCurrency.ID,
                Currency   = defaultCurrency
            };

            var viewModel = new GoalFormViewModel
            {
                Goal = goal,
                DefaultCurrencySymbol = _accountService.GetUserDefaultCurrencySymbol(userID)
            };

            return(View("GoalForm", viewModel));
        }
Ejemplo n.º 10
0
        public async Task <ActionResult> Save(GoalFormViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("TeamGoalsForm", model));
            }
            else
            {
                var user = await _userService.GetUser();

                foreach (var goal in model.Goals)
                {
                    if (goal.Id == null || goal.Id == 0)
                    {
                        goal.Team = user.Team;
                        _context.TeamGoals.Add(goal);
                    }
                    else
                    {
                        var goalToUpdate = _context.TeamGoals.SingleOrDefault(g => g.Id == goal.Id);

                        if (goal.Text == null)
                        {
                            _context.TeamGoals.Remove(goalToUpdate);
                        }
                        else
                        {
                            goalToUpdate.Text       = goal.Text;
                            goalToUpdate.IsAchieved = goal.IsAchieved;
                        }
                    }
                }

                _context.SaveChanges();

                return(Redirect("TeamHome"));
            }
        }
Ejemplo n.º 11
0
        public ActionResult SaveGoal(Goal goal)
        {
            if (!ModelState.IsValid)
            {
                string UserGuid = User.Identity.GetUserId();

                var viewModel = new GoalFormViewModel
                {
                    Goal        = goal,
                    DefCurrency = _context.Users.SingleOrDefault(u => u.Id == UserGuid).DefCurrency
                };

                return(View("GoalForm", viewModel));
            }


            if (goal.Id == 0)
            {
                _context.Goals.Add(goal);

                if (goal.Type == Goal.TypeCredit) //Дать в долг
                {
                    Transaction transaction = new Transaction
                    {
                        Amount     = goal.Amount,
                        CategoryId = _context.Categories.SingleOrDefault(c => c.CreatedBy == "SYS_4").Id,
                        IsSpending = true,
                        Name       = "Дать в долг \"" + goal.GoalName + "\"",
                        UserId     = User.Identity.GetUserId(),
                        TransDate  = DateTime.Now,
                        IsPlaned   = false
                    };
                    _context.Transactions.Add(transaction);
                }
                else if (goal.Type == Goal.TypeDebt) //Взять в долг
                {
                    Transaction transaction = new Transaction
                    {
                        Amount     = goal.Amount,
                        CategoryId = _context.Categories.SingleOrDefault(c => c.CreatedBy == "SYS_6").Id,
                        IsSpending = false,
                        Name       = "Взять в долг \"" + goal.GoalName + "\"",
                        UserId     = User.Identity.GetUserId(),
                        TransDate  = DateTime.Now,
                        IsPlaned   = false
                    };
                    _context.Transactions.Add(transaction);
                }
            }
            else /*Редактирование*/
            {
                var goalInDb = _context.Goals.Single(g => g.Id == goal.Id);
                goalInDb.GoalName     = goal.GoalName;
                goalInDb.Amount       = goal.Amount;
                goalInDb.CurAmount    = goal.CurAmount;
                goalInDb.CompleteDate = goal.CompleteDate;
                goalInDb.IsActive     = goal.IsActive;
            }
            _context.SaveChanges();

            return(RedirectToAction("MyBudget", "Transactions"));
        }