Exemple #1
0
        public ActionResult Index(DefaultModel model)
        {
            var data = _service.CreateQuery().FindList(!string.IsNullOrEmpty(model.SearchText), o => o.Name.Contains(model.SearchText) || o.Code.Contains(model.SearchText))
                       .Where(!string.IsNullOrEmpty(model.ID), o => o.ID == model.ID)
                       .OrderByDescending(o => o.ID)
                       .ToList();

            ViewBag.Data      = data.Skip(model.PageSize * model.PageIndex).Take(model.PageSize).ToList();
            model.TotalRecord = data.Count;
            ViewBag.Model     = model;
            return(View());
        }
        public void Export(DefaultModel model)
        {
            DateTime startDate = model.StartDate > DateTime.MinValue ? new DateTime(model.StartDate.Year, model.StartDate.Month, model.StartDate.Day, 0, 0, 0) : DateTime.MinValue;
            DateTime endDate   = model.EndDate > DateTime.MinValue ? new DateTime(model.EndDate.Year, model.EndDate.Month, model.EndDate.Day, 23, 59, 59) : DateTime.MinValue;

            var data = _service.CreateQuery().FindList(!string.IsNullOrEmpty(model.SearchText), o => o.Name.Contains(model.SearchText) || o.Code.Contains(model.SearchText))
                       .Where(!string.IsNullOrEmpty(model.ID), o => o.ID == model.ID)
                       .Where(startDate > DateTime.MinValue, o => o.Created >= startDate)
                       .Where(endDate > DateTime.MinValue, o => o.Created <= endDate)
                       .OrderByDescending(o => o.ID)
                       .ToList();

            DataTable dt = data.ToDataTable();

            Response.Clear();
            Response.Headers["content-disposition"] = "attachment;filename=DanhMucCapDo.xls";
            Response.ContentType = "application/excel";

            string     html           = Query.ConvertDataTableToHTML(dt);
            HtmlString htmlTextWriter = new HtmlString(html);

            Response.WriteAsync(html);
        }