public async Task <HttpResponseMessage> ArchiveOrder(DROM_Client.Models.BusinessObjects.Order order) { var result = await new DbInteractions().AchiveOrder(order.Id); var response = Request.CreateResponse(result.Item2); response.ReasonPhrase = result.Item1; return(response); }
/// <summary> /// Calls API to update order. /// </summary> /// <param name="updatedOrder">Updated order to be saved</param> /// <param name="editEvents">List of id's of edit events to be executed</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> PutUpdateOrder(Order updatedOrder, List<int> editEvents) { using (var client = new HttpClient()) { try { var dto = new Tuple<Order, List<int>>(updatedOrder, editEvents); client.BaseAddress = _baseAddress; var response = client.PutAsXmlAsync("api/order/updateorder", dto).Result; if (response.IsSuccessStatusCode) { return new Tuple<bool, string>(true, response.StatusCode.ToString()); } else //do failure thing { return new Tuple<bool, string>(false, "Could not save updated order: Error from Web api: " + response.StatusCode.ToString() + ": " + response.ReasonPhrase); } } catch (Exception ex) { throw; } } }
/// <summary> /// Archives order on Web API (Does not delete order on Web API) /// </summary> /// <param name="order">Order to be deleted</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> PutDeleteOrder(Order order) { using (var client = new HttpClient()) { try { client.BaseAddress = _baseAddress; var response = client.PutAsXmlAsync("api/order/archive", order).Result; //Archiving, not deleting if (response.IsSuccessStatusCode) { return new Tuple<bool, string>(true, response.StatusCode.ToString()); } else //do failure thing { return new Tuple<bool, string>(false, "Could not delete order: Error from Web api: " + response.StatusCode.ToString() + ": " + response.ReasonPhrase); } } catch (Exception ex) { throw; } } }
/// <summary> /// Method to find orders in the database, while filtering events so that only pending and edit events are loaded. /// </summary> /// <param name="restaurant"></param> /// <returns></returns> public async Task<Tuple<List<DROM_Client.Models.BusinessObjects.Order>, string, HttpStatusCode>> GetOrdersWithSortedEvents(int restaurant) { try { using (var db = new Database()) { //get non arcihved orders from database, with only relevant events. //Projection is used to get the data, since filtering on child collections is not availeble in eager loading https://msdn.microsoft.com/en-us/magazine/hh205756.aspx var query = await (from o in db.Orders where o.Archived == false where o.RestaurantId == restaurant select new { Order = o, //child collections aren't loaded, and have to be selected seperately Graph = o.DCRGraph, Events = (from e in o.DCRGraph.DCREvents where ( e.Pending && e.Included && !e.Conditions.Any( c => c.Included && c.Executed == false) && !e.Milestones.Any( m => m.Included && m.Pending) ) || ( e.Groups.Any(g => g.Name == "Edit events") && e.Included ) select new { Event = e, Groups = e.Groups, Roles = e.Roles } ), Customer = o.Customer, OrderDetails = o.OrderDetails, Items = (from od in o.OrderDetails select new { Item = od.Item, Category = od.Item.Category, Quantity = od.Quantity } ), }).ToListAsync(); var orders = new List<DROM_Client.Models.BusinessObjects.Order>(); //go through all the orders loaded from the database ad make DTOs foreach (var queryOrder in query) { //Make a DTO order and set all the non collection type properties var order = new DROM_Client.Models.BusinessObjects.Order() { Id = queryOrder.Order.Id, Notes = queryOrder.Order.Notes, OrderDate = queryOrder.Order.OrderDate, OrderType = queryOrder.Order.OrderType, Table = queryOrder.Order.Table, AcceptingState = queryOrder.Graph.AcceptingState, Restaurant = restaurant }; var events = new List<Event>(); //Assemble events - meaning put the disjointed information together in one object. foreach (var e in queryOrder.Events) { var assemblyEvent = new Event { Description = e.Event.Description, Executed = e.Event.Executed, Id = e.Event.Id, Included = e.Event.Included, Label = e.Event.Label, Pending = e.Event.Pending, Groups = new List<Group>() }; foreach (var g in e.Groups) { assemblyEvent.Groups.Add(new Group() { Id = g.Id, Name = g.Name }); } assemblyEvent.Roles = new List<Role>(); foreach (var r in e.Roles) { assemblyEvent.Roles.Add(new Role() { Id = r.Id, Name = r.Name }); } events.Add(assemblyEvent); } //make the DCRGraph, to be put onto the order, with all the newly assembled events in it order.DCRGraph = new DROM_Client.Models.BusinessObjects.DCRGraph() { Id = queryOrder.Graph.Id, Events = events }; order.ItemsAndQuantity = new List<ItemQuantity>(); //put item, quantity and category together to form the DTO Item and quantity. foreach (var i in queryOrder.Items) { order.ItemsAndQuantity.Add(new ItemQuantity() { Item = new DROM_Client.Models.BusinessObjects.Item() { Id = i.Item.Id, Description = i.Item.Description, Price = i.Item.Price, Name = i.Item.Name, Category = i.Category.Name }, Quantity = i.Quantity }); } //If there is a customer, include it. if (queryOrder.Customer != null) { //map customer to DTO Customer order.Customer = new DROM_Client.Models.BusinessObjects.Customer() { Id = queryOrder.Customer.Id, City = queryOrder.Customer.City, Phone = queryOrder.Customer.Phone, ZipCode = queryOrder.Customer.Zipcode, Email = queryOrder.Customer.Email, StreetAndNumber = queryOrder.Customer.StreetAndNumber, LastName = queryOrder.Customer.LastName, FirstAndMiddleNames = queryOrder.Customer.FirstName }; } orders.Add(order); } return new Tuple<List<DROM_Client.Models.BusinessObjects.Order>, string, HttpStatusCode>(orders, "Success", HttpStatusCode.OK); } } catch (Exception ex) { return new Tuple<List<DROM_Client.Models.BusinessObjects.Order>, string, HttpStatusCode>(null, ex.Message, HttpStatusCode.InternalServerError); } }
/// <summary> /// Method to find orders in the database, while filtering events so that only pending and edit events are loaded. /// </summary> /// <param name="restaurant"></param> /// <returns></returns> public async Task <Tuple <List <DROM_Client.Models.BusinessObjects.Order>, string, HttpStatusCode> > GetOrdersWithSortedEvents(int restaurant) { try { using (var db = new Database()) { //get non arcihved orders from database, with only relevant events. //Projection is used to get the data, since filtering on child collections is not availeble in eager loading https://msdn.microsoft.com/en-us/magazine/hh205756.aspx var query = await(from o in db.Orders where o.Archived == false where o.RestaurantId == restaurant select new { Order = o, //child collections aren't loaded, and have to be selected seperately Graph = o.DCRGraph, Events = (from e in o.DCRGraph.DCREvents where ( e.Pending && e.Included && !e.Conditions.Any( c => c.Included && c.Executed == false) && !e.Milestones.Any( m => m.Included && m.Pending) ) || ( e.Groups.Any(g => g.Name == "Edit events") && e.Included ) select new { Event = e, Groups = e.Groups, Roles = e.Roles } ), Customer = o.Customer, OrderDetails = o.OrderDetails, Items = (from od in o.OrderDetails select new { Item = od.Item, Category = od.Item.Category, Quantity = od.Quantity } ), }).ToListAsync(); var orders = new List <DROM_Client.Models.BusinessObjects.Order>(); //go through all the orders loaded from the database ad make DTOs foreach (var queryOrder in query) { //Make a DTO order and set all the non collection type properties var order = new DROM_Client.Models.BusinessObjects.Order() { Id = queryOrder.Order.Id, Notes = queryOrder.Order.Notes, OrderDate = queryOrder.Order.OrderDate, OrderType = queryOrder.Order.OrderType, Table = queryOrder.Order.Table, AcceptingState = queryOrder.Graph.AcceptingState, Restaurant = restaurant }; var events = new List <Event>(); //Assemble events - meaning put the disjointed information together in one object. foreach (var e in queryOrder.Events) { var assemblyEvent = new Event { Description = e.Event.Description, Executed = e.Event.Executed, Id = e.Event.Id, Included = e.Event.Included, Label = e.Event.Label, Pending = e.Event.Pending, Groups = new List <Group>() }; foreach (var g in e.Groups) { assemblyEvent.Groups.Add(new Group() { Id = g.Id, Name = g.Name }); } assemblyEvent.Roles = new List <Role>(); foreach (var r in e.Roles) { assemblyEvent.Roles.Add(new Role() { Id = r.Id, Name = r.Name }); } events.Add(assemblyEvent); } //make the DCRGraph, to be put onto the order, with all the newly assembled events in it order.DCRGraph = new DROM_Client.Models.BusinessObjects.DCRGraph() { Id = queryOrder.Graph.Id, Events = events }; order.ItemsAndQuantity = new List <ItemQuantity>(); //put item, quantity and category together to form the DTO Item and quantity. foreach (var i in queryOrder.Items) { order.ItemsAndQuantity.Add(new ItemQuantity() { Item = new DROM_Client.Models.BusinessObjects.Item() { Id = i.Item.Id, Description = i.Item.Description, Price = i.Item.Price, Name = i.Item.Name, Category = i.Category.Name }, Quantity = i.Quantity }); } //If there is a customer, include it. if (queryOrder.Customer != null) { //map customer to DTO Customer order.Customer = new DROM_Client.Models.BusinessObjects.Customer() { Id = queryOrder.Customer.Id, City = queryOrder.Customer.City, Phone = queryOrder.Customer.Phone, ZipCode = queryOrder.Customer.Zipcode, Email = queryOrder.Customer.Email, StreetAndNumber = queryOrder.Customer.StreetAndNumber, LastName = queryOrder.Customer.LastName, FirstAndMiddleNames = queryOrder.Customer.FirstName }; } orders.Add(order); } return(new Tuple <List <DROM_Client.Models.BusinessObjects.Order>, string, HttpStatusCode>(orders, "Success", HttpStatusCode.OK)); } } catch (Exception ex) { return(new Tuple <List <DROM_Client.Models.BusinessObjects.Order>, string, HttpStatusCode>(null, ex.Message, HttpStatusCode.InternalServerError)); } }
private async void Delete_Order_Click(object sender, RoutedEventArgs e) { _orderToBeDeleted = ((Button)sender).Tag as Order; // Create the message dialog and set its content var messageDialog = new MessageDialog("Are you sure you want to delete this order?"); // Add commands and set their callbacks; both buttons use the same callback function instead of inline event handlers messageDialog.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(this.delete_Popup_Yes))); messageDialog.Commands.Add(new UICommand("No", new UICommandInvokedHandler(this.delete_Popup_No))); // Set the command to be invoked when escape is pressed messageDialog.CancelCommandIndex = 1; // Show the message dialog await messageDialog.ShowAsync(); }