public ActionResult SearchOrder()
        {
            try
            {
                var table = new StringBuilder();
                var datefrom = DateTime.ParseExact(Request["DateFrom"], "dd/MM/yyyy", null);
                var dateto = DateTime.ParseExact(Request["DateTo"], "dd/MM/yyyy", null);
                var oService = new OrderService();
                var cService = new CustomerService();
                var orders = oService.GetOrderByDate(datefrom, dateto);
                var totalcount = orders.Count();
                var newcount = orders.Count(c => c.IsSeen == false);
                double totalsum = 0, newsum = 0;

                table.Append("<table id='table1' class='table1'>");
                table.Append("<thead>");
                table.Append("<tr>");
                table.Append("<th>Mã đơn hàng</th>");
                table.Append("<th>Giá đơn hàng</th>");
                table.Append("<th>Tỉnh/thành khách hàng</th>");
                table.Append("<th>Trạng thái đơn hàng</th>");
                table.Append("</tr>");
                table.Append("</thead>");

                table.Append("<tbody>");
                foreach (var order in orders)
                {
                    var total = oService.GetOrderDetailByOrderid(order.Id).Sum(c => c.TotalQuantity);
                    var customer = cService.GetCustomerById(order.CustomerId);
                    if (order.IsSeen == false)
                        table.Append("<tr style='background:grey'>");
                    else
                        table.Append("<tr>");
                    table.AppendFormat("<td>{0}</td>", order.Code);
                    table.AppendFormat("<td>{0}</td>", Constant.ConvertCurrency(total));
                    table.AppendFormat("<td>{0}</td>", customer.City.Name);
                    table.AppendFormat("<td>{0}</td>", AccessFactory.GetStatus(order.Status));
                    table.Append("</tr>");

                    totalsum += total;
                    if (order.IsSeen == false)
                        newsum += total;
                }

                table.Append("</tbody>");
                table.Append("</table>");
                oService.UpdateOrderInSeen(orders);

                return Json(new
                {
                    finish = true,
                    data = table.ToString(),
                    totalCount = totalcount,
                    totalSum = Constant.ConvertCurrency(totalsum),
                    newCount = newcount,
                    newSum = Constant.ConvertCurrency(newsum)
                });
            }
            catch (Exception e)
            {

                return Json(new { finish = false, data = e.ToString() });

            }
        }
        public ActionResult SearchCustomer()
        {
            try
            {
                var table = new StringBuilder();
                var datefrom = DateTime.ParseExact(Request["DateFrom"], "dd/MM/yyyy", null);
                var dateto = DateTime.ParseExact(Request["DateTo"], "dd/MM/yyyy", null);
                var oService = new OrderService();
                var orders = oService.GetOrderByDate(datefrom, dateto).
                              Where(c => c.ReferUserId == AccessFactory.CurrentUser.Id);

                table.Append("<table id='table1' class='table1'>");
                table.Append("<thead>");
                table.Append("<tr>");
                table.Append("<th>Mã đơn hàng</th>");
                table.Append("<th>Tổng giá trị</th>");
                table.Append("<th>Ngày tạo</th>");
                table.Append("</tr>");
                table.Append("</thead>");

                table.Append("<tbody>");
                foreach (var order in orders)
                {
                    var total = oService.GetOrderDetailByOrderid(order.Id).Sum(c => c.TotalQuantity);

                    table.Append("<tr>");
                    table.AppendFormat("<td>{0}</td>", order.Code);
                    table.AppendFormat("<td>{0}</td>", Constant.ConvertCurrency(total));
                    table.AppendFormat("<td>{0}</td>", order.CreatedDate.ToString("dd/MM/yyyy"));
                    table.Append("</tr>");
                }

                table.Append("</tbody>");
                table.Append("</table>");

                return Json(new
                {
                    finish = true,
                    data = table.ToString()
                });
            }
            catch (Exception e)
            {
                return Json(new { finish = false, data = e.ToString() });
            }
        }