Ejemplo n.º 1
0
        public async Task <ActionResult> EditTransaction(EditTransaction model)
        {
            var svcData = new AOrder_PostOrderTransaction()
            {
                OrderId = model.OrderId,
                OrderTransactionTypeCode = model.OrderTransactionTypeCode
            };
            var svcItems = new List <AOrder_PostOrderTransactionItem>();

            foreach (var item in model.TransactionEntries)
            {
                if (item.Selected)
                {
                    var svcItem = new AOrder_PostOrderTransactionItem()
                    {
                        OrderItemId             = item.OrderItemId,
                        OrderItemStatusTypeCode = model.OrderItemStatusTypeCode,
                        Quantity = item.Quantity
                    };
                    svcItems.Add(svcItem);
                }
            }
            svcData.Items = svcItems;

            _ = await OrderAdminService.PostOrderTransactionAsync(svcData);

            return(RedirectToAction("Index", new { id = model.OrderId }));
        }
Ejemplo n.º 2
0
        public ActionResult EditTransaction(string TransID)
        {
            TransactionHistoryTableAdapter adapter = new TransactionHistoryTableAdapter();
            EditTransaction model = new EditTransaction();

            TransactionTypeTableAdapter tranTypeAdapter = new TransactionTypeTableAdapter();
            DataTable tranTypeDT = tranTypeAdapter.GetData();

            List<SelectListItem> items = new List<SelectListItem>();
            foreach (DataRow row in tranTypeDT.Rows)
            {
                items.Add(new SelectListItem { Text = row["Name"].ToString(), Value = row["TransactionTypeID"].ToString() });
            }
            ViewData["TransType"] = items;

            try
            {
                int transactionID = int.Parse(TransID);
                DataTable result = adapter.GetDataByKey(transactionID);

                if (result.Rows.Count != 0)
                {
                    model.Username = result.Rows[0].Field<string>("Username");
                    model.TransactionTypeID = result.Rows[0].Field<int>("TransactionTypeID");
                    model.Value = result.Rows[0].Field<int>("Value");
                    model.TransactionContent = result.Rows[0].Field<string>("TransactionContent");
                    model.ScheduleMealSetDetailID = result.Rows[0].Field<int?>("ScheduleMealSetDetailID");
                    model.IsAuto = result.Rows[0].Field<Boolean>("IsAuto");
                    model.InsertedDate = result.Rows[0].Field<DateTime>("InsertedDate");
                    model.UpdatedBy = result.Rows[0].Field<string>("UpdatedBy");
                    model.LastUpdated = result.Rows[0].Field<DateTime>("LastUpdated");
                    model.TransactionHistoryID = result.Rows[0].Field<int>("TransactionHistoryID");
                }
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
            }

            return View(model);
        }
