示例#1
0
        public void TestServiceVerifyOrder()
        {
            bool res = true;

            try
            {
                Client         client = new Client(publickey, privatekey, mode);
                PlaceOrderInfo order  = new PlaceOrderInfo(
                    "12",
                    "M4 C# SDK",
                    180,
                    "Eduardo Aguilar",
                    "*****@*****.**"
                    );
                NewOrderInfo neworder = client.api.placeOrder(order);
                CpOrderInfo  response = client.api.verifyOrder(neworder.getId());
                res = !response.getId().Equals(null);
            }
            catch (Exception e)
            {
                res = false;
            }

            Assert.IsTrue(res);
        }
示例#2
0
        public void TestServiceSms()
        {
            bool res = true;

            try
            {
                Client         client = new Client(publickey, privatekey, mode);
                PlaceOrderInfo order  = new PlaceOrderInfo(
                    "12",
                    "M4 C# SDK",
                    180,
                    "Eduardo Aguilar",
                    "*****@*****.**"
                    );
                NewOrderInfo neworder = client.api.placeOrder(order);
                SmsInfo      response = client.api.sendSmsInstructions(phone_number, neworder.getId());
                res = !response.getType().Equals("");
            }
            catch (Exception e)
            {
                res = false;
            }

            Assert.IsTrue(res);
        }
示例#3
0
        public static bool CreateOrder(NewOrderInfo info, Func<OrderInfo, bool> toConfirm)
        {
            OrderInfo myOrder = new OrderInfo();
            myOrder.CustomerName = info.CustomerName;
            myOrder.Area = info.Area;
            myOrder.Product = info.Product;
            myOrder.State = info.State;

            // Stores results of order calculations based on user input. 
            myOrder.MaterialCost = Calculations.GetMaterialCost(myOrder.Area.Value, myOrder.Product.CostPerSqFoot);
            myOrder.LaborCost = Calculations.GetLaborCost(myOrder.Area.Value, myOrder.Product.LaborCostPerSqFoot);
            myOrder.SubTotal = Calculations.GetSubTotal(myOrder.MaterialCost, myOrder.LaborCost);
            myOrder.TaxAmount = Calculations.GetTaxAmt(myOrder.State.TaxRate, myOrder.SubTotal);
            myOrder.TotalCost = Calculations.GetTotalCost(myOrder.SubTotal, myOrder.TaxAmount);

            List<OrderInfo> orders = FlooringManager.Orders.LoadAll(DateTime.Today);

            // If the orders list is empty, makeOrderNum will be 1.  Otherwise, it's the highest existing one plus one.
            var makeOrderNum = orders.Any() ? orders.Max(o => o.OrderNum) + 1 : 1;
            
            myOrder.OrderNum = makeOrderNum;

            bool wasConfirmed = toConfirm(myOrder);

            if (wasConfirmed)
            {
                orders.Add(myOrder);
                FlooringManager.Orders.SaveAll(DateTime.Today, orders);
            }

            return wasConfirmed;
        }
示例#4
0
        public void TestServicePlaceOrderFarmaciaABC()
        {
            bool res = true;

            try
            {
                Client         client = new Client(publickey, privatekey, mode);
                PlaceOrderInfo order  = new PlaceOrderInfo(
                    "12",
                    "M4 C# SDK",
                    180,
                    "Eduardo Aguilar",
                    "*****@*****.**",
                    "FARMACIA_ABC"
                    );
                NewOrderInfo neworder = client.api.placeOrder(order);
                res = !neworder.getId().Equals(null);
            }
            catch (Exception e)
            {
                res = false;
            }

            Assert.IsTrue(res);
        }
示例#5
0
        public static bool UpdateOrder(DateTime fileDate, OrderInfo existingOrder, NewOrderInfo edits, Func<OrderInfo, bool> toConfirm)
        {
            //Re-runs methods to update price information based on any changes made to the user order.
            OrderInfo newOrder = new OrderInfo();

            newOrder.OrderNum = edits.OrderNum;
            newOrder.CustomerName = edits.CustomerName;
            newOrder.Area = edits.Area;
            newOrder.Product = edits.Product;
            newOrder.State = edits.State;

            newOrder.MaterialCost = Calculations.GetMaterialCost(newOrder.Area.Value, newOrder.Product.CostPerSqFoot);
            newOrder.LaborCost = Calculations.GetLaborCost(newOrder.Area.Value, newOrder.Product.LaborCostPerSqFoot);
            newOrder.SubTotal = Calculations.GetSubTotal(newOrder.MaterialCost, newOrder.LaborCost);
            newOrder.TaxAmount = Calculations.GetTaxAmt(newOrder.State.TaxRate, newOrder.SubTotal);
            newOrder.TotalCost = Calculations.GetTotalCost(newOrder.SubTotal, newOrder.TaxAmount);

            bool wasConfirmed = toConfirm(newOrder);
            List<OrderInfo> currentOrders = FlooringManager.Orders.LoadAll(fileDate);

            if (wasConfirmed)
            {
                currentOrders.Remove(existingOrder);
                currentOrders.Add(newOrder);
                FlooringManager.Orders.SaveAll(fileDate, currentOrders);
            }

            return wasConfirmed;

        }
