예제 #1
0
 public MenuRecord UpdateMenuRecord([FromBody]MenuRecord record)
 {
     var excistingRecord = context.MenuRecords
         .FirstOrDefault(r => r.MenuRecordId == record.MenuRecordId);
     if(excistingRecord != null)
     {
         var nutritionManager = new NutritionManager(context, User.GetUserId());
         nutritionManager.AddOrUpdateProduct(record.Product);
         excistingRecord.Product = record.Product;
         excistingRecord.Weight = record.Weight;
         context.Update(excistingRecord);
         context.SaveChanges();
     }
     return record;
 }
예제 #2
0
 public MenuRecord AddMenuRecord([FromBody]MenuRecordViewModel model)
 {
     var menu = context.Menus.Include(m => m.MenuRecords).FirstOrDefault(m => m.MenuId == model.MenuId);
     var record = model.MenuRecord;
     if (menu != null)
     {
         var nutritionManager = new NutritionManager(context, User.GetUserId());
         nutritionManager.AddOrUpdateProduct(model.MenuRecord.Product);
         context.MenuRecords.Add(record);
         menu.MenuRecords.Add(record);
         context.Attach(menu);
         context.SaveChanges();
     }; 
     return record;
 }
예제 #3
0
 public OperationResult Create([FromBody]Dish dish)
 {
     if (!ModelState.IsValid)
     {
         return OperationResult.Error(ModelState);
     }
     dish.Author = User.GetUserName();
     dish.DishId = 0;
     var nutritionManager = new NutritionManager(context, User.GetUserId());
     foreach(var record in dish.Products.MenuRecords)
     {
         record.MenuRecordId = 0;
         nutritionManager.AddOrUpdateProduct(record.Product);
         context.Add(record);
     }
     dish.Products.MenuId = 0;
     context.Add(dish.Products);
     context.Dishes.Add(dish);
     context.SaveChanges();
     return OperationResult.Success();
 }
예제 #4
0
 public void RememberDish([FromBody]Dish dish)
 {
     var nutritionManager = new NutritionManager(context, User.GetUserId());
     nutritionManager.AddOrUpdateProduct(CreateProduct(dish));
     context.SaveChanges();
 }