Ejemplo n.º 1
0
        public override async Task <TransactionDto> Create(CreateTransactionDto input)
        {
            try
            {
                TimePlayZeroDbContextFactory fac     = new TimePlayZeroDbContextFactory();
                TimePlayZeroDbContext        context = fac.CreateDbContext(null);

                Transaction transaction = new Transaction();
                transaction.CreationTime = DateTime.Now;
                transaction.Duration     = input.Duration;
                transaction.CustomerName = input.CustomerName;
                transaction.PhoneNumber  = input.PhoneNumber;
                transaction.Price        = input.Price;

                transaction.State         = input.State;
                transaction.ItemPriceCode = input.ItemPriceCode;
                transaction.ItemPriceId   = input.ItemPriceId;
                transaction.CustomerId    = input.CustomerId;
                transaction.Description   = input.Description;
                transaction.IsUnlimited   = input.IsUnlimited;
                context.Transactions.Add(transaction);
                int x = await context.SaveChangesAsync();

                TransactionDate transactionDate = new TransactionDate();
                transactionDate.Date          = DateTime.Now;
                transactionDate.Type          = (int)EnumTransactionDateType.Start;
                transactionDate.TransactionId = transaction.Id;

                context.TransactionDates.Add(transactionDate);

                int y = await context.SaveChangesAsync();

                var res = MapToEntityDto(transaction);

                res.TotalPrice = transaction.Price;
                res.StartDate  = transactionDate.Date;

                if (input.IsUnlimited)
                {
                    res.DurationStr = L("IsUnlimited");
                }
                else
                {
                    res.DurationStr = res.Duration.ToString();
                }
                return(res);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public void StartStopTransaction(int transactionId)
        {
            TimePlayZeroDbContextFactory fac     = new TimePlayZeroDbContextFactory();
            TimePlayZeroDbContext        context = fac.CreateDbContext(null);

            var trans = context.Transactions.Where(w => w.Id == transactionId).FirstOrDefault();

            if (trans == null)
            {
                return;
            }

            trans.State = trans.State == 0 ? 2 : 0;

            EnumTransactionDateType type = (EnumTransactionDateType)context.TransactionDates
                                           .Where(w => w.TransactionId == transactionId).OrderByDescending(o => o.Date)
                                           .Select(s => s.Type).FirstOrDefault();

            TransactionDate transactionDate = new TransactionDate();

            transactionDate.Date          = DateTime.Now;
            transactionDate.TransactionId = transactionId;
            transactionDate.Type          = type == EnumTransactionDateType.Start ? (int)EnumTransactionDateType.Stop : (int)EnumTransactionDateType.Start;

            context.TransactionDates.Add(transactionDate);
            context.SaveChangesAsync();
        }