Exemplo n.º 1
0
        public async Task <IActionResult> Create(AddMealViewModel addMealViewModel)
        {
            if (ModelState.IsValid)
            {
                WeatherType   newWeatherType      = _context.WeatherTypes.Single(w => w.ID == addMealViewModel.WeatherTypeID);
                CookingMethod newCookingMethod    = _context.CookingMethods.Single(m => m.ID == addMealViewModel.CookingMethodID);
                CookingMethod newAltCookingMethod = _context.CookingMethods.Single(a => a.ID == addMealViewModel.AltCookingMethodID);
                CookingTime   newCookingTime      = _context.CookingTimes.Single(t => t.ID == addMealViewModel.CookingTimeID);
                PrepTime      newPrepTime         = _context.PrepTimes.Single(p => p.ID == addMealViewModel.PrepTimeID);

                //Add the new default meal to the default meal table
                Meal newMeal = new Meal
                {
                    Name             = addMealViewModel.Name,
                    Description      = addMealViewModel.Description,
                    Location         = addMealViewModel.Location,
                    UserID           = addMealViewModel.UserID,
                    WeatherType      = newWeatherType,
                    CookingMethod    = newCookingMethod,
                    AltCookingMethod = newAltCookingMethod,
                    CookingTime      = newCookingTime,
                    PrepTime         = newPrepTime
                };

                _context.Meals.Add(newMeal);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(addMealViewModel));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (PrepTime != null)
         {
             hashCode = hashCode * 59 + PrepTime.GetHashCode();
         }
         if (TotalTime != null)
         {
             hashCode = hashCode * 59 + TotalTime.GetHashCode();
         }
         if (Servings != null)
         {
             hashCode = hashCode * 59 + Servings.GetHashCode();
         }
         if (ServingSize != null)
         {
             hashCode = hashCode * 59 + ServingSize.GetHashCode();
         }
         return(hashCode);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Returns true if RecipeObjectAttributes instances are equal
        /// </summary>
        /// <param name="other">Instance of RecipeObjectAttributes to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(RecipeObjectAttributes other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     PrepTime == other.PrepTime ||
                     PrepTime != null &&
                     PrepTime.Equals(other.PrepTime)
                     ) &&
                 (
                     TotalTime == other.TotalTime ||
                     TotalTime != null &&
                     TotalTime.Equals(other.TotalTime)
                 ) &&
                 (
                     Servings == other.Servings ||
                     Servings != null &&
                     Servings.Equals(other.Servings)
                 ) &&
                 (
                     ServingSize == other.ServingSize ||
                     ServingSize != null &&
                     ServingSize.Equals(other.ServingSize)
                 ));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,Description")] PrepTime prepTime)
        {
            if (id != prepTime.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(prepTime);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PrepTimeExists(prepTime.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(prepTime));
        }
        public async Task <IActionResult> Create([Bind("ID,Description")] PrepTime prepTime)
        {
            if (ModelState.IsValid)
            {
                _context.Add(prepTime);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(prepTime));
        }
Exemplo n.º 6
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder($"{Id}");

            sb.Append($"{DinnerName}");
            sb.Append($"{StartTime.ToString()}");
            sb.Append($"{PrepTime.ToString()}");
            sb.Append($"{NumOfRounds}");
            sb.Append($"{Parallel}");
            sb.Append($"{Participants.Count}");
            sb.Append($"{Rounds.Count}");
            return(sb.ToString());
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Edit(int id, EditMealViewModel editMealViewModel)
        {
            if (id != editMealViewModel.mealID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    WeatherType   newWeatherType      = _context.WeatherTypes.Single(w => w.ID == editMealViewModel.WeatherTypeID);
                    CookingMethod newCookingMethod    = _context.CookingMethods.Single(m => m.ID == editMealViewModel.CookingMethodID);
                    CookingMethod newAltCookingMethod = _context.CookingMethods.Single(a => a.ID == editMealViewModel.AltCookingMethodID);
                    CookingTime   newCookingTime      = _context.CookingTimes.Single(t => t.ID == editMealViewModel.CookingTimeID);
                    PrepTime      newPrepTime         = _context.PrepTimes.Single(p => p.ID == editMealViewModel.PrepTimeID);

                    //Add the new default meal to the default meal table
                    Meal editMeal = new Meal
                    {
                        ID               = editMealViewModel.mealID,
                        Name             = editMealViewModel.Name,
                        Description      = editMealViewModel.Description,
                        Location         = editMealViewModel.Location,
                        UserID           = editMealViewModel.UserID,
                        WeatherType      = newWeatherType,
                        CookingMethod    = newCookingMethod,
                        AltCookingMethod = newAltCookingMethod,
                        CookingTime      = newCookingTime,
                        PrepTime         = newPrepTime
                    };

                    _context.Update(editMeal);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MealExists((editMealViewModel.mealID)))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }

            return(View(editMealViewModel));
        }