示例#1
0
        public void testStudentMealMappings()
        {
            StudentMeal sm       = new StudentMeal();
            Mappings    mappings = fCfg.Mappings.GetMappings("Default");
            IDictionary map      = new Hashtable();

            map.Add("Balance", "10.55");

            StringMapAdaptor sma = new StringMapAdaptor(map);

            mappings.MapOutbound(sma, sm);

            sm = (StudentMeal)AdkObjectParseHelper.WriteParseAndReturn(sm, fVersion);

            // Assert that the object was mapped correctly
            FSAmounts amounts = sm.Amounts;

            Assertion.AssertNotNull(amounts);
            FSAmount amount = amounts.ItemAt(0);

            Assertion.Assert(amount.Value.HasValue);
            Assertion.AssertEquals(10.55, amount.Value.Value);


            // Now, map the object back to a hashmap and assert it
            IDictionary restoredData = new Hashtable();

            sma = new StringMapAdaptor(restoredData);
            mappings.MapInbound(sm, sma);
            assertMapsAreEqual(map, restoredData);
        }
示例#2
0
        public IHttpActionResult AddMeal(StudentMeal studentMeal)
        {
            var studentInDb = _context.Students.SingleOrDefault(s => s.Id == studentMeal.StudentId);
            var foodMenu    = _context.Meals.Include(f => f.FoodMenu)
                              .SingleOrDefault(m => m.Id == studentMeal.MealId);

            if (studentInDb == null || foodMenu == null)
            {
                return(BadRequest("No student is found"));
            }

            studentInDb.DeuAmount = studentInDb.DeuAmount + foodMenu.FoodMenu.FullPrice;

            studentMeal.AssignToken();

            _context.StudentMeals.Add(studentMeal);

            _context.SaveChanges();
            return(Ok(studentMeal));
        }
示例#3
0
        public IHttpActionResult RemoveMeal(StudentMeal studentMeal)
        {
            var studentInDb = _context.Students.SingleOrDefault(s => s.Id == studentMeal.StudentId);

            var foodMenu = _context.Meals.Include(f => f.FoodMenu)
                           .SingleOrDefault(m => m.Id == studentMeal.MealId);

            var studentMealInDb = _context.StudentMeals.SingleOrDefault(sm =>
                                                                        sm.MealId == studentMeal.MealId && sm.StudentId == studentMeal.StudentId);

            if (studentInDb == null || foodMenu == null || studentMealInDb == null)
            {
                return(BadRequest("No student is found"));
            }


            studentInDb.DeuAmount -= foodMenu.FoodMenu.FullPrice;

            _context.StudentMeals.Remove(studentMealInDb);


            _context.SaveChanges();
            return(Ok(studentMeal));
        }