public ActionResult doTransaction()
 {
     object result;
     Dictionary<string, object> dic = getTransactionValidation();
     object tmp;
     dic.TryGetValue("pilotAccount_id", out tmp);
     PilotAccount pilot = PilotAccountEntity.selectById(long.Parse(tmp.ToString()));
     dic.TryGetValue("prix", out tmp);
     float price = float.Parse(tmp.ToString());
     double? total = 0;
     if (pilot == null)
     {
         result = ResponseHelper.notFound("Pilot");
     }
     else
     {
         if (Session["services"] == null)
         {
             result = ResponseHelper.forbidden();
         }
         else
         {
             ArrayList services = (ArrayList)Session["services"];
             double ton = (double)Session["ton"];
             foreach (KeyValuePair<Service, long> pair in services)
             {
                 Service s = (Service)pair.Key;
                 double? servicePrice = null;
                 if (s.service_type == "forfait")
                 {
                     total += s.service_price * (int)pair.Value;
                 }
                 else if (s.WeightRangeService.Count > 0)
                 {
                     WeightRangeService selected = null;
                     foreach (WeightRangeService wrs in s.WeightRangeService)
                     {
                         if (wrs.weightRangeService_tonMin <= ton && wrs.weightRangeService_tonMax > ton)
                         {
                             selected = wrs;
                             break;
                         }
                         else if (selected == null ||
                           (wrs.weightRangeService_tonMax < ton
                             && selected.weightRangeService_tonMax < wrs.weightRangeService_tonMax))
                         {
                             selected = wrs;
                         }
                     }
                     servicePrice = selected.weightRangeService_priceFixed
                         + (ton - selected.weightRangeService_tonMin)
                         * selected.weightRangeService_pricePerTon;
                     total += servicePrice * (int)pair.Value;
                 }
             }
             if (total != price)
             {
                 result = ResponseHelper.wrongInput();
             }
             else
             {
                 Transaction t = new Transaction()
                 {
                     transaction_date = DateTime.Now,
                     transaction_price = total,
                     aircraft_id = long.Parse(Session["aircraft_id"].ToString()),
                     pilotAccount_id = pilot.pilotAccount_id
                 };
                 PilotAccountEntity.debitPilot(pilot, (float)total);
                 TransactionEntity.createTransaction(t);
                 result = ResponseHelper.success();
             }
         }
     }
     return Json(result);
 }
 /// <summary>
 /// Créez un nouvel objet Transaction.
 /// </summary>
 /// <param name="transaction_id">Valeur initiale de la propriété transaction_id.</param>
 /// <param name="aircraft_id">Valeur initiale de la propriété aircraft_id.</param>
 public static Transaction CreateTransaction(global::System.Int64 transaction_id, global::System.Int64 aircraft_id)
 {
     Transaction transaction = new Transaction();
     transaction.transaction_id = transaction_id;
     transaction.aircraft_id = aircraft_id;
     return transaction;
 }
 /// <summary>
 /// Méthode déconseillée pour ajouter un nouvel objet à l'EntitySet Transaction. Utilisez la méthode .Add de la propriété ObjectSet&lt;T&gt; associée à la place.
 /// </summary>
 public void AddToTransaction(Transaction transaction)
 {
     base.AddObject("Transaction", transaction);
 }
Example #4
0
        //--------------------------------------------------
        //Transaction JSON Object
        public static Object transactionToObject(Transaction transaction)
        {
            return new
            {
                transaction_id = transaction.transaction_id,
                //service_id = transaction.service_id,
                aircraft_id = transaction.aircraft_id,
                transaction_date = transaction.transaction_date,
                //service_quantite = transaction.service_quantite,
                transaction_price = transaction.transaction_price,
                transaction_type = transaction.transaction_type,
                transaction_creator = transaction.transaction_creator

            };
        }