public IActionResult UpdateGoal(long id, [FromBody] GoalRequest goalRequest)
        {
            if (goalRequest.Status == null)
            {
                return(GetResultBadRequest());
            }

            var hasField = typeof(GoalStatus).GetFields(BindingFlags.Public | BindingFlags.Static)
                           .Select(x => x.GetRawConstantValue().ToString()).Contains(goalRequest.Status);

            if (!hasField)
            {
                return(GetResultBadRequest());
            }

            try
            {
                _goalService.UpdateGoal(id, goalRequest);
                return(GetResultSuccess());
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(GetResultInternalError());
            }
        }
예제 #2
0
 public Goal UpdateGoal(Goal existingGoal, GoalRequest request)
 {
     existingGoal.Target       = request.Target;
     existingGoal.IsPrivate    = request.IsPrivate;
     existingGoal.InitialValue = request.InitialValue;
     return(existingGoal);
 }
예제 #3
0
        public async Task <GoalResponse> AddGoal(Guid userId, GoalRequest request)
        {
            var challenge = _mappingService.CreateChallenge(request);
            var goal      = _mappingService.CreateGoal(userId, challenge.ChallengeId, request);

            _challengeRepo.Create(challenge);
            _goalRepo.Create(goal);
            await _goalRepo.Save();

            return(new GoalResponse(goal));
        }
예제 #4
0
 public Goal CreateGoal(Guid userId, Guid challengeId, GoalRequest request)
 {
     return(new Goal
     {
         UserId = userId,
         ChallengeId = challengeId,
         InitialValue = request.InitialValue,
         Target = request.Target,
         IsPrivate = request.IsPrivate
     });
 }
예제 #5
0
        public async Task <bool> IsGoalSetAsync(GoalRequest goal)
        {
            if (_connectedService)
            {
                var  goalRestService = new GoalRestService();
                bool result          = await goalRestService.IsGoalSetAsync(goal);

                return(result);
            }
            else
            {
            }
            return(false);
        }
예제 #6
0
        public async Task <IActionResult> SubmitedUserGoal(GoalRequest request)
        {
            var userId = User.ParseUserId();
            var result = await _userGoalsManager.SubmitUserGoalAsync(userId, request.GoalId);

            if (result)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
예제 #7
0
        public async Task <IActionResult> TakePartInGlobalGoal(GoalRequest request)
        {
            var userId = User.ParseUserId();

            var result = await _globalGoalsManager.TakePartInGlobalGoalsAsync(userId, request.GoalId);

            if (result)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
예제 #8
0
        public async Task <List <Goal> > GetGoalAsync(GoalRequest goal)
        {
            List <Goal> result;

            if (_connectedService)
            {
                var goalRestService = new GoalRestService();
                result = await goalRestService.GetGoalsAsync(goal);
            }
            else
            {
                result = new GoalDataProvider(_dbPath, _platform).Query("SELECT * FROM GOAL ", new object[] { });
            }
            return(result);
        }
예제 #9
0
        public async Task <GoalResponse> UpdateGoal(Guid userId, Guid goalId, GoalRequest request)
        {
            var existingGoal = await _goalRepo.Get(goalId);

            existingGoal.EnsureExists("Goal not found.");

            VerifyUserOwnsGoal(userId, existingGoal);

            var updatedChallenge = _mappingService.UpdateChallenge(existingGoal.Challenge, request);
            var updatedGoal      = _mappingService.UpdateGoal(existingGoal, request);

            _challengeRepo.Update(updatedChallenge);
            _goalRepo.Update(updatedGoal);
            await _goalRepo.Save();

            return(new GoalResponse(updatedGoal));
        }
예제 #10
0
 public void UpdateGoal(long id, GoalRequest goalRequest)
 {
     try
     {
         var goal        = _goalRepository.Get(id);
         var goalUpdated = new Goal()
         {
             GoalId     = goal.GoalId,
             JobId      = goal.JobId,
             LocationId = goal.LocationId,
             Status     = goalRequest.Status,
         };
         _goalRepository.Update(goal, goalUpdated);
     }
     catch (Exception e)
     {
         throw new Exception(e.ToString());
     }
 }
 public async Task <ActionResult <GoalResponse> > UpdateGoal(Guid goalId, GoalRequest request)
 {
     return(Ok(await _goalService.UpdateGoal(UserId, goalId, request)));
 }
 public async Task <ActionResult <GoalResponse> > AddGoal(GoalRequest request)
 {
     return(Ok(await _goalService.AddGoal(UserId, request)));
 }