Beispiel #1
0
 public void SetValue <T>(ref Requisite <T> requisite, string name, object value)
 {
     requisite.value    = (T)value;
     requisite.revision = revision;
     if (TrackChanges)
     {
         MarkAsChanged(name, value);
     }
 }
Beispiel #2
0
        public async Task <Operation> Payment(Operation newOperation)
        {
            newOperation.Date           = DateTime.Now;
            newOperation.Operation_type = "Платёж";
            Requisite newRequisite = newOperation.Requisite;

            using (var connection = new NpgsqlConnection(ConnectionString))
            {
                connection.Open();
                using (var transaction = connection.BeginTransaction())
                {
                    try
                    {
                        int requisiteId = await EqualRequisites(newRequisite);

                        if (requisiteId < 1)
                        {
                            requisiteId = await connection.QueryFirstOrDefaultAsync <int>("INSERT INTO requisites (payment_name, target_name, target_email) values (@payment_name, @target_name, @target_email) Returning (id)",
                                                                                          new
                            {
                                newRequisite.Payment_name,
                                newRequisite.Target_name,
                                newRequisite.Target_email
                            }, transaction);
                        }

                        await connection.ExecuteAsync("INSERT INTO OPERATIONS (amount, date, account_in_id ,account_out_id, operation_type,  requisite_id ) values (@amount, @date, @account_in_id, @account_out_id, @operation_type, @requisiteId)",
                                                      new {
                            newOperation.Amount,
                            newOperation.Date,
                            newOperation.Account_in_id,
                            newOperation.Account_out_id,
                            newOperation.Operation_type,
                            newOperation.Purpose,
                            requisiteId
                        }, transaction);

                        await this.ChangeBalance(newOperation.Account_in_id, newOperation.Amount, transaction);

                        await this.ChangeBalance(newOperation.Account_out_id, -newOperation.Amount, transaction);

                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                        throw new Exception("Ошибка при выполнении платежа");
                    }
                    return(newOperation);
                }
            }
        }
Beispiel #3
0
        public async Task <IActionResult> CreateTemplate([FromBody] Requisite newRequisite)
        {
            try
            {
                int userId     = int.Parse(User.FindFirst("userId").Value);
                var templateId = await _accountRequestHandler.CreateTemplate(newRequisite, userId);

                return(Ok(templateId));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Beispiel #4
0
        public async Task <int> CreateRequisite(Requisite newRequisite, int userId)
        {
            using (var connection = new NpgsqlConnection(ConnectionString))
            {
                int requisiteId = await connection.QueryFirstOrDefaultAsync <int>("INSERT INTO requisites (payment_name, target_name, target_email, user_id) values (@payment_name, @target_name, @target_email, @userId) Returning (id)",
                                                                                  new {
                    newRequisite.Payment_name,
                    newRequisite.Target_name,
                    newRequisite.Target_email,
                    userId
                });

                return(requisiteId);
            }
        }
Beispiel #5
0
 public T GetValue <T>(ref Requisite <T> requisite, string name)
 {
     if (revision > requisite.revision)
     {
         if (requisite.revision == 0)
         {
             object resultObject;
             if (ValueSource == null || !ValueSource.TryLoadValue(name, typeof(T), out resultObject))
             {
                 resultObject = default(T);
             }
             if (resultObject == null && typeof(IList).IsAssignableFrom(typeof(T)))
             {
                 var listItemType = typeof(T).GetGenericArguments()[0];
                 resultObject = (T)ListFactory.Create(listItemType, null, 1);
             }
             requisite.value = (T)resultObject;
         }
         requisite.revision = revision;
         var needTrack = typeof(Abstract1CEntity).IsAssignableFrom(typeof(T)) ||
                         (typeof(T).IsGenericType &&
                          typeof(T).GetGenericTypeDefinition() == typeof(List <>) &&
                          typeof(Abstract1CEntity).IsAssignableFrom(typeof(T).GetGenericArguments()[0]));
         if (needTrack)
         {
             if (observedValues == null)
             {
                 observedValues = new Dictionary <string, ObservedValue>();
             }
             var list = requisite.value as IList;
             observedValues[name] = new ObservedValue
             {
                 value        = requisite.value,
                 originalList = list == null
                     ? null
                     : ListFactory.Create(typeof(T).GetGenericArguments()[0], list, 0)
             };
         }
     }
     return(requisite.value);
 }
Beispiel #6
0
        public async Task <int> EqualRequisites(Requisite requisite)
        {
            using (var connection = new NpgsqlConnection(ConnectionString))
            {
                try
                {
                    int id = await connection.QueryFirstOrDefaultAsync <int>("SELECT Id FROM Requisites WHERE payment_name=@payment_name AND target_email=@target_email AND target_name=@target_name",
                                                                             new {
                        requisite.Payment_name,
                        requisite.Target_email,
                        requisite.Target_name
                    });

                    return(id);
                }
                catch
                {
                    return(-1);
                }
            }
        }
        public async Task <Requisite> GetTemplate(int id, int userId)
        {
            Requisite requisite = await _accountService.GetRequisite(id);

            return(requisite);
        }
        public async Task <int> CreateTemplate(Requisite newRequisite, int userId)
        {
            int requisiteId = await _accountService.CreateRequisite(newRequisite, userId);

            return(requisiteId);
        }