Ejemplo n.º 3
0
        public ActionResult EditTransaction(EditTransaction model)
        {
            TransactionTypeTableAdapter tranTypeAdapter = new TransactionTypeTableAdapter();
            DataTable tranTypeDT = tranTypeAdapter.GetData();

            List<SelectListItem> items = new List<SelectListItem>();
            foreach (DataRow row in tranTypeDT.Rows)
            {
                items.Add(new SelectListItem { Text = row["Name"].ToString(), Value = row["TransactionTypeID"].ToString() });
            }
            ViewData["TransType"] = items;

            if (!ModelState.IsValid)
            {
                return View(model);
            }
            int transactionHistoryID = model.TransactionHistoryID;
            string username = model.Username;
            int transactionTypeID = model.TransactionTypeID;
            int value = model.Value;
            string transactionContent = model.TransactionContent;
            int? scheduleMealSetDetailID = model.ScheduleMealSetDetailID;
            Boolean isAuto = model.IsAuto;
            DateTime insertedDate = model.InsertedDate;
            string updatedBy = model.UpdatedBy;
            DateTime lastUpdated = DateTime.Now;
            TransactionHistoryTableAdapter transAdapter = new TransactionHistoryTableAdapter();
            try
            {
                transAdapter.UpdateTransactionHistory(username, transactionTypeID, value, transactionContent
                    , scheduleMealSetDetailID, isAuto, insertedDate, AccountInfo.GetUserName(Request), lastUpdated
                    , transactionHistoryID);
                XmlSync.SaveTransactionHistoryXml(transactionHistoryID, username, transactionTypeID, value, transactionContent
                    , scheduleMealSetDetailID, isAuto, insertedDate, AccountInfo.GetUserName(Request), lastUpdated, null);
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
            }

            return RedirectToAction("ListTransaction", "Transaction");
        }
        public async Task EditTransactionAsync(EditTransaction command)
        {
            var results = editTransactionValidator.Validate(command);

            if (!results.IsValid)
            {
                throw new ArgumentException(results.ToString("~"));
            }

            var user = await userRepository.GetFirstUserAsync();

            var firstTransaction = await this.transactionRepository.GetTransactionAsync(command.Id);

            Transaction secondTransaction = null;

            await transactionRepository.UpdateAsync(firstTransaction);

            //merge tags
            var tags2Transactions = await this.tagRepository.GetTagToTransactionsAsync(command.Id);

            var tags2Add    = command.Tags.Except(tags2Transactions.Select(t => t.TagId));
            var tags2Remove = tags2Transactions.Select(t => t.TagId).Except(command.Tags);
            var tags2Transactions2Remove = tags2Transactions.Where(t => tags2Remove.Contains(t.TagId));

            //add new
            await this.CreateTagsToTransaction(tags2Add, firstTransaction.Id);

            //delete removed
            await this.tagRepository.RemoveAsync(tags2Transactions2Remove);

            //merge files
            await this.MergeFiles(command.FileGuid, firstTransaction);

            var transfer = await transactionRepository.GetTransferAsync(command.Id);

            if (transfer != null)
            {
                var secondTransactionId = transfer.ToTransactionId != command.Id ? transfer.ToTransactionId : transfer.FromTransactionId;
                secondTransaction = await this.transactionRepository.GetTransactionAsync(transfer.ToTransactionId);
            }

            //remove transfer, no more transfer
            if (command.ExtendedType != ExtendedTransactionType.Transfer &&
                transfer != null && secondTransaction != null)
            {
                await this.transactionRepository.RemoveTransferAsync(transfer);

                await this.transactionRepository.RemoveTransactionAsync(secondTransaction);

                firstTransaction.Edit(command.AccountId, command.ExtendedType.ToTransactionType(), command.Amount, command.Date, command.Name, command.Comment, user.Id, command.IsDeleted, command.CategoryId, command.Latitude, command.Longitude);
                await this.transactionRepository.UpdateAsync(firstTransaction);
            }
            //new Transfer, no transfer before
            else if (command.ExtendedType == ExtendedTransactionType.Transfer &&
                     transfer == null && secondTransaction == null)
            {
                firstTransaction.Edit(command.AccountId, TransactionType.Expense, command.Amount, command.Date, command.Name, command.Comment, user.Id, command.IsDeleted, command.CategoryId, command.Latitude, command.Longitude);
                await this.transactionRepository.UpdateAsync(firstTransaction);

                var transactionIncome = Transaction.Create(command.TransferAccountId.Value, TransactionType.Income, command.TransferAmount.Value, command.TransferDate.Value, command.Name, command.Comment, user.Id, command.IsDeleted, command.CategoryId, null, command.Latitude, command.Longitude);
                await transactionRepository.AddTransactionAsync(transactionIncome);

                var newTransfer = Transfer.Create(firstTransaction.Id, transactionIncome.Id, command.Rate.Value);
                await transactionRepository.AddTransferAsync(newTransfer);
            }

            //edit transfer
            else if (command.ExtendedType == ExtendedTransactionType.Transfer &&
                     transfer != null && secondTransaction != null)
            {
                firstTransaction.Edit(command.AccountId, TransactionType.Expense, command.Amount, command.Date, command.Name, command.Comment, user.Id, command.IsDeleted, command.CategoryId, command.Latitude, command.Longitude);
                await this.transactionRepository.UpdateAsync(firstTransaction);

                secondTransaction.Edit(command.TransferAccountId.Value, TransactionType.Income, command.TransferAmount.Value, command.TransferDate.Value, command.Name, command.Comment, user.Id, command.IsDeleted, command.CategoryId, command.Latitude, command.Longitude);
                await this.transactionRepository.UpdateAsync(firstTransaction);

                transfer.SetRate(command.Rate.Value);
                await transactionRepository.UpdateTransferAsync(transfer);
            }
            //just edit 1 transaction, no transfer before
            else if (command.ExtendedType != ExtendedTransactionType.Transfer &&
                     transfer == null && secondTransaction == null)
            {
                decimal amount = 0;

                if (command.ExtendedType == ExtendedTransactionType.Expense && command.Amount > 0)
                {
                    amount = command.Amount * (-1);
                }
                else if (command.ExtendedType == ExtendedTransactionType.Income && command.Amount < 0)
                {
                    amount = command.Amount * (-1);
                }
                else
                {
                    amount = command.Amount;
                }

                firstTransaction.Edit(command.AccountId, command.ExtendedType.ToTransactionType(), amount, command.Date, command.Name, command.Comment, user.Id, command.IsDeleted, command.CategoryId, command.Latitude, command.Longitude);
                await this.transactionRepository.UpdateAsync(firstTransaction);
            }
        }
        public async Task <IActionResult> Put(Guid id, [FromBody] EditTransaction command)
        {
            await this.DispatchAsync(command);

            return(NoContent());
        }