コード例 #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="amount">Amount of the transaction, negative if it needs to be paid</param>
 /// <param name="userId">Id of the user</param>
 /// <param name="type">Type of the transaction</param>
 /// <param name="questionId">Id of the question</param>
 /// <returns>The id of the created question</returns>
 public static int Create(int amount, int userId, TransacType type, int? questionId)
 {
     var res = QuestionYourFriendsDataAccess.DataAccess.Transac.Create(Context.QyfEntities, amount, userId,
                                                                       type, questionId);
     User.UpdateMoney(userId);
     return res;
 }
コード例 #3
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);
         QuestionYourFriendsDataAccess.Transac transac = qyfEntities.Transacs.CreateObject();
         transac.amount = amount;
         transac.userId = userId;
         transac.SetTransacStatus(TransacStatus.Ok);
         transac.SetTransacType(type);
         transac.questionId = questionId;
         qyfEntities.Transacs.AddObject(transac);
         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.");
     }
 }
コード例 #4
0
 /// <summary>
 /// Set the transaction type
 /// </summary>
 /// <param name="type">Type to set</param>
 public static void SetTransacType(this Transac transac, TransacType type)
 {
     transac.type = (int) type;
 }