public void Can_Deserialize_Weight() { string content = File.ReadAllText(SampleData.PathFor("Weight.txt")); var deserializer = new RestSharp.Deserializers.XmlDeserializer(); deserializer.RootElement = "weight"; Weight result = deserializer.Deserialize <Weight>(new RestResponse() { Content = content }); Assert.IsNotNull(result); Assert.IsTrue(result.Weights.Count == 2); WeightLog log = result.Weights[0]; Assert.AreEqual(log.LogId, 1330991999000); Assert.AreEqual(log.Bmi, 23.566633224487305); Assert.AreEqual(log.Date, new DateTime(2012, 3, 5)); Assert.AreEqual(log.Time, new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59)); Assert.AreEqual(log.Weight, 73); Assert.AreEqual(log.DateTime, new DateTime(2012, 3, 5, 23, 59, 59)); log = result.Weights[1]; Assert.AreEqual(log.LogId, 1330991999000); Assert.AreEqual(log.Bmi, 22.566633224487305); Assert.AreEqual(log.Date, new DateTime(2012, 3, 5)); Assert.AreEqual(log.Time, new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 21, 10, 59)); Assert.AreEqual(log.Weight, 72.5); Assert.AreEqual(log.DateTime, new DateTime(2012, 3, 5, 21, 10, 59)); }
public void Delete(int ID) { WeightLog weight = db.WeightLogs.First(x => x.ID == ID); db.WeightLogs.Remove(weight); db.SaveChanges(); }
private void ParseStats(WeightLog wl) { analyserEntry.Byte0 = wl.Byte0; analyserEntry.Byte1 = wl.Byte1; analyserEntry.Byte2 = wl.Byte2; analyserEntry.Byte3 = wl.Byte3; analyserEntry.Byte4 = wl.Byte4; analyserEntry.Byte5 = wl.Byte5; analyserEntry.Byte6 = wl.Byte6; analyserEntry.Byte7 = wl.Byte7; analyserEntry.Byte8 = wl.Byte8; analyserEntry.Byte9 = wl.Byte9; analyserEntry.Byte10 = wl.Byte10; analyserEntry.Byte11 = wl.Byte11; analyserEntry.Byte12 = wl.Byte12; analyserEntry.Byte13 = wl.Byte13; analyserEntry.Byte14 = wl.Byte14; analyserEntry.Byte15 = wl.Byte15; analyserEntry.Byte16 = wl.Byte16; analyserEntry.Byte17 = wl.Byte17; analyserEntry.Byte18 = wl.Byte18; analyserEntry.Byte19 = wl.Byte19; analyserEntry.Byte20 = wl.Byte20; analyserEntry.Byte21 = wl.Byte21; analyserEntry.Byte22 = wl.Byte22; analyserEntry.Byte23 = wl.Byte23; analyserEntry.Byte24 = wl.Byte24; analyserEntry.Byte25 = wl.Byte25; analyserEntry.Byte26 = wl.Byte26; analyserEntry.Byte27 = wl.Byte27; analyserEntry.Byte28 = wl.Byte28; analyserEntry.Byte29 = wl.Byte29; analyserEntry.Byte30 = wl.Byte30; analyserEntry.Byte31 = wl.Byte31; }
private void ValidateWeight(Weight weight) { Assert.IsNotNull(weight); Assert.AreEqual(2, weight.Weights.Count); WeightLog log = weight.Weights.First(); Assert.IsNotNull(log); Assert.AreEqual(new DateTime(2012, 3, 5), log.Date); Assert.AreEqual(1330991999000, log.LogId); Assert.AreEqual(73f, log.Weight); Assert.AreEqual(23.57f, log.Bmi); Assert.AreEqual(new DateTime(2012, 3, 5, 23, 59, 59).TimeOfDay, log.Time.TimeOfDay); weight.Weights.Remove(log); log = weight.Weights.First(); Assert.IsNotNull(log); Assert.AreEqual(new DateTime(2012, 3, 5), log.Date); Assert.AreEqual(1330991999000, log.LogId); Assert.AreEqual(72.5f, log.Weight); Assert.AreEqual(22.57f, log.Bmi); Assert.AreEqual(new DateTime(2012, 3, 5, 21, 10, 59).TimeOfDay, log.Time.TimeOfDay); }
public async Task <IActionResult> PutWeightLog(int id, WeightLog weightLog) { if (id != weightLog.WeightLogId) { return(BadRequest()); } _context.Entry(weightLog).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WeightLogExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <WeightLog> > PostWeightLog(WeightLog weightLog) { _context.WeightLogs.Add(weightLog); await _context.SaveChangesAsync(); return(CreatedAtAction("GetWeightLog", new { id = weightLog.WeightLogId }, weightLog)); }
public ActionResult DeleteConfirmed(int id) { WeightLog weightLog = db.WeightLogs.Find(id); db.WeightLogs.Remove(weightLog); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Delete(Guid id) { WeightLog weightLog = await _weigtLogManageService.FindWeightLogById(id); await _weigtLogManageService.Remove(weightLog); return(RedirectToAction(nameof(TableController.Index), "Table")); }
public void Add(WeightLogDetailDTO entity) { WeightLog weightLog = new WeightLog(); weightLog.MemberID = entity.MemberID; weightLog.Weight = entity.Weight; weightLog.UpdatedDate = entity.UpdatedDate; dao.Add(weightLog); }
public WeightEditPage() { InitializeComponent(); var weightLog = new WeightLog { Date = DateTime.Now, Weight = 0 }; }
public ActionResult Edit([Bind(Include = "ID,PersonID,Weight,WeightDate,Deleted,Notes")] WeightLog weightLog) { if (ModelState.IsValid) { db.Entry(weightLog).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(weightLog)); }
public void Update(WeightLogDetailDTO entity) { WeightLog weight = new WeightLog(); weight.ID = entity.ID; weight.MemberID = entity.MemberID; weight.Weight = entity.Weight; weight.UpdatedDate = entity.UpdatedDate; dao.Update(weight); }
public void WeightLog_DateTime_Mash() { DateTime date = new DateTime(2014, 10, 2); DateTime time = new DateTime(1970, 1, 1, 12, 45, 56); WeightLog weightLog = new WeightLog(); weightLog.Date = date; weightLog.Time = time; Assert.AreEqual(new DateTime(2014, 10, 2, 12, 45, 56), weightLog.DateTime); }
public Task <int> SaveWeightAsync(WeightLog weightlog) { if (weightlog.Id != 0) { return(database.UpdateAsync(weightlog)); } else { return(database.InsertAsync(weightlog)); } }
private IWeightlog WeightLogViewModelToInterface(LogAddWeightLogViewModel viewmodel) { var weightLog = new WeightLog { DateTime = DateTime.Now, User = AuthController.GetAuthUser(User), Weight = viewmodel.Weight }; return(weightLog); }
public ActionResult Create([Bind(Include = "ID,PersonID,Weight,WeightDate,Deleted,Notes")] WeightLog weightLog) { if (ModelState.IsValid) { weightLog.PersonID = Convert.ToInt32(Request.Cookies["SDNWebApps"]["SDNID"]); db.WeightLogs.Add(weightLog); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(weightLog)); }
public void Add(WeightLog weightLog) { try { db.WeightLogs.Add(weightLog); db.SaveChanges(); } catch (Exception ex) { throw ex; } }
public void Log_Single_Fat_Today() { Random r = new Random(); DateTime today = DateTime.Today; float fat = r.Next(10, 30); WeightLog response = client.LogWeight(today, fat, "-"); Assert.AreEqual(fat, response.Weight); Assert.AreNotEqual(-1, response.LogId); Assert.AreEqual(today, response.Date); }
public Task UpdateWeightLog(WeightLogTableViewModel weightLogViewModel) { return(Task.Run(() => { WeightLog weightLog = _context.WeightLogs.Find(weightLogViewModel.Id); weightLog.WeightValue = weightLogViewModel.WeightValue; _context.Update(weightLog); return _context.SaveChangesAsync(); })); }
public void Update(WeightLog entity) { try { WeightLog weightLog = db.WeightLogs.First(x => x.ID == entity.ID); weightLog.MemberID = entity.MemberID; weightLog.Weight = entity.Weight; db.SaveChanges(); } catch (Exception ex) { throw ex; } }
// GET: Cardio/WeightLogs/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } WeightLog weightLog = db.WeightLogs.Find(id); if (weightLog == null) { return(HttpNotFound()); } return(View(weightLog)); }
public Task Add(WeightLog weightLog) { WeightLog weightLogFromDatabase = _context.WeightLogs.FirstOrDefault(wl => wl.LogDate == weightLog.LogDate); if (weightLogFromDatabase == null) { _context.WeightLogs.AddAsync(weightLog); } else { weightLogFromDatabase.WeightValue = weightLog.WeightValue; _context.WeightLogs.Update(weightLogFromDatabase); } return(_context.SaveChangesAsync()); }
public async Task <IActionResult> Edit(Guid id) { WeightLog weightLog = await _weigtLogManageService.FindWeightLogById(id); var user = await _applicationUserService.GetUserByName(this.User.Identity.Name); ViewBag.MeasureType = user.MeasureType; if (user.MeasureType == Enums.MeasureType.lbs) { weightLog = WeightConverter.ConvertToLbs(weightLog); } WeightLogViewModel weightLogViewModel = _mapper.Map <WeightLogViewModel>(weightLog); return(View(weightLogViewModel)); }
//Weights are stored as serialised strings rather than objects - lazy me. private void SerialiseWeightsAndSaveToDB(double[] weightStatistics, List <double[]> weights1, List <double[]> weights2, List <double[]> weights3, List <double[]> weights4) { BTCCrackerDBContext wdbc = new BTCCrackerDBContext(); WeightLog ws = new WeightLog(); ws.WeightsHL0 = SerialiseWeights(weights1); ws.WeightsHL1 = SerialiseWeights(weights2); ws.WeightsHL2 = SerialiseWeights(weights3); ws.WeightsOL = SerialiseWeights(weights4); ws.Byte0 = (int)weightStatistics[0]; ws.Byte1 = (int)weightStatistics[1]; ws.Byte2 = (int)weightStatistics[2]; ws.Byte3 = (int)weightStatistics[3]; ws.Byte4 = (int)weightStatistics[4]; ws.Byte5 = (int)weightStatistics[5]; ws.Byte6 = (int)weightStatistics[6]; ws.Byte7 = (int)weightStatistics[7]; ws.Byte8 = (int)weightStatistics[8]; ws.Byte9 = (int)weightStatistics[9]; ws.Byte10 = (int)weightStatistics[10]; ws.Byte11 = (int)weightStatistics[11]; ws.Byte12 = (int)weightStatistics[12]; ws.Byte13 = (int)weightStatistics[13]; ws.Byte14 = (int)weightStatistics[14]; ws.Byte15 = (int)weightStatistics[15]; ws.Byte16 = (int)weightStatistics[16]; ws.Byte17 = (int)weightStatistics[17]; ws.Byte18 = (int)weightStatistics[18]; ws.Byte19 = (int)weightStatistics[19]; ws.Byte20 = (int)weightStatistics[20]; ws.Byte21 = (int)weightStatistics[21]; ws.Byte22 = (int)weightStatistics[22]; ws.Byte23 = (int)weightStatistics[23]; ws.Byte24 = (int)weightStatistics[24]; ws.Byte25 = (int)weightStatistics[25]; ws.Byte26 = (int)weightStatistics[26]; ws.Byte27 = (int)weightStatistics[27]; ws.Byte28 = (int)weightStatistics[28]; ws.Byte29 = (int)weightStatistics[29]; ws.Byte30 = (int)weightStatistics[30]; ws.Byte31 = (int)weightStatistics[31]; wdbc.Add(ws); wdbc.SaveChanges(); }
public async Task <IActionResult> Create(WeightLogViewModel weightLogViewModel) { if (ModelState.IsValid) { WeightLog newWeightLog = _mapper.Map <WeightLog>(weightLogViewModel); var user = await _applicationUserService.GetUserByName(this.User.Identity.Name); newWeightLog.User = user; newWeightLog = user.MeasureType == Enums.MeasureType.lbs ? WeightConverter.ConvertToKg(newWeightLog) : newWeightLog; await _weigtLogManageService.Add(newWeightLog); return(RedirectToAction(nameof(TableController.Index), "Table"));; } return(View(weightLogViewModel)); }
public void Retrieve_Weight_Last_Week() { DateTime startDate = DateTime.Now.AddDays(-7); DateTime endDate = DateTime.Now; Weight weights = client.GetWeight(startDate, endDate); Assert.IsNotNull(weights); Assert.IsNotNull(weights.Weights); Assert.IsTrue(weights.Weights.Count > 0); WeightLog firstWeight = weights.Weights[0]; Assert.GreaterOrEqual(firstWeight.DateTime, startDate.Date); Assert.Less(firstWeight.DateTime, endDate.AddDays(1).Date); Assert.IsTrue(firstWeight.LogId > 0); Assert.IsTrue(firstWeight.Bmi > 0); Assert.IsTrue(firstWeight.Weight > 0); }
//SaveWeight() saves WeightLog in the database public WeightLog SaveWeight(WeightLogModel weight) { //open a connection to a database FitnesspointDatabase using (var context = new FitnesspointDatabaseEntities()) { //Creating WieghtLog object and assigning data using WeightLogModel class WeightLog weightLog = new WeightLog() { Weight = weight.Weight, Created_At = DateTime.UtcNow, Updated_At = DateTime.UtcNow, UserId = weight.UserId }; //add weightLog to the database WeightLog using model WeightLog context.WeightLogs.Add(weightLog); //save the changes to the database context.SaveChanges(); return(weightLog); } }
public async Task <IActionResult> Add([FromBody] WeightLogBindingModel model) { var user = await _userManager.GetUserAsync(User); var existingLogForToday = await _dbContext.WeightLogs.AnyAsync(l => l.LoggedOn.Date == DateTime.UtcNow.Date && l.UserId == user.Id); if (existingLogForToday) { return(BadRequest("You already log your weight today")); } var log = new WeightLog() { LoggedOn = DateTime.UtcNow, UserId = user.Id, Weight = model.Weight }; _dbContext.WeightLogs.Add(log); await _dbContext.SaveChangesAsync(); return(Ok()); }
public static WeightLog ConvertToLbs(WeightLog log) { log.WeightValue = log.WeightValue / (float)0.45359237; return(log); }
public Task <int> DeleteWeightAsync(WeightLog weightlog) { return(database.DeleteAsync(weightlog)); }