public async Task <ActionResult <String> > GetCalorieIntakeByDate(String userId, DateTime date)
        {
            var usr = await userCollection.GetById(userId);

            if (usr == null)
            {
                return(NotFound());
            }

            foreach (var i in usr.CalorieIntakeIds)
            {
                var ci = await calorieIntakeCollection.GetById(i);

                if (ci == null)
                {
                    continue;
                }

                if (isSameDay(date, ci.Date))
                {
                    return(ci.Id.ToString());
                }
            }
            var ciNew = new CalorieIntake(ObjectId.Empty, 0, 0, 0, 0, 0, 0, 0, 0, date);

            calorieIntakeCollection.InsertOne(ciNew);
            await this.AddCalorieIntakeToUser(userId, ciNew.Id.ToString());

            return(ciNew.Id.ToString());
        }
Beispiel #2
0
        public async Task <ActionResult <CalorieIntakeDto> > Replace(CalorieIntakeCreationDto calorieIntakeCreationDto, string id)
        {
            var na = new CalorieIntake(ObjectId.Parse(id), calorieIntakeCreationDto.CalorieGoal, calorieIntakeCreationDto.CalorieCurrent, calorieIntakeCreationDto.FatGoal, calorieIntakeCreationDto.FatCurrent, calorieIntakeCreationDto.ProteinGoal, calorieIntakeCreationDto.ProteinCurrent, calorieIntakeCreationDto.CarbohydratesGoal, calorieIntakeCreationDto.CarbohydratesCurrent, calorieIntakeCreationDto.Date);
            await calorieIntakeCollection.ReplaceById(id, na);

            return(Ok(200));
        }
Beispiel #3
0
        public async Task <ActionResult <CalorieIntakeDto> > Add(CalorieIntakeCreationDto calorieIntakeCreationDto)
        {
            var na = new CalorieIntake(ObjectId.Empty, calorieIntakeCreationDto.CalorieGoal, calorieIntakeCreationDto.CalorieCurrent, calorieIntakeCreationDto.FatGoal, calorieIntakeCreationDto.FatCurrent, calorieIntakeCreationDto.ProteinGoal, calorieIntakeCreationDto.ProteinCurrent, calorieIntakeCreationDto.CarbohydratesGoal, calorieIntakeCreationDto.CarbohydratesCurrent, calorieIntakeCreationDto.Date);
            await calorieIntakeCollection.InsertOneAsync(na);

            return(CreatedAtRoute(nameof(GetSingleCalorieIntake), new { na.Id },
                                  new CalorieIntakeDto(na.Id.ToString(), na.CalorieGoal, na.CalorieCurrent, na.FatGoal, na.FatCurrent, na.ProteinGoal, na.ProteinCurrent, na.CarbohydratesGoal, na.CarbohydratesCurrent, na.Date)));
        }
Beispiel #4
0
        public async Task <ActionResult <CalorieIntakeDto> > InitCalorieIntake()
        {
            var na = new CalorieIntake(ObjectId.Empty, 500, 200, 800, 400, 300, 150, 200, 100, DateTime.Now);
            await calorieIntakeCollection.InsertOneAsync(na);

            na = new CalorieIntake(ObjectId.Empty, 500, 200, 800, 400, 300, 150, 200, 100, DateTime.Now);
            await calorieIntakeCollection.InsertOneAsync(na);

            na = new CalorieIntake(ObjectId.Empty, 500, 200, 800, 400, 300, 150, 200, 100, DateTime.Now);
            await calorieIntakeCollection.InsertOneAsync(na);

            return(Ok(200));
        }