Beispiel #1
0
        public async Task <ActionResult> PostAsync(ClosingCash model)
        {
            var meta = await AppUsers.GetCurrentAsync(this.Tenant).ConfigureAwait(true);

            var dates = await Dates.GetFrequencyDatesAsync(this.Tenant, meta.OfficeId).ConfigureAwait(true);

            model.UserId          = meta.UserId;
            model.TransactionDate = dates.Today;
            model.AuditUserId     = meta.UserId;
            model.AuditTs         = DateTimeOffset.UtcNow;
            model.Deleted         = false;

            await ClosingCashTransactions.AddAsync(this.Tenant, model).ConfigureAwait(true);

            return(this.Ok());
        }
        public static async Task AddAsync(string tenant, ClosingCash model)
        {
            using (var db = DbProvider.Get(FrapidDbServer.GetConnectionString(tenant), tenant).GetDatabase())
            {
                try
                {
                    await db.BeginTransactionAsync().ConfigureAwait(false);

                    await db.InsertAsync("sales.closing_cash", "closing_cash_id", true, model).ConfigureAwait(false);

                    var sql = new Sql("UPDATE sales.opening_cash SET closed=@0", true);
                    sql.Where("user_id=@0 AND transaction_date=@1", model.UserId, model.TransactionDate);

                    await db.NonQueryAsync(sql).ConfigureAwait(false);

                    db.CommitTransaction();
                }
                catch
                {
                    db.RollbackTransaction();
                    throw;
                }
            }
        }