Beispiel #1
0
        public async Task <ActionResult> AddStep(GoalVM goal)
        {
            var currentUserProfile = await userProfileUOW.UserProfiles.GetUserProfileAsync(userService.GetUserId());

            if (goal.UserProfileId != currentUserProfile.Id)
            {
                ModelState.AddModelError("Goal", "You cannot add or update goal for another user.");
                return(View(goal));
            }

            var checkGoal = await userProfileUOW.Goals.GetAsync(g => g.Id == goal.Id);

            if (!checkGoal.Any())
            {
                ModelState.AddModelError("Goal", "The provided goal does not exist.");
                return(View(goal));
            }
            var goalStep = Mapper.Map <Step>(goal);

            goalStep.State = Core.Models.ModelState.Added;

            var goalToUpdate = Mapper.Map <Goal>(goal);

            goalToUpdate.Steps.Add(goalStep);

            userProfileUOW.Goals.InsertOrUpdateGraph(goalToUpdate);

            await userProfileUOW.CompleteAsync();

            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public async Task <bool> Create(GoalVM goalVM, string username)
        {
            var user = await this._userService.GetByUsername(username);

            goalVM.UserId    = user.Id;
            goalVM.Remaining = goalVM.Target;
            var goal = this._mapper.Map <Goal>(goalVM);

            return(await this._goalRepostitory.Create(goal));
        }
        public async Task <IActionResult> Edit(GoalVM goalVM)
        {
            if (!ModelState.IsValid)
            {
                AddModelErrors(ModelState);
                return(View(goalVM));
            }

            await this._goalService.Update(goalVM);

            return(RedirectToAction(nameof(All), new { timestamp = DateTime.Now.Ticks })
                   .WithSuccess("Успех!", "Промените бяха запазени."));
        }
        public async Task <IActionResult> Create(GoalVM goalVM)
        {
            if (!ModelState.IsValid)
            {
                AddModelErrors(ModelState);
                return(View(goalVM));
            }

            if (!await this._goalService.Create(goalVM, User.Identity.Name))
            {
                return(View(goalVM));
            }

            return(RedirectToAction(nameof(All), new { timestamp = DateTime.Now.Ticks })
                   .WithSuccess("Успех!", "Финансовата цел беше запазена."));
        }
Beispiel #5
0
        public IActionResult Goal()
        {
            User user = new User();

            user = authProvider.GetCurrentUser();

            Goal goal = new Goal();

            goal = goalDAL.GetCurrentGoal(user.Id);

            GoalVM UsersGoal = new GoalVM();

            UsersGoal.User = user;
            UsersGoal.Goal = goal;

            return(View(UsersGoal));
        }
Beispiel #6
0
        public async Task <ActionResult> AddGoal(GoalVM goal)
        {
            var currentUserProfile = await userProfileUOW.UserProfiles.GetUserProfileAsync(userService.GetUserId());

            if (goal.UserProfileId != currentUserProfile.Id)
            {
                ModelState.AddModelError("Goal", "You cannot add goals for another user.");
                return(View(goal));
            }

            var userGoal = Mapper.Map <Goal>(goal);

            userGoal.State = Core.Models.ModelState.Added;

            currentUserProfile.Goals.Add(userGoal);
            userProfileUOW.UserProfiles.InsertOrUpdateGraph(currentUserProfile);

            await userProfileUOW.CompleteAsync();

            return(RedirectToAction("Index"));
        }
Beispiel #7
0
        public IActionResult GoalCalories(GoalVM goalVM)
        {
            User user = new User();

            user        = authProvider.GetCurrentUser();
            goalVM.User = user;

            Goal currentgoal = goalDAL.GetCurrentGoal(user.Id);

            if (currentgoal.Id == 0)
            {
                goalDAL.CreateGoal(goalVM.Goal, goalVM.User.Id);
                goalVM.Goal.CalorieGoal = goalDAL.CalculateCalorieGoal(goalVM.Goal, user.Id);
                goalDAL.UpdateGoal(goalVM.Goal, goalVM.User.Id);
            }
            else
            {
                goalDAL.UpdateGoal(goalVM.Goal, goalVM.User.Id);
                goalVM.Goal.CalorieGoal = goalDAL.CalculateCalorieGoal(goalVM.Goal, user.Id);
                goalDAL.UpdateGoal(goalVM.Goal, goalVM.User.Id);
            }
            return(RedirectToAction("Goal"));
        }
Beispiel #8
0
 public GoalController(ApplicationDBContext context, IWebHostEnvironment hostEnvironment)
 {
     _context         = context;
     _hostEnvironment = hostEnvironment;
     viewModel        = new GoalVM(_hostEnvironment);
 }
Beispiel #9
0
        public async Task <bool> Update(GoalVM goalVM)
        {
            var goal = this._mapper.Map <Goal>(goalVM);

            return(await this._goalRepostitory.Update(goal));
        }