コード例 #1
0
ファイル: MenuController.cs プロジェクト: roszman/barcaliente
        public JsonResult Add(Meal meal)
        {
            if (ModelState.IsValid)
            {
                if (_mealRepository.Save(meal))
                {
                    Response.StatusCode = (int)HttpStatusCode.OK;
                    return new JsonResult { Data = new {message = "Udało się dodać nowe danie :)", meal = meal} };
                }
                Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                return new JsonResult();
            }

            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return new JsonResult();
        }
コード例 #2
0
 public bool Save(Meal meal)
 {
     if (meal.MealID == 0)
     {
         context.Meals.Add(meal);
     }
     else
     {
         Meal mealtoUpdate = context.Meals.Find(meal.MealID);
         if (mealtoUpdate != null)
         {
             mealtoUpdate.Name = meal.Name;
             mealtoUpdate.Description = meal.Description;
             mealtoUpdate.Category = meal.Category;
             mealtoUpdate.Price = meal.Price;
             mealtoUpdate.Order = 100;
             mealtoUpdate.IsDeleted = false;
         }
     }
     return context.SaveChanges() > 0;
 }