Beispiel #1
0
        public IActionResult Update([FromBody] int id)
        {
            //Get the transaction and update it
            var transaction = financeRepository.Transactions.FirstOrDefault(a => a.Id == id);

            transaction.IsProcessed   = 1;
            transaction.DateProcessed = DateTime.Now;
            financeRepository.UpdateTransaction(transaction);
            // Also update the whole fund
            var found = compRepository.Account;

            found.MemberShare = found.MemberShare + (transaction.Price / 2);
            found.CoOpShare   = found.CoOpShare + (transaction.Price / 2);
            found.Date        = DateTime.Now;
            compRepository.UpdateAccount(found);
            return(Ok());
        }
        public async Task <IActionResult> AcceptOrder(RequestsViewModel model)
        {
            var transactionId = model.TransactionId;
            var order         = _transactionRepository.Transactions.FirstOrDefault(t => t.Id == transactionId);
            var adminId       = await GetUserId();

            //order shipped by admin
            order.DateProcessed = DateTime.Now;
            order.IsProcessed   = 1;
            order.RecipientId   = adminId;
            _transactionRepository.UpdateTransaction(order);

            // get clients money and balance it to member & coopshare
            var companyAccount = _compAccount.Account;
            var price          = order.Price / 2m;

            companyAccount.CoOpShare   += price;
            companyAccount.MemberShare += price;
            companyAccount.Date         = DateTime.Now;
            _compAccount.UpdateAccount(companyAccount);

            //send notification to user
            var items = string.Join(',', order.TransactionItem
                                    .Select(ti => ti.Item.Name)
                                    .ToArray());
            var message = new Message()
            {
                SenderId   = adminId,
                ReceiverId = order.OwnerId,
                DateSent   = DateTime.Now,
                Title      = "Your Order is being shipped",
                Message1   = $"Your order for {items} is being shipped. We hope to see you again soon.<br> Have a great day,<br> Co-Partenership"
            };

            _messageInterface.SaveMessage(message);

            return(RedirectToAction(nameof(Requests)));
        }