Advertisement
Guest User

Untitled

a guest
Dec 20th, 2017
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.55 KB | None | 0 0
  1.       /// <summary>
  2.       /// Returns an object with fields from dapper query columns
  3.       /// </summary>
  4.       /// <remarks>
  5.       /// Returns Events for SmartRoc machines
  6.       /// Returns a cursor value that keeps track of what data's been recieved
  7.       /// </remarks>
  8.       /// <param name="apiUser"></param>
  9.       /// <param name="fromId">Input cursor to get Events from MachineEventHistoryId  {fromId} + 1  to fetch <see cref="LimitOfRows"/>  number of events</param>
  10.       [HeaderAuthorizeActionFilter]
  11.       [GuidAuthorizationActionFilter]
  12.       [Route("events")]
  13.       [HttpGet]
  14.       [ResponseType(typeof(List<dynamic>))]
  15.       public HttpResponseMessage GetTrainingDataEventsSmartRoc(IUser apiUser, int fromId)
  16.       {
  17.         // var list = _certiqApiContainer.TrainingDataRepository.TrainingDataSmartRocEvents(apiUser, fromId, LimitOfRows);
  18.  
  19.          var records = new List<Record>()
  20.          {
  21.             new Record{ BirthDate = DateTime.Now, Email = "apa@hotmail.com", Name = "apa", Phone = "0704153", Tickets = 3 },
  22.             new Record{ BirthDate = DateTime.Now, Email = "apa2@hotmail.com", Name = "apa2", Phone = "0704153", Tickets = 3 },
  23.             new Record{ BirthDate = DateTime.Now, Email = "apa3@hotmail.com", Name = "apa3", Phone = "0704153", Tickets = 3 }
  24.          };
  25.  
  26.       var sb = new StringBuilder();
  27.  
  28.          sb.Append("Name,Phone,Email,Birth Date,Tickets\r\n");
  29.  
  30.          foreach (var record in records)
  31.          {
  32.             sb.AppendFormat("=\"{0}\",", record.Name);
  33.             sb.AppendFormat("=\"{0}\",", record.Phone);
  34.             sb.AppendFormat("=\"{0}\",", record.Email);
  35.             sb.AppendFormat("=\"{0}\",", record.BirthDate.ToShortDateString());
  36.             sb.AppendFormat("=\"{0}\"\r\n", record.Tickets.ToString());
  37.          }
  38.  
  39.          HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
  40.  
  41.          result.Content = new StringContent(sb.ToString());
  42.          result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
  43.          result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); //attachment will force download
  44.          result.Content.Headers.ContentDisposition.FileName = "RecordExport.csv";
  45.  
  46.          return result;
  47.  
  48.  
  49.          return null;
  50.       }
  51.    }
  52.  
  53.  
  54.  
  55.  
  56.  
  57.    public class Record
  58.    {
  59.       public string Name { get; set; }
  60.       public string Phone { get; set; }
  61.       public string Email { get; set; }
  62.       public DateTime BirthDate { get; set; }
  63.       public int Tickets { get; set; }
  64.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement