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")); }
public async Task <ActionResult> Post(FoodRecord record) { _dbContext.FoodRecords.Add(record); await _dbContext.SaveChangesAsync(); return(Ok()); }
public void Delete(int Id) { FoodRecord DeleteFoodRecord = db.FoodRecord.Find(Id); //delete all data from database db.FoodRecord.Remove(DeleteFoodRecord); Save(); }
public async Task <IActionResult> Post(FoodRecord model) { await _dbContext.AddAsync(model); await _dbContext.SaveChangesAsync(); return(Ok()); }
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")); }
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(); }
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()); }
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()); }
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()); } }
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)); } }
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); }
public bool CheckUpdate(int FoodRecord_Id) { FoodRecord Data = db.FoodRecord.Find(FoodRecord_Id); return(Data != null); }
public async Task Post(FoodRecord model) { await _dbContext.AddAsync(model); await _dbContext.SaveChangesAsync(); }