Exemple #1
0
        public ActionResult Create([Bind(Include = "ProblemID,Title,ProblemDescription")] ProblemsData problemsData, HttpPostedFileBase filePosted)
        {
            //AttachmentsBusinessModel fileDownload = new AttachmentsBusinessModel();
            AttachmentsBusinessModel fileUpload = new AttachmentsBusinessModel();

            if (ModelState.IsValid)
            {
                problemsData.UserName    = User.Identity.Name;
                problemsData.DateAndTime = DateTime.Now;
                if (problemsData.Title == null)
                {
                    problemsData.Title = "Empty";
                }
                if (problemsData.ProblemDescription == null)
                {
                    problemsData.ProblemDescription = "Empty";
                }
                db.ProblemsDatas.Add(problemsData);
                db.SaveChanges();

                fileUpload.attachment.UserName  = User.Identity.Name;
                fileUpload.attachment.ProblemID = problemsData.ProblemID;
                fileUpload.uploadData(filePosted);

                return(RedirectToAction("Index"));
            }
            return(View(problemsData));
        }
Exemple #2
0
        public ActionResult Download(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Attachment attachment = db.Attachments.Find(id);
            AttachmentsBusinessModel fileDownload = new AttachmentsBusinessModel();

            if (attachment == null)
            {
                return(HttpNotFound());
            }

            fileDownload.DownloadFile(attachment.FileID);
            Response.Clear();
            Response.Buffer  = true;
            Response.Charset = "";
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = fileDownload.attachment.ContentType;
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileDownload.attachment.FileName);
            Response.BinaryWrite(fileDownload.attachment.Data);
            Response.Flush();
            Response.End();
            return(View());
        }