Пример #1
0
        private async Task <IActionResult> ExportPoints <T>(int groupid) where T : class
        {
            try

            {
                using (NHibernate.IStatelessSession session = sessionFactory.OpenStatelessSession())
                {
                    //DigitalOutputGroup s;s.
                    var @object = await session.CreateCriteria <T>().Add(Restrictions.Eq("Groupid", groupid)).ListAsync <T>();

                    if (@object == null || @object.Count == 0)
                    {
                        return(BadRequest(ApiResult.BadRequest($"대상 GROUP ID {groupid}가 존재하지 않습니다")));
                    }

                    byte[] data     = ExportCSVFormat <T>(@object);
                    string filename = $"{typeof(T).Name}.csv";

                    System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
                    {
                        FileName = Uri.EscapeUriString(filename),
                        Inline   = false // false = prompt the user for downloading;  true = browser to try to show the file inline
                    };
                    Response.Headers.Add("Content-Disposition", cd.ToString());
                    Response.Headers.Add("X-Content-Type-Options", "nosniff");
                    return(File(data, "application/octet-stream"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ApiResult.BadRequest(ex.Message)));
            }
        }
Пример #2
0
 public StatelessSessionWrapper(NHibernate.IStatelessSession s)
 {
     session = s;
 }