Exemplo n.º 1
0
        public bool updatePersonFoodById(PersonFood updatePersonFood, int personId, int foodId)
        {
            PersonFood personFood = this.getPersonFoodById(personId, foodId);

            if (personFood == null)
            {
                return(false);
            }
            try{
                //If FoodCount, FoodId, and PersonId are not below 0, they will not be placed
                if (updatePersonFood.FoodCount >= 0)
                {
                    personFood.FoodCount = updatePersonFood.FoodCount;
                }
                if (updatePersonFood.PersonId >= 0)
                {
                    personFood.PersonId = updatePersonFood.PersonId;
                }
                if (updatePersonFood.FoodId >= 0)
                {
                    personFood.FoodId = updatePersonFood.FoodId;
                }
                personFood.RecordTime = new DateTime();
                _db.Update(personFood);
                _db.SaveChanges();
            }catch (Exception) {
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        // METHOD SIGNATURE BEGINS, THIS METHOD IS REQUIRED
        // RETURN AN EMPTY MATRIX IF PREFERRED LUNCH IS NOT FOUND
        public static string[,] matchLunches(string[,] lunchMenuPairs,
                                             string[,] teamCuisinePreference)
        {
            List <PersonFood> personFoods = new List <PersonFood>();

            Dictionary <string, List <string> > cuisineFoodMap = new Dictionary <string, List <string> >();

            // we can build a ht with key as cuisine and key as List of food option
            for (int i = 0; i < lunchMenuPairs.GetLength(0); i++)
            {
                string food    = lunchMenuPairs[i, 0];
                string cuisine = lunchMenuPairs[i, 1];

                if (cuisineFoodMap.ContainsKey(cuisine))
                {
                    cuisineFoodMap[cuisine].Add(food);
                }
                else
                {
                    List <string> foods = new List <string>();
                    foods.Add(food);
                    cuisineFoodMap.Add(cuisine, foods);
                }
            }

            for (int i = 0; i < teamCuisinePreference.GetLength(0); i++)
            {
                string        person  = teamCuisinePreference[i, 0];
                string        cuisine = teamCuisinePreference[i, 1];
                List <string> foods   = new List <string>();

                if (cuisine == "*")
                {
                    foreach (KeyValuePair <string, List <string> > entry in cuisineFoodMap)
                    {
                        foods.AddRange(entry.Value);
                    }
                }
                else
                {
                    if (cuisineFoodMap.ContainsKey(cuisine))
                    {
                        foods = cuisineFoodMap[cuisine];
                    }
                }

                PersonFood personFood = new PersonFood(person, foods);
                personFoods.Add(personFood);
            }

            string[,] result = new string[5, 5];
            // convert the list of person food to 2 d array

            return(result);
        }
Exemplo n.º 3
0
 public bool orderFood(PersonFood order)
 {
     try{
         _db.PersonFoods.Add(order);
         _db.SaveChanges();
     }catch (Exception)
     {
         return(false);
     }
     return(true);
 }
 public ActionResult setPersonFood(PersonFood personFoodIn)
 {
     if (_db.setPersonFood(personFoodIn))
     {
         return(Ok(personFoodIn));
     }
     else
     {
         return(BadRequest());
     }
 }
 public ActionResult UpdatePersonFood(string type, int personId, int foodId, PersonFood personFoodUpdate)
 {
     System.Console.WriteLine(personFoodUpdate.FoodId);
     if (_db.updatePersonFoodById(personFoodUpdate, personId, foodId))
     {
         return(Ok());
     }
     else
     {
         return(BadRequest());
     }
 }
Exemplo n.º 6
0
 public bool setPersonFood(PersonFood person)
 {
     //for set time by server
     //person.RecordTime=new DateTime();
     try{
         _db.PersonFoods.Add(person);
         _db.SaveChanges();
     }catch (Exception)
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 7
0
        public bool deletePersonFoodById(int personId, int foodId)
        {
            PersonFood personFood = this.getPersonFoodById(personId, foodId);

            if (personFood == null)
            {
                return(false);
            }
            try{
                _db.Remove(personFood);
                _db.SaveChanges();
            }catch (Exception) {
                return(false);
            }
            return(true);
        }