示例#6
0
 /// <summary>
 /// Save order on web api.
 /// </summary>
 /// <param name="newOrder">New Order to be saved.</param>
 /// <returns>Tuple of bool and string, bool == true when API succeded, bool == false when API did not succeed, string == fail message.</returns>
 public Tuple <bool, string> PostOrderAsync(NewOrderInfo newOrder)
 {
     using (var client = new HttpClient())
     {
         try
         {
             client.BaseAddress = _baseAddress;
             var response = client.PostAsXmlAsync("api/order/create", newOrder, new CancellationToken()).Result;
             if (response.IsSuccessStatusCode)
             {
                 var answer = new Tuple <bool, string>(true, response.StatusCode.ToString());
                 return(answer);
             }
             else //do failure thing
             {
                 var answer = new Tuple <bool, string>(false, "Could not save the created order: Error from Web api: " + response.StatusCode.ToString() + ": " + response.ReasonPhrase);
                 return(answer);
             }
         }
         catch (Exception ex)
         {
             throw;
         }
     }
 }
示例#7
0
        public NewZOVOrderSelectMenu(Form tMainForm, ref OrdersManager tOrdersManager,
                                     ref OrdersCalculate tOrdersCalculate, ref NewOrderInfo tNewOrderInfo)
        {
            MainForm     = tMainForm;
            NewOrderInfo = tNewOrderInfo;

            OrdersManager   = tOrdersManager;
            OrdersCalculate = tOrdersCalculate;
            InitializeComponent();
            Initialize();
        }
示例#8
0
        /// <summary>
        /// Call to save order
        /// </summary>
        /// <returns>Tuple of bool and string. bool == true if success, bool == false if it fails. String == message to show in UI if fail.</returns>
        internal Tuple <bool, string> SaveOrder()
        {
            NewOrderInfo createdOrder = new NewOrderInfo()
            {
                ItemsAndQuantity = OrderBeingCreated.ItemsAndQuantity,
                OrderType        = OrderBeingCreated.OrderType,
                Customer         = OrderBeingCreated.Customer,
                OrderDate        = OrderBeingCreated.OrderDate,
                Notes            = OrderBeingCreated.Notes,
                Table            = OrderBeingCreated.Table,
                Restaurant       = RestaurantLoginContainer.Instance.RestaurantId
            };

            return(_APICaller.PostOrderAsync(createdOrder));
        }
示例#9
0
 public IActionResult AddOrder(int id, NewOrderInfo orderInfo)
 {
     try
     {
         _service.AddOrder(id, orderInfo);
     }
     catch (CustomerNotFoundException ex)
     {
         return(BadRequest("Such customer does not exists"));
     }
     catch (ConfectioneryNameNotFoundException ex) {
         return(BadRequest("No such confectionery name"));
     }
     return(Ok("Done"));
 }
示例#10
0
 public async Task <HttpResponseMessage> Post([FromBody] NewOrderInfo info)
 {
     try
     {
         await new Mapper().CreateOrder(new DCRXmlParser().Parse(Properties.Resources.Bachelor2), info);
         var response = Request.CreateResponse(HttpStatusCode.OK);
         response.ReasonPhrase = "success";
         return(response);
     }
     catch (Exception ex)
     {
         var response = Request.CreateResponse(HttpStatusCode.InternalServerError);
         response.ReasonPhrase = ex.Message;
         return(response);
     }
 }
示例#11
0
        public static NewOrderInfo newOrderInfo(string source)
        {
            var          serializer = new JavaScriptSerializer();
            NewOrderInfo obj        = null;

            if (verifierVersion(source, serializer))
            {
                obj = serializer.Deserialize <NewOrderInfo11>(source);
            }
            else
            {
                obj = serializer.Deserialize <NewOrderInfo10>(source);
            }

            return(obj);
        }
