예제 #1
0
        public void AddDietLog()
        {
            if (SelectedDietDay == null || string.IsNullOrWhiteSpace(FoodAmount) || !double.TryParse(FoodAmount, out double amount))
            {
                return;
            }

            var dietLog = new DietLog
            {
                AddedDate  = SelectedDietDay.Date,
                DietFoodId = SelectedDietFood.Id,
                Amount     = amount
            };

            using var db = new AppDbContext();
            db.DietLogs.Add(dietLog);
            db.SaveChanges();

            SelectedDietDay.DietLogItems.Insert(0, new DietLogItem
            {
                DietLog  = dietLog,
                DietFood = SelectedDietFood
            });

            FoodAmount       = null;
            SelectedDietFood = null;
            SelectedDietNutrientAndEnergyValue = null;
        }
 public DietLogDTO(DietLog Dl)
 {
     foreach (var propertyInfo in typeof(DietLog).GetProperties())
     {
         propertyInfo.SetValue(this, propertyInfo.GetValue(Dl));
     }
 }
예제 #3
0
        public bool Add(DietLogDTO entity)
        {
            DietLog dietlog = new DietLog();

            dietlog.MemberID     = entity.MemberID;
            dietlog.TimeOfDayID  = entity.TimeOfDayID;
            dietlog.MealOptionID = entity.MealOptionID;
            dietlog.EditTime     = entity.EditTime;
            dietlog.Portion      = entity.Portion;
            dietlog.Date         = entity.Date;
            return(dao.Add(dietlog));
        }
예제 #4
0
 public bool Add(DietLog dietLog)
 {
     try
     {
         db.DietLogs.Add(dietLog);
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #5
0
        internal DietLogDTO GetDietLog(int dietLogID)
        {
            try
            {
                DietLog theDLog = db.DietLogs.FirstOrDefault(dl => dl.ID == dietLogID);

                DietLogDTO dto = new DietLogDTO(theDLog);
                return(dto);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #6
0
        internal bool DeleteDietLog(int dietLogID)
        {
            try
            {
                DietLog d = db.DietLogs.FirstOrDefault(dl => dl.ID == dietLogID);
                db.DietLogs.Remove(d);
                db.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #7
0
        internal bool UpdateDietLogPortion(int dietLogID, double newPortion)
        {
            try
            {
                DietLog theRecord = db.DietLogs.FirstOrDefault(dl => dl.ID == dietLogID);

                theRecord.Portion  = newPortion;
                theRecord.EditTime = DateTime.Now;
                db.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }