Esempio n. 1
0
        public IHttpResponse List(IHttpContext httpContext)
        {
            string username = httpContext.Request.Session.GetParameter(SessionParamsConstants.CurrentUser).ToString();

            IList <ShortOrderDetailsViewModel> orderDetails = this.orders.ShortDetailsList(username);

            List <string> headers = new List <string> {
                "OrderID", "Created On", "Sum"
            };

            string[][] data = new string[orderDetails.Count][];

            for (int i = 0; i < orderDetails.Count; i++)
            {
                data[i] = new[] { $"<a href=\"\\order\\{orderDetails[i].Id}\">{orderDetails[i].Id}</a>", $"{orderDetails[i].CreationDate}", $"{orderDetails[i].TotalAmount}" };
            }

            HtmlTableDataModel dataModel = new HtmlTableDataModel(headers, data);

            string table = HtmlHelper.HtmlTable(dataModel);

            this.ViewData[ViewDataConstants.Orders] = table;

            return(this.HtmlViewResponse("order/list"));
        }
Esempio n. 2
0
        public static string HtmlTable(HtmlTableDataModel dataModel)
        {
            if (dataModel == null)
            {
                return("");
            }

            IList <string> headers = dataModel.Headers;

            string[][] data = dataModel.Data;

            StringBuilder table = new StringBuilder();

            table.AppendLine("<table>");
            table.AppendLine("<tr>");
            foreach (string header in headers)
            {
                table.AppendLine($"<th>{header}</th>");
            }
            table.AppendLine("</tr>");
            for (int i = 0; i < data.Length; i++)
            {
                table.AppendLine("<tr>");
                foreach (string item in data[i])
                {
                    table.AppendLine($"<td>{item}</td>");
                }
                table.AppendLine("</tr>");
            }

            table.AppendLine("</table>");

            return(table.ToString().Trim());
        }
Esempio n. 3
0
        public IHttpResponse Details(IHttpContext httpContext)
        {
            Cart cart = (Cart)httpContext.Request.Session.GetParameter(SessionParamsConstants.Cart);

            List <string> headers = new List <string> {
                "Product", "Count", "Amount"
            };

            IDictionary <int, int> orderedProductsIds = cart.OrderedItems;

            IDictionary <ProductInCartViewModel, int> orderedProducts = new Dictionary <ProductInCartViewModel, int>();

            foreach (KeyValuePair <int, int> productId in orderedProductsIds)
            {
                ProductInCartViewModel product = this.products.GetOrderedProductDetails(productId.Key);

                orderedProducts.Add(product, productId.Value);
            }

            decimal totalAmount = 0;

            string[][] data = new string[orderedProducts.Count][];

            for (int i = 0; i < data.Length; i++)
            {
                string  productName   = orderedProducts.ToList()[i].Key.Name;
                int     productsCount = orderedProducts.ToList()[i].Value;
                decimal price         = orderedProducts.ToList()[i].Key.Price;
                decimal amount        = price * productsCount;

                totalAmount += amount;

                data[i] = new[] { $"{productName}", $"{productsCount}", $"{amount:f2}" };
            }

            HtmlTableDataModel dataModel = new HtmlTableDataModel(headers, data);

            string table = HtmlHelper.HtmlTable(dataModel);

            this.ViewData[ViewDataConstants.Details]     = table;
            this.ViewData[ViewDataConstants.TotalAmount] = $"{totalAmount:f2}";

            return(this.HtmlViewResponse("/cart/details"));
        }
Esempio n. 4
0
        public IHttpResponse Details(IHttpContext httpContext)
        {
            int orderId = NumberParser.ParseInt(httpContext.Request.UrlParameters["id"]);

            OrderDetailsViewModel order = this.orders.Details(orderId);

            List <string> headers = new List <string> {
                "Product", "Quantity", "Amount"
            };

            string[][] data = new string[order.Products.Count][];

            decimal totalAmount = 0;

            for (int i = 0; i < order.Products.Count; i++)
            {
                string  productName = order.Products[i].Item1;
                int     quantity    = order.Products[i].Item2;
                decimal price       = order.Products[i].Item3;
                decimal amount      = quantity * price;
                totalAmount += amount;


                data[i] = new[] { $"{productName}", $"{quantity}", $"{amount:f2}" };
            }

            HtmlTableDataModel dataModel = new HtmlTableDataModel(headers, data);

            string table = HtmlHelper.HtmlTable(dataModel);

            this.ViewData[ViewDataConstants.Id]           = order.Id.ToString();
            this.ViewData[ViewDataConstants.CreationDate] = DateTime.Now.ToString("dd-MM-yyyy");
            this.ViewData[ViewDataConstants.TotalAmount]  = $"{totalAmount:f2}";
            this.ViewData[ViewDataConstants.Products]     = table;

            return(this.HtmlViewResponse("order/details"));
        }