public int AddFoodUsage(JournalItemModel foodUsageModel)
        {
            var portions = foodUsageModel.portions.Select(portionModel => new Portion
            {
                Size       = portionModel.size,
                UnitId     = portionModel.unit.id,
                BreadUnits = portionModel.breadUnits,
                ProductId  = portionModel.product.id
            }).ToList();

            using (var context = new EasyScheduleDatabaseEntities())
            {
                var newFoodUsage = new JournalItem
                {
                    JournalItemTypeId = (int)Enums.JournalItemTypes.FoodUsage,
                    FoodUsageTypeId   = foodUsageModel.foodUsageType.id,
                    Time     = foodUsageModel.time,
                    Value    = foodUsageModel.value,
                    Portions = portions
                };
                context.JournalItems.Add(newFoodUsage);
                context.SaveChanges();
                return(newFoodUsage.Id);
            }
        }
 public void UpdateSugar(int id, JournalItemModel model)
 {
     using (var context = new EasyScheduleDatabaseEntities())
     {
         var editedSugar = new JournalItem {
             Id = id
         };
         context.JournalItems.Attach(editedSugar);
         editedSugar.Value = model.value;
         editedSugar.Time  = model.time;
         context.SaveChanges();
     }
 }
 public int AddSugar(JournalItemModel shugarModel)
 {
     using (var context = new EasyScheduleDatabaseEntities())
     {
         var newSugar = new JournalItem
         {
             JournalItemTypeId = (int)Enums.JournalItemTypes.Sugar,
             Time  = shugarModel.time,
             Value = shugarModel.value
         };
         context.JournalItems.Add(newSugar);
         context.SaveChanges();
         return(newSugar.Id);
     }
 }
 public void UpdateInsulinusage(int id, JournalItemModel model)
 {
     using (var context = new EasyScheduleDatabaseEntities())
     {
         var editedIsulinUsage = new JournalItem()
         {
             Id = id
         };
         context.JournalItems.Attach(editedIsulinUsage);
         editedIsulinUsage.Time          = model.time;
         editedIsulinUsage.Value         = model.value;
         editedIsulinUsage.InsulinTypeId = model.insulinType.id;
         context.SaveChanges();
     }
 }
 public int AddInsulinUsage(JournalItemModel insulinUsageModel)
 {
     using (var context = new EasyScheduleDatabaseEntities())
     {
         var newInsulin = new JournalItem
         {
             JournalItemTypeId = (int)Enums.JournalItemTypes.InsulinUsage,
             InsulinTypeId     = insulinUsageModel.insulinType.id,
             Time  = insulinUsageModel.time,
             Value = insulinUsageModel.value
         };
         context.JournalItems.Add(newInsulin);
         context.SaveChanges();
         return(newInsulin.Id);
     }
 }
        public JournalItemModel ToModel()
        {
            var result = new JournalItemModel
            {
                id = Id,
                journalItemTypeId = JournalItemTypeId,
                time  = Time,
                value = Value
            };

            if (JournalItemTypeId == (int)Enums.JournalItemTypes.InsulinUsage)
            {
                result.insulinType = InsulinType.ToModel();
            }
            if (JournalItemTypeId == (int)Enums.JournalItemTypes.FoodUsage)
            {
                result.foodUsageType = FoodUsageType.ToModel();
            }
            return(result);
        }
Exemple #7
0
 // PUT api/sugars/5
 public void Put(int id, JournalItemModel value)
 {
     (new ScheduleService()).UpdateSugar(id, value);
 }
Exemple #8
0
 // POST api/sugars
 public int Post(JournalItemModel value)
 {
     return((new ScheduleService()).AddSugar(value));
 }
Exemple #9
0
 // POST api/foodusages
 public int Post(JournalItemModel model)
 {
     return((new ScheduleService()).AddFoodUsage(model));
 }
 // PUT api/insulinusages/5
 public void Put(int id, JournalItemModel value)
 {
     (new ScheduleService()).UpdateInsulinusage(id, value);
 }
 // POST api/insulinusages
 public void Post(JournalItemModel value)
 {
     (new ScheduleService()).AddInsulinUsage(value);
 }