コード例 #1
0
        public async Task <IActionResult> EditRecords(DateTime Date, long[] FoodIDs, float[] Quantities)
        {
            if (FoodIDs.Length != Quantities.Length || FoodIDs.Length == 0)
            {
                return(BadRequest());
            }

            FitnessUser currentUser = await userManager.GetUserAsync(HttpContext.User);

            FoodRecord[] existingRecords = await dbContext.FoodRecords.Where(record => record.User == currentUser && record.ConsumptionDate == Date).ToArrayAsync();

            dbContext.FoodRecords.RemoveRange(existingRecords);

            FoodRecord[] newRecords = new FoodRecord[FoodIDs.Length];
            for (int i = 0; i < FoodIDs.Length; i++)
            {
                newRecords[i] = new FoodRecord()
                {
                    ConsumptionDate = Date,
                    User            = currentUser,
                    FoodID          = FoodIDs[i],
                    Quantity        = Quantities[i]
                };
            }
            dbContext.FoodRecords.AddRange(newRecords);
            await dbContext.SaveChangesAsync();

            return(RedirectToAction("AddFood"));
        }
コード例 #2
0
        public async Task <ActionResult> Post(FoodRecord record)
        {
            _dbContext.FoodRecords.Add(record);
            await _dbContext.SaveChangesAsync();

            return(Ok());
        }
コード例 #3
0
        public void Delete(int Id)
        {
            FoodRecord DeleteFoodRecord = db.FoodRecord.Find(Id);

            //delete all data from database
            db.FoodRecord.Remove(DeleteFoodRecord);
            Save();
        }
コード例 #4
0
        public async Task <IActionResult> Post(FoodRecord model)
        {
            await _dbContext.AddAsync(model);

            await _dbContext.SaveChangesAsync();

            return(Ok());
        }
コード例 #5
0
ファイル: HomeController.cs プロジェクト: weicheng95/GLife
        public ActionResult AddFood([Bind(Include = "FoodAmount, Food_Id, FoodType, CreateDate")] FoodRecord foodRecord, FormCollection form)
        {
            foodRecord.Username = User.Identity.Name;;
            foodRecordService.Insert(foodRecord);

            // return JavaScript("location.reload(true)");
            return(RedirectToAction("Record"));
        }
コード例 #6
0
        public void DeleteDataById(int Id)
        {
            FoodRecord data     = db.FoodRecord.Find(Id);
            String     username = data.Username;
            DateTime   date     = data.CreateDate;

            db.FoodRecord.Remove(data);
            Save();

            db.TotalCaloriesCal(date, username);
            Save();
        }
コード例 #7
0
        public async Task <ActionResult> Put(int id, FoodRecord record)
        {
            var exists = await _dbContext.FoodRecords.AnyAsync(x => x.Id == id);

            if (!exists)
            {
                return(NotFound());
            }

            _dbContext.FoodRecords.Update(record);
            await _dbContext.SaveChangesAsync();

            return(Ok());
        }
コード例 #8
0
        public async Task <ActionResult> Put(string id, FoodRecord model)
        {
            var exists = await _dbContext.FoodRecords.AnyAsync(f => f.Id == id);

            if (!exists)
            {
                return(NotFound());
            }

            _dbContext.FoodRecords.Update(model);

            await _dbContext.SaveChangesAsync();

            return(Ok());
        }
コード例 #9
0
ファイル: HomeController.cs プロジェクト: weicheng95/GLife
        public PartialViewResult FoodDBDetail(int?id)
        {
            if (id.HasValue)
            {
                FoodDatabase foodDBDetail = FoodAndSportDBService.GetFoodDataById(id);
                FoodRecord   foodRecord   = new FoodRecord();
                foodRecord.FoodName = foodDBDetail.FoodName;
                foodRecord.Calories = foodDBDetail.Calories;
                foodRecord.Food_Id  = foodDBDetail.Food_Id;
                DateTime date = (DateTime)Session["currentDate"];
                foodRecord.CreateDate = date;
                System.Diagnostics.Debug.WriteLine(foodRecord.CreateDate);

                return(PartialView(foodRecord));
            }
            else
            {
                return(PartialView());
            }
        }
コード例 #10
0
        public async Task <BaseResult> AddFood(User user, string foodName)
        {
            try
            {
                FoodRecord foodRecord = new FoodRecord()
                {
                    UserId     = user.UserId,
                    FoodName   = foodName,
                    CreateTime = DateTime.Now
                };
                _context.FoodRecord.Add(foodRecord);
                await _context.SaveChangesAsync();

                return(new BaseResult());
            }
            catch (Exception e)
            {
                _logger.LogError(e, "");
                return(new BaseResult(-1, e.Message));
            }
        }
コード例 #11
0
        public void Insert(FoodRecord newFoodRecord)
        {
            /*
             * var query = from p in db.FoodDatabase
             *          where ((p.FoodName) == newFoodRecord.FoodName)
             *          select p;
             */

            var query = from p in db.FoodDatabase
                        where ((p.Food_Id) == newFoodRecord.Food_Id)
                        select p;

            //choice from foodDB
            FoodDatabase foodDatabase = query.Single();

            newFoodRecord.Calories = foodDatabase.Calories;
            newFoodRecord.FoodName = foodDatabase.FoodName;
            db.FoodRecord.Add(newFoodRecord);

            Save();

            //use stored procedure to calculate calories spent by date
            db.TotalCaloriesCal(newFoodRecord.CreateDate, newFoodRecord.Username);
        }
コード例 #12
0
        public bool CheckUpdate(int FoodRecord_Id)
        {
            FoodRecord Data = db.FoodRecord.Find(FoodRecord_Id);

            return(Data != null);
        }
コード例 #13
0
        public async Task Post(FoodRecord model)
        {
            await _dbContext.AddAsync(model);

            await _dbContext.SaveChangesAsync();
        }