public JsonResult Purchase(int?drink_id) { if (drink_id == null || drink_id < 1) { return(Json(new { success = false, message = "Неправильный код напитка", cash = Settings.AppSettings.Cash }, JsonRequestBehavior.AllowGet)); } Core.Drink drink = Core.Drink.GetEntityById(drink_id.Value); if (drink.price > Settings.AppSettings.Cash) { return(Json(new { success = false, message = "Недостаточно средств", cash = Settings.AppSettings.Cash }, JsonRequestBehavior.AllowGet)); } // Спишем средства со счета Settings.AppSettings.Cash -= drink.price; // Запишем продажу в БД Core.Sold sold = new Sold(); sold.drink_id = drink_id.Value; sold.dt = DateTime.Now; sold.Save(); // Уменьшим количество товара в хранилище Core.Store store = Core.Store.GetEntityById(drink_id.Value); store.qty--; store.Save(); return(Json(new { success = true, message = "success", cash = Settings.AppSettings.Cash }, JsonRequestBehavior.AllowGet)); }