Esempio n. 1
0
        public ActionResult Attach(Guid[] attachmentIds, HttpPostedFileBase file)
        {
            try
            {
                // Get the employer.

                var employer = CurrentEmployer;

                var fileName   = Path.GetFileName(file.FileName);
                var attachment = _employerMemberContactsCommand.CreateMessageAttachment(employer, attachmentIds, new HttpPostedFileContents(file), fileName);

                // Must send text/plain mime type for legacy browsers.

                return(Json(new JsonFileModel
                {
                    Id = attachment.Id,
                    Name = fileName,
                    Size = file.ContentLength,
                }, MediaType.Text));
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            return(Json(new JsonResponseModel(), MediaType.Text));
        }
 protected MemberMessageAttachment CreateMessageAttachment(IEmployer employer, int index)
 {
     using (var stream = new MemoryStream())
     {
         using (var writer = new StreamWriter(stream))
         {
             writer.Write("This is the contents of the file.");
             stream.Position = 0;
             return(_employerMemberContactsCommand.CreateMessageAttachment(employer, new Guid[0], new StreamFileContents(stream), string.Format("FileName{0}.txt", index)));
         }
     }
 }