public async Task<IHttpActionResult> GetMenuDTO() { var menuDTO = new List<MenuDTO>(); var connectionString = ConfigurationManager.ConnectionStrings["TRAContext"].ConnectionString; SqlDataReader reader = null; using (var connection = new SqlConnection(connectionString)) { var cmd = new SqlCommand("dbp_resto_get_menu", connection); connection.Open(); try { reader = cmd.ExecuteReader(); menuDTO = new CommonResource.ReflectionPopulator<MenuDTO>().CreateList(reader); } catch (Exception ex) { var message = ex.Message; throw; } finally { if (reader != null) { reader.Close(); } } } return Ok(menuDTO); }
public async Task<IHttpActionResult> GetRecentOrders(string orderType, string orderValue) { var connectionString = ConfigurationManager.ConnectionStrings["TRAContext"].ConnectionString; SqlDataReader reader = null; var orderdto = new List<OrderDetailDTO>(); using (var connection = new SqlConnection(connectionString)) { var cmd = new SqlCommand("dbp_get_recent_orders", connection); connection.Open(); try { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@pv_order_by", orderType)); cmd.Parameters.Add(new SqlParameter("@pv_value", orderValue)); reader = cmd.ExecuteReader(); var orderlist = new CommonResource.ReflectionPopulator<TempOrderDTO>().CreateList(reader); var dorderlist = orderlist.GroupBy(c => c.OrderId).Select(s => new OrderDetailDTO() { Comments = s.FirstOrDefault().Comments, CustomerId = s.FirstOrDefault().CustomerId, DateOrdered = s.FirstOrDefault().DateOrdered, DateRequired = s.FirstOrDefault().DateRequired, ID = s.FirstOrDefault().OrderId, IsInvoiced = s.FirstOrDefault().IsInvoiced, Name = s.FirstOrDefault().Name, OrderItems = s.Where(d => d.OrderId == s.Key).Select(m => new TransactionDTO() { MenuID = m.MenuID, MenuName = m.MenuName, Quantity = m.Quantity, UnitPrice = m.UnitPrice, }).ToList(), }).ToList(); orderdto = dorderlist; } catch (Exception ex) { var message = ex.Message; throw; } finally { if (reader != null) { reader.Close(); } } } return Ok(orderdto); }
public async Task<IHttpActionResult> GetOrdersDTO(string orderType, string orderValue) { var connectionString = ConfigurationManager.ConnectionStrings["TRAContext"].ConnectionString; SqlDataReader reader = null; var orderdto = new List<OrderDTO>(); using (var connection = new SqlConnection(connectionString)) { var cmd = new SqlCommand("dbp_get_orders", connection); connection.Open(); try { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@pv_order_by", orderType)); cmd.Parameters.Add(new SqlParameter("@pv_value", orderValue)); reader = cmd.ExecuteReader(); var orderlist = new CommonResource.ReflectionPopulator<OrderDTO>().CreateList(reader); orderdto = orderlist; } catch (Exception ex ) { var message = ex.Message; throw; } finally { if (reader != null) { reader.Close(); } } } return Ok(orderdto); }