예제 #1
0
        public Challenge CreateChallenge(RestContext context, ChallengeViewModel cvm)
        {
            var challenge = CreateInstance();

            FillGeneralData(challenge, cvm);
            FillSpecificData(challenge, context, cvm);

            return(challenge);
        }
예제 #2
0
 private void FillGeneralData(Challenge challenge, ChallengeViewModel data)
 {
     challenge.Date = DateTime.Now;
     challenge.Done = false;
     challenge.Type = data.Type;
     if (data.Type.Contains("."))
     {
         string[] parts = data.Type.Split('.');
         challenge.Type = parts[0];
         data.Type      = parts[1];
     }
 }
예제 #3
0
 protected override void FillSpecificData(Challenge challenge, RestContext context, ChallengeViewModel data)
 {
 }
예제 #4
0
 /// <summary>
 /// Fill the challenge with challengespecific data.
 /// </summary>
 /// <param name="challenge">The object to be filled.</param>
 /// <param name="context">Context where you can get data.</param>
 protected abstract void FillSpecificData(Challenge challenge, RestContext context, ChallengeViewModel data);
예제 #5
0
        protected override void FillSpecificData(Challenge challenge, RestContext context, ChallengeViewModel data)
        {
            var restaurant = context.Restaurants.FirstOrDefault(r => r.RestaurantId == data.RestaurantId);
            var c          = (challenge as RestaurantChallenge);

            if (restaurant == null)
            {
                throw new NullReferenceException($"Restaurant with id {data.RestaurantId} was not found.");
            }

            c.Earnings   = 3;
            c.Restaurant = restaurant;
        }
예제 #6
0
        protected override void FillSpecificData(Challenge challenge, RestContext context, ChallengeViewModel data)
        {
            var recipe = context.Recipes.FirstOrDefault(r => r.RecipeId == data.RecipeId);
            var c      = (challenge as RecipeChallenge);

            if (recipe == null)
            {
                throw new NullReferenceException($"Recipe with id {data.RecipeId} was not found.");
            }

            c.Recipe     = recipe;
            c.PrepareFor = (TargetSubject)R.Next(0, 4);
            c.Earnings   = 1;
            c.Thumbnail  = recipe.Image;
        }
예제 #7
0
        protected override void FillSpecificData(Challenge challenge, RestContext context, ChallengeViewModel data)
        {
            var c = challenge as CreativeCookingChallenge;

            if (data.IngredientsId == null)
            {
                throw new NullReferenceException("Ingredients are required.");
            }

            if (data.RecipeId == -1)
            {
                throw new ArgumentException("Well then please just give a recipe.");
            }

            var recipe = context.Recipes.FirstOrDefault(r => r.RecipeId == data.RecipeId);

            if (recipe == null)
            {
                throw new NullReferenceException($"No recipe was found with id {data.RecipeId}.");
            }
            c.Recipe = recipe;

            foreach (int ingredientId in data.IngredientsId)
            {
                var ingredient = context.Ingredients.FirstOrDefault(i => i.IngredientId == ingredientId);
                if (ingredient != null)
                {
                    c.Ingredients.Add(ingredient);
                }
            }
            c.Thumbnail = recipe.Image;
            c.Earnings  = (int)(1.5 * c.Ingredients.Count);
        }