Ejemplo n.º 1
0
        public async Task <IActionResult> AddTodayWeight(float Weight)
        {
            if (Weight <= 0 || Weight >= 200)
            {
                return(BadRequest());
            }

            FitnessUser currentUser = await GetUser();

            BodyweightRecord newRecord = new BodyweightRecord()
            {
                User   = currentUser,
                Date   = DateTime.Today,
                Weight = Weight
            };

            await storageService.StoreBodyweightRecord(newRecord);

            return(RedirectToAction("Summary"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> EditRecords(DateTime[] Dates, float[] Weights)
        {
            if (Dates == null || Weights == null)
            {
                return(BadRequest());
            }
            if (Dates.Length != Weights.Length)
            {
                return(BadRequest());
            }

            for (int i = 0; i < Dates.Length; i++)
            {
                if (Weights[i] <= 0 || Weights[i] >= 200)
                {
                    return(BadRequest());
                }
            }

            FitnessUser currentUser = await GetUser();

            await storageService.DeleteExistingRecords(currentUser);

            BodyweightRecord[] records = new BodyweightRecord[Dates.Length];
            for (int i = 0; i < Dates.Length; i++)
            {
                BodyweightRecord newRecord = new BodyweightRecord()
                {
                    User   = currentUser,
                    Date   = Dates[i],
                    Weight = Weights[i]
                };
                records[i] = newRecord;
            }

            await storageService.StoreBodyweightRecords(records);

            return(RedirectToAction("Summary"));
        }
 public async Task StoreBodyweightRecord(BodyweightRecord Record)
 {
     dbContext.BodyweightRecords.Add(Record);
     await dbContext.SaveChangesAsync();
 }