コード例 #1
0
 /// <summary>
 /// Adds a transaction
 /// </summary>
 /// <param name="qyfEntities">Entity context</param>
 /// <param name="amount">Amount of the transaction</param>
 /// <param name="userId">Id of the owner</param>
 /// <param name="type">Type of the transaction</param>
 /// <param name="questionId">Id of the question</param>
 /// <returns>The id of the created transaction</returns>
 public static int Create(QuestionYourFriendsEntities qyfEntities, int amount, int userId, TransacType type,
     int? questionId)
 {
     try
     {
         _logger.InfoFormat("New transaction creation: amount({0}), userId({1}), type({2})", amount, userId, type);
         var transac = new QuestionYourFriendsDataAccess.Transac
                           {
                               UserReference =
                                   {EntityKey = new EntityKey("QuestionYourFriendsEntities.Users", "id", userId)}
                           };
         transac.SetTransacStatus(TransacStatus.Ok);
         transac.SetTransacType(type);
         if (questionId.HasValue)
             transac.QuestionReference.EntityKey = new EntityKey("QuestionYourFriendsEntities.Questions", "id", questionId);
         qyfEntities.AddToTransacs(transac);
         transac.amount = amount;
         qyfEntities.SaveChanges();
         _logger.InfoFormat("New transaction id: {0}", transac.id);
         return transac.id;
     }
     catch (Exception ex)
     {
         _logger.Error("Cannot create a new transaction", ex);
         throw new ApplicationException("A database error occured during the operation.");
     }
 }
コード例 #2
0
 /// <summary>
 /// Adds a transaction
 /// </summary>
 /// <param name="qyfEntities">Entity context</param>
 /// <param name="t">Transaction to add</param>
 /// <returns>Id of the created transaction</returns>
 public static int Create(QuestionYourFriendsEntities qyfEntities, QuestionYourFriendsDataAccess.Transac t)
 {
     try
     {
         _logger.InfoFormat("New transaction creation: amount({0}), userId({1}), type({2})", t.amount, t.User.id, t.type);
         qyfEntities.AddToTransacs(t);
         qyfEntities.SaveChanges();
         _logger.InfoFormat("New transaction id: {0}", t.id);
         return t.id;
     }
     catch (Exception ex)
     {
         _logger.Error("Cannot create a new transaction", ex);
         throw new ApplicationException("A database error occured during the operation.");
     }
 }