示例#12
0
        public override void Display()
        {
            //Prompts user for date and order number.

            UserDate = UserInput.GetDate();
            int userOrderNumber = UserInput.GetUserOrderNumber();

            OrderInfo existingOrder = OrderManager.GetOrder(UserDate, userOrderNumber);

            if (existingOrder == null)
            {
                UserInput.Log("That order number doesn't exist.");
                return;
            }

            NewOrderInfo newOrder = new NewOrderInfo();

            newOrder.OrderNum = existingOrder.OrderNum;


            //Prompts user for new information based on stored information.
            Console.WriteLine("Edit order details, press enter to accept current order details: ");
            Console.WriteLine();

            Console.WriteLine("Order Number: {0}", userOrderNumber);
            newOrder.CustomerName = Edit("Name", existingOrder.CustomerName);

            newOrder.Area  = EditDecimal("Project Area", existingOrder.Area);
            newOrder.State = EditState("State Abbreviation", existingOrder.State);

            Console.WriteLine("State Name: {0}", newOrder.State.StateName);

            Console.WriteLine("Tax Rate: {0}", newOrder.State.TaxRate);

            newOrder.Product = EditProductType("Product Type", existingOrder.Product);

            Console.WriteLine("Labor cost per square foot: {0}", newOrder.Product.LaborCostPerSqFoot);

            Console.WriteLine("Cost per square foot: {0}", newOrder.Product.CostPerSqFoot);

            bool committed = OrderManager.UpdateOrder(UserDate, existingOrder, newOrder, ConfirmUpdateOrder);

            Console.WriteLine(committed ? "Your changes were saved." : "Your changes were not saved.");
            Console.ReadLine();
        }
示例#13
0
        public void Test()
        {
            FlooringManager.Configure(true);
            MockOrderRepo orderRepo = FlooringManager.Orders as MockOrderRepo;

            Assert.AreEqual(0, orderRepo.SavedOrders.Count);

            Func <OrderInfo, bool> mockFunction = (order) =>
            {
                Assert.AreEqual(order.CustomerName, "Test Name");
                return(true);
            };
            NewOrderInfo newOrder = new NewOrderInfo();

            newOrder.CustomerName = "Test Name";
            newOrder.Area         = 0;

            ProductInfo myProduct = new ProductInfo();

            myProduct.ProductType        = "carpet";
            myProduct.CostPerSqFoot      = 0;
            myProduct.LaborCostPerSqFoot = 0;
            newOrder.Product             = myProduct;

            StateInfo myState = new StateInfo();

            myState.StateAbbreviation = "MN";
            myState.StateName         = "Minnesota";
            myState.TaxRate           = 0;

            newOrder.State = myState;

            OrderManager.CreateOrder(newOrder, mockFunction);

            Assert.AreEqual(1, orderRepo.SavedOrders.Count);
            Assert.IsTrue(orderRepo.SavedOrders.ContainsKey(DateTime.Today));

            var todaysOrders = orderRepo.SavedOrders[DateTime.Today];

            Assert.AreEqual(1, todaysOrders.Count);
            Assert.AreEqual("Test Name", todaysOrders[0].CustomerName);
        }
示例#14
0
        public override void Display()
        {
            //Prompt user for new order information, verifying with methods on UserInput screen, and assigning them to variables.

            NewOrderInfo myNewOrder = new NewOrderInfo();

            Console.WriteLine("Please enter the following information");

            myNewOrder.CustomerName = UserInput.GetString("Please enter your name: ");

            myNewOrder.Area = UserInput.GetDecimal("Area of project in square feet: ");

            myNewOrder.Product = UserInput.GetProductType("Product type: ");

            myNewOrder.State = UserInput.GetState("State (abbreviation): ");

            bool committed = OrderManager.CreateOrder(myNewOrder, ConfirmAddOrder);

            Console.WriteLine(committed ? "Your order was saved." : "Your order was not saved.");
            Console.ReadLine();
        }
示例#15
0
        public void AddOrder(int idCustomer, NewOrderInfo orderInfo)
        {
            int idConfectionery = _context.Confectionery.Where(c => c.Name == orderInfo.Confectionery.Name)
                                  .Select(c => c.IdConfectionery)
                                  .FirstOrDefault();

            if (idConfectionery == 0)
            {
                throw new ConfectioneryNameNotFoundException();
            }

            if (!_context.Customer.Any(e => e.IdCustomer == idCustomer))
            {
                throw new CustomerNotFoundException();
            }

            Random random = new Random();

            Order newOrder = new Order()
            {
                IdOrder      = _context.Order.Max(o => o.IdOrder) + 1,
                IdCustomer   = idCustomer,
                IdEmployee   = random.Next(1, _context.Employee.Max(e => e.IdEmployee)),
                DateAccepted = orderInfo.DateAccepted,
                DateFinished = orderInfo.DateAccepted,
                Notes        = orderInfo.Notes,
            };

            Confectionery_Order newConfectionery_Order = new Confectionery_Order()
            {
                IdOrder         = newOrder.IdOrder,
                IdConfectionery = idConfectionery,
                Quantity        = orderInfo.Confectionery.Quantity,
                Notes           = orderInfo.Confectionery.Notes
            };

            _context.Order.Add(newOrder);
            _context.Confectionery_Order.Add(newConfectionery_Order);
            _context.SaveChanges();
        }
示例#16
0
        /// <summary>
        /// Method to create new orders in the database.
        /// It will create a new order with the information it receives and with the DCRGraph which is currently in the xml file which the API reads from.
        /// </summary>
        /// <param name="container"></param>
        /// <param name="orderInfo"></param>
        /// <returns></returns>
        public async Task <Tuple <string, HttpStatusCode> > CreateOrder(EventAndRolesContainer container, NewOrderInfo orderInfo)
        {
            using (var db = new WebAPI.Models.DBObjects.Database())
            {
                try
                {
                    //setup a new dcrgraph
                    var graph = new DCRGraph
                    {
                        AcceptingState = false,
                        Lock           = false,
                        LockTime       = DateTime.Now,
                        DCREvents      = container.Events,
                    };

                    //setup a new order
                    var order = new Order()
                    {
                        DCRGraph     = graph,
                        OrderDate    = orderInfo.OrderDate,
                        Notes        = orderInfo.Notes,
                        Table        = orderInfo.Table,
                        OrderDetails = new List <OrderDetail>(),
                        OrderType    = orderInfo.OrderType,
                        RestaurantId = orderInfo.Restaurant
                    };

                    //put items on the order. Can only put items that exists in the database on.
                    foreach (var iq in orderInfo.ItemsAndQuantity)
                    {
                        var item =
                            db.Items
                            .FirstOrDefaultAsync(i => i.Name == iq.Key.Name).Result;

                        if (!iq.Key.Name.ToLower().Equals(item.Name.ToLower()))
                        {
                            throw new Exception("Item '" + iq.Key.Name + "' did not exist in the database");
                        }

                        order.OrderDetails.Add(
                            new OrderDetail()
                        {
                            ItemId   = item.Id,
                            Item     = item,
                            Order    = order,
                            Quantity = iq.Value
                        });
                    }



                    //Determine if there should be a customer on the order. We do not want cutstomers with the phone number 0.
                    if (orderInfo.Customer.Phone != 0)
                    {
                        //see if we already have customer with the same phone number, otherwise create a new one.
                        var customer =
                            await db.Customers
                            .FirstOrDefaultAsync(c => c.Phone == orderInfo.Customer.Phone) ?? new Customer
                        {
                            City            = orderInfo.Customer.City ?? "n/a",
                            Email           = orderInfo.Customer.Email ?? "n/a",
                            FirstName       = orderInfo.Customer.FirstAndMiddleNames ?? "n/a",
                            LastName        = orderInfo.Customer.LastName ?? "n/a",
                            Phone           = orderInfo.Customer.Phone,
                            StreetAndNumber = orderInfo.Customer.StreetAndNumber ?? "n/a",
                            Zipcode         = orderInfo.Customer.ZipCode,
                            Orders          = new HashSet <Order> {
                                order
                            }
                        };

                        order.Customer = customer;
                    }

                    db.Orders.Add(order);
                    db.SaveChanges();


                    //put groups on events
                    foreach (var i in container.EventGroups)
                    {
                        var group = db.Groups.FirstOrDefaultAsync(x => x.Name.Equals(i.GroupName)).Result;
                        container.Events.Find(x => x.EventId.Equals(i.EventId)).Groups.Add(group);
                    }


                    //put roles on events
                    foreach (var i in container.EventRoles)
                    {
                        var role = db.Roles.FirstOrDefaultAsync(x => x.Name.Equals(i.RoleName)).Result;
                        container.Events.Find(x => x.EventId.Equals(i.EventId)).Roles.Add(role);
                    }


                    //put inclusions on events
                    foreach (var i in container.Inclusions)
                    {
                        var fromEvent = container.Events.Find(x => x.EventId.Equals(i.fromNodeId));
                        var toEvent   = container.Events.Find(x => x.EventId.Equals(i.toNodeId));
                        container.Events.Find(e => e.Id == fromEvent.Id).Includes.Add(toEvent);
                        //InsertBySqlQuery(fromEvent.Id, toEvent.Id, "Includes");
                    }

                    //put exclusions on events
                    foreach (var i in container.Exclusions)
                    {
                        var fromEvent = container.Events.Find(x => x.EventId.Equals(i.fromNodeId));
                        var toEvent   = container.Events.Find(x => x.EventId.Equals(i.toNodeId));
                        container.Events.Find(e => e.Id == fromEvent.Id).Excludes.Add(toEvent);
                        //InsertBySqlQuery(fromEvent.Id, toEvent.Id, "Excludes");
                    }

                    //put responses on events
                    foreach (var i in container.Responses)
                    {
                        var fromEvent = container.Events.Find(x => x.EventId.Equals(i.fromNodeId));
                        var toEvent   = container.Events.Find(x => x.EventId.Equals(i.toNodeId));
                        container.Events.Find(e => e.Id == fromEvent.Id).Responses.Add(toEvent);
                        //InsertBySqlQuery(fromEvent.Id, toEvent.Id, "Milestones");
                    }

                    //put conditions on events
                    foreach (var i in container.Conditions)
                    {
                        var fromEvent = container.Events.Find(x => x.EventId.Equals(i.fromNodeId));
                        var toEvent   = container.Events.Find(x => x.EventId.Equals(i.toNodeId));
                        container.Events.Find(e => e.Id == fromEvent.Id).Conditions.Add(toEvent);
                        //InsertBySqlQuery(fromEvent.Id, toEvent.Id, "Conditions");
                    }



                    //put milestones on events
                    foreach (var i in container.Milestones)
                    {
                        var fromEvent = container.Events.Find(x => x.EventId.Equals(i.fromNodeId));
                        var toEvent   = container.Events.Find(x => x.EventId.Equals(i.toNodeId));
                        container.Events.Find(e => e.Id == fromEvent.Id).Milestones.Add(toEvent);
                        //InsertBySqlQuery(fromEvent.Id, toEvent.Id, "Milestones");
                    }



                    foreach (var e in container.Events)
                    {
                        db.Entry(e).State = EntityState.Modified;
                    }
                    await db.SaveChangesAsync();

                    //needs statuscode exception handling
                    DCREvent dcrEvent;
                    switch (orderInfo.OrderType)
                    {
                    case "For serving":
                        dcrEvent = order.DCRGraph.DCREvents.FirstOrDefault(e => e.Label == "Setup graph serving");
                        if (dcrEvent != null)
                        {
                            await new DbInteractions().ExecuteEvent(dcrEvent.Id, false);
                            break;
                        }
                        return(new Tuple <string, HttpStatusCode>("The DCRGraph does not contain the relvant setup event",
                                                                  HttpStatusCode.InternalServerError));

                    case "For takeaway":
                        dcrEvent = order.DCRGraph.DCREvents.FirstOrDefault(e => e.Label == "Setup graph takeaway");
                        if (dcrEvent != null)
                        {
                            await new DbInteractions().ExecuteEvent(dcrEvent.Id, false);
                            break;
                        }

                        return(new Tuple <string, HttpStatusCode>("The DCRGraph does not contain the relvant setup event",
                                                                  HttpStatusCode.InternalServerError));

                    case "For delivery":
                        dcrEvent = order.DCRGraph.DCREvents.FirstOrDefault(e => e.Label.Contains("Setup graph delivery"));
                        if (dcrEvent != null)
                        {
                            await new DbInteractions().ExecuteEvent(dcrEvent.Id, false);
                            break;
                        }
                        return(new Tuple <string, HttpStatusCode>("The DCRGraph does not contain the relvant setup event",
                                                                  HttpStatusCode.InternalServerError));

                    case "Bulk order":
                        dcrEvent = order.DCRGraph.DCREvents.FirstOrDefault(e => e.Label.Contains("Setup bulk order"));
                        if (dcrEvent != null)
                        {
                            await new DbInteractions().ExecuteEvent(dcrEvent.Id, false);
                            break;
                        }
                        return(new Tuple <string, HttpStatusCode>("The DCRGraph does not contain the relvant setup event",
                                                                  HttpStatusCode.InternalServerError));

                    default:
                        return(new Tuple <string, HttpStatusCode>("ordertype id not match - " + orderInfo.OrderType,
                                                                  HttpStatusCode.InternalServerError));
                    }



                    //scope.Complete();
                    return(new Tuple <string, HttpStatusCode>("success", HttpStatusCode.OK));
                }
                catch (Exception ex)
                {
                    return(new Tuple <string, HttpStatusCode>(ex.Message, HttpStatusCode.InternalServerError));
                }

                //}
            }
        }