コード例 #1
0
ファイル: CustomerController.cs プロジェクト: snowpl/CRUD
        public ActionResult Index()
        {
            var customers = _customerQueryService.GetAll();

            var result = customers.Select(x => Convert(x)).ToList();

            return(View(result));
        }
コード例 #2
0
        public HttpResponseMessage Get( )
        {
            List <ICustomerExcelDto> result = new EditableList <ICustomerExcelDto>();
            var customer = _customerQueryService.GetAll();

            result.AddRange(customer.Select(p => new CustomerExcelDto
            {
                FirstName    = p.FirstName,
                LastName     = p.LastName,
                EmailAddress = p.EmailAddress,
                IsActive     = p.IsActive?"فعال":"غیر فعال",
            }));
            HttpResponseMessage response;
            DataTable           dt = new DataTable();

            dt = result.ToDataTableExtension();
            MemoryStream ms = new MemoryStream();

            try
            {
                ExcelReader.WriteExcel(ms, dt);
                ms.Position = 0;

                response = new HttpResponseMessage
                {
                    Content = new StreamContent(ms)
                };

                response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                {
                    FileName = "fefef.xlsx"
                };
                response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
            }
            catch (Exception ex)
            {
                response = new HttpResponseMessage
                {
                    Content = new StringContent("Error: " + ex.Message)
                };
            }
            return(response);
        }
コード例 #3
0
 public IHttpActionResult Get()
 {
     return(Ok(_customerQueryService.GetAll()));
 }