Beispiel #1
0
        public async Task <IHttpActionResult> PutFood(int id, Containers.Models.EasyInputs.EasyFood food)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            DB.Food foodDb = food.ToDBFood();
            foodDb.Id = id;

            db.Entry(foodDb).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FoodExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #2
0
 public ActionResult FoodAdd(Models.FoodAddModels models)
 {
     try
     {
         if (models.Food.ID != 0)
         {
             DB.Food food = db.Food.FirstOrDefault(x => x.ID == models.Food.ID);
             food.tr_Text      = models.Food.tr_Text;
             food.en_Text      = models.Food.en_Text;
             food.tr_Desc      = models.Food.tr_Desc;
             food.en_Desc      = models.Food.en_Desc;
             food.CategoryID   = models.Food.CategoryID;
             food.Price        = models.Food.Price;
             food.ModifiedDate = DateTime.Now;
         }
         else
         {
             models.Food.AddedDate = DateTime.Now;
             db.Food.Add(models.Food);
         }
         db.SaveChanges();
         TempData["AddSucFood"] = "Başarılı Bir Şekilde Kaydedildi";
         return(RedirectToAction("FoodAdd", "Panel"));
     }
     catch (Exception ex)
     {
         TempData["AddErrFood"] = ex.Message;
         return(View(models));
     }
 }
        public static async Task <FoodImg> Add(EasyFood food)
        {
            try
            {
                DB.Food foodDb = await FindFoodByNoId(food.ToDBFood());

                FoodImg imgFoodOutput = new FoodImg();

                if (foodDb is null || foodDb.Id < 0)
                {
                    Food inputDbFood = food.ToDBFood();
                    db.Food.Add(inputDbFood);
                    await db.SaveChangesAsync();

                    foodDb = await FindFoodByNoId(food.ToDBFood());

                    imgFoodOutput = FoodImg.ToFood(foodDb);
                    await imgFoodOutput.getImages();
                }
                else
                {
                    imgFoodOutput = FoodImg.ToFood(foodDb);
                    await imgFoodOutput.getImages();
                }

                return(imgFoodOutput);
            }
        public DB.Food ToDBFood()
        {
            DB.Food food = new DB.Food();

            food.Name          = Name;
            food.Type          = Type;
            food.Price         = Price;
            food.Id_Restaurant = Id_Restaurant;
            food.Id            = 0;

            return(food);
        }
        public static FoodImg ToFood(DB.Food dbFood)
        {
            FoodImg meFood = new FoodImg();

            meFood.Id            = dbFood.Id;
            meFood.Name          = dbFood.Name;
            meFood.Price         = dbFood.Price;
            meFood.Type          = dbFood.Type;
            meFood.Id_Restaurant = dbFood.Id_Restaurant;

            meFood.Ingredient_To_Food = dbFood.Ingredient_To_Food;
            meFood.Order_To_Food      = dbFood.Order_To_Food;
            meFood.Restaurant         = dbFood.Restaurant;

            return(meFood);
        }
        public DB.Food Reverse()
        {
            DB.Food outputFood = new DB.Food();

            outputFood.Id            = this.Id;
            outputFood.Name          = this.Name;
            outputFood.Price         = this.Price;
            outputFood.Type          = this.Type;
            outputFood.Id_Restaurant = this.Id_Restaurant;

            outputFood.Ingredient_To_Food = this.Ingredient_To_Food;
            outputFood.Order_To_Food      = this.Order_To_Food;
            outputFood.Restaurant         = this.Restaurant;

            return(outputFood);
        }