Exemple #1
0
 public void Handle(BillCommand message)
 {
     Console.Out.WriteLine(ConsoleColor.Cyan, "Billing for order {0}...", message.Id);
     Thread.Sleep(2000);
     Console.Out.WriteLine(ConsoleColor.Cyan, "Finished billing for order {0}", message.Id);
     bus.SendLocal(new ShipCommand {
         Id = message.Id
     });
 }
Exemple #2
0
        public ActionResult AddAllToCommands()
        {
            var        user       = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(User.Identity.GetUserId());
            CartItem   itemSupr   = new CartItem();
            List <int> commandIds = new List <int>();
            long       cost       = 0;
            var        cartItems  = db.CartItems.ToList();

            for (int i = 0; i < cartItems.Count(); i++)
            {
                var     cartItem = cartItems[i];
                Machine machine  = db.Machines.Find(cartItem.MachineId);
                // validate userId and disponibility
                if (cartItem.UserId == user.Id && validate(machine, cartItem.From, cartItem.To))
                {
                    Command item = new Command();

                    long Duration = DateTimeHelper.DateTimeHelper.LongDiff(cartItem.From, cartItem.To).Days + 1; // Same date -> diff = 0
                    cost += machine.RentPrice * Duration;

                    itemSupr = db.CartItems.Find(cartItem.Id);

                    item.From      = cartItem.From;
                    item.To        = cartItem.To;
                    item.MachineId = cartItem.MachineId;
                    item.UserId    = user.Id;
                    item.Status    = null;

                    db.Commands.Add(item);
                    db.CartItems.Remove(itemSupr);
                    db.SaveChanges();

                    commandIds.Add(item.Id);
                }
            }

            // Create bill
            Bill bill = new Bill();

            bill.UserId = user.Id;
            bill.Value  = (int)cost;
            db.Bills.Add(bill);
            db.SaveChanges();

            foreach (int commandId in commandIds)
            {
                // Add commands to bill
                BillCommand billCommand = new BillCommand();
                billCommand.BillId    = bill.Id;
                billCommand.CommandId = commandId;
                db.BillCommands.Add(billCommand);
                db.SaveChanges();
            }

            return(View("AddToCommands"));
        }
Exemple #3
0
        public ActionResult AddToCommands(int cartId)
        {
            var         user        = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(User.Identity.GetUserId());
            CartItem    cartItem    = db.CartItems.Find(cartId);
            Machine     machine     = db.Machines.Find(cartItem.MachineId);
            Command     command     = new Command();
            Bill        bill        = new Bill();
            BillCommand billCommand = new BillCommand();

            // validation of the disponibility
            if (validate(machine, cartItem.From, cartItem.To))
            {
                long cost     = 0;
                long Duration = DateTimeHelper.DateTimeHelper.LongDiff(cartItem.From, cartItem.To).Days + 1; // Same date -> diff = 0
                cost += machine.RentPrice * Duration;

                command.From      = cartItem.From;
                command.To        = cartItem.To;
                command.MachineId = cartItem.MachineId;
                command.UserId    = user.Id;
                command.Status    = null;

                // Create command and remove from cart
                db.Commands.Add(command);
                db.CartItems.Remove(cartItem);

                // Create bill
                bill.UserId = user.Id;
                bill.Value  = (int)cost;
                db.Bills.Add(bill);

                // Add commands to bill
                billCommand.BillId    = bill.Id;
                billCommand.CommandId = command.Id;
                db.BillCommands.Add(billCommand);

                // Save
                db.SaveChanges();
                return(View("AddToCommands"));
            }
            else // return to index if not valid
            {
                return(RedirectToAction("Index"));
            }
        }
 private void ReigsterCommands()
 {
     BillCommand.BuildCommand(storageManager);
     RegisterCommand.BuildCommand(storageManager);
     GithubBot.AddStorageManager(storageManager);
 }