public async Task <CustomApiResult> Update([FromBody] Goal value)
        {
            //NOTE
            //userId is immutable

            // We do this manually as this endpoint will handle all updates to the user obj
            // and we want to be able to send in only the changed fields data
            var savedGoal = await _goalService.Get(value.Id);

            // These are the only fields we allow changing
            if (!string.IsNullOrWhiteSpace(value.GoalFriendlyName))
            {
                savedGoal.GoalFriendlyName = value.GoalFriendlyName;
            }

            if (!string.IsNullOrWhiteSpace(value.DailyGoalTogglID))
            {
                savedGoal.DailyGoalTogglID = value.DailyGoalTogglID;
            }

            if ((value.DailyGoalTimeInMs != int.MinValue || value.DailyGoalTimeInMs != int.MaxValue) && value.DailyGoalTimeInMs > 0)
            {
                savedGoal.DailyGoalTimeInMs = value.DailyGoalTimeInMs;
            }

            if (value.DailyGoalTrackStyle != TrackTypeConstants.TrackType.None)
            {
                savedGoal.DailyGoalTrackStyle = value.DailyGoalTrackStyle;
            }

            await _goalService.Update(savedGoal);

            return(new CustomApiResult(_responseHelper.ValidResponse()));
        }
Ejemplo n.º 2
0
        public async Task TestGetGoals_CheckProperties()
        {
            var goal = new Goal
            {
                GoalId   = 1,
                GoalName = "goal"
            };

            context.Goals.Add(goal);
            Action <PagedQueryResults <GoalDTO> > tester = (results) =>
            {
                Assert.AreEqual(1, results.Total);
                Assert.AreEqual(1, results.Results.Count);

                var firstResult = results.Results.First();
                Assert.AreEqual(goal.GoalId, firstResult.Id);
                Assert.AreEqual(goal.GoalName, firstResult.Name);
            };
            var defaultSorter = new ExpressionSorter <GoalDTO>(x => x.Id, SortDirection.Ascending);
            var queryOperator = new QueryableOperator <GoalDTO>(0, 10, defaultSorter);

            var serviceResults      = service.Get(queryOperator);
            var serviceResultsAsync = await service.GetAsync(queryOperator);

            tester(serviceResults);
            tester(serviceResultsAsync);
        }
Ejemplo n.º 3
0
        public override void Post([FromBody] Investment investment)
        {
            Goal goal = GoalService.Get(investment.GoalId);

            if (goal != null)
            {
                Service.Create(investment);
            }
        }