예제 #1
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            AnswerAttachment answerAttachment = db.AnswerAttachments.Find(id);

            db.AnswerAttachments.Remove(answerAttachment);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #2
0
 public ActionResult Edit([Bind(Include = "Id,AnswerId,Created,FileName,MimeType,Size")] AnswerAttachment answerAttachment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(answerAttachment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(answerAttachment));
 }
예제 #3
0
        public ActionResult Create([Bind(Include = "Id,AnswerId,Created,FileName,MimeType,Size")] AnswerAttachment answerAttachment)
        {
            if (ModelState.IsValid)
            {
                answerAttachment.Id = Guid.NewGuid();
                db.AnswerAttachments.Add(answerAttachment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(answerAttachment));
        }
예제 #4
0
        // GET: AnswerAttachments/Delete/5
        public ActionResult Delete(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AnswerAttachment answerAttachment = db.AnswerAttachments.Find(id);

            if (answerAttachment == null)
            {
                return(HttpNotFound());
            }
            return(View(answerAttachment));
        }
        public static List <AnswerAttachment> TransformToAnswerAttachment(int answerId, IEnumerable <HttpPostedFileBase> files)
        {
            var attachments = new List <AnswerAttachment>();

            foreach (var file in files)
            {
                if (file == null)
                {
                    continue;
                }

                Attachment attachment       = GenerateAttachment(file);
                var        answerAttachment = new AnswerAttachment(answerId, attachment);
                attachments.Add(answerAttachment);
            }

            return(attachments);
        }
        public ActionResult Attachment(int id)
        {
            AnswerAttachment img = db.AnswerAttachments.Find(id);

            return(File(img.Data, EnumDescription.Get(img.FileType)));
        }