コード例 #1
0
ファイル: RiskController.cs プロジェクト: ryanask/MRK
        public ActionResult AttachmentNew(HttpPostedFileBase file, RiskAttachmentViewModel vm)
        {
            if (file == null || file.ContentLength == 0)
            {
                ModelState.AddModelError("", "File yang akan di-upload harus diisi");
                vm.Risk = db.Risks.Where(p => p.RiskId == vm.RiskAttachment.RiskId).FirstOrDefault();
                return View(vm);
            }
            if (ModelState.IsValid)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    file.InputStream.CopyTo(ms);
                    byte[] fileData = ms.GetBuffer();

                    var attach = new RiskAttachment();
                    attach.RiskId = vm.RiskAttachment.RiskId;
                    attach.AttachName = vm.RiskAttachment.AttachName;
                    attach.Notes = vm.RiskAttachment.Notes;
                    attach.Filename = file.FileName;
                    attach.ContentType = file.ContentType;
                    attach.ContentLength = file.ContentLength;
                    attach.Data = fileData;
                    db.RiskAttachments.AddObject(attach);
                    db.SaveChanges();
                    return RedirectToAction("AttachmentList", new { id = vm.RiskAttachment.RiskId });
                }
            }
            vm.Risk = db.Risks.Where(p => p.RiskId == vm.RiskAttachment.RiskId).FirstOrDefault();
            return View(vm);
        }
コード例 #2
0
ファイル: RiskController.cs プロジェクト: ryanask/MRK
        public ActionResult AttachmentEdit(HttpPostedFileBase file, RiskAttachmentViewModel vm)
        {
            if (ModelState.IsValid)
            {
                RiskAttachment attach = db.RiskAttachments.Where(p => p.AttachId == vm.RiskAttachment.AttachId).FirstOrDefault();
                attach.AttachName = vm.RiskAttachment.AttachName;
                attach.Notes = vm.RiskAttachment.Notes;

                if (file != null && file.ContentLength > 0)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        file.InputStream.CopyTo(ms);
                        byte[] fileData = ms.GetBuffer();
                        attach.Filename = file.FileName;
                        attach.ContentType = file.ContentType;
                        attach.ContentLength = file.ContentLength;
                        attach.Data = fileData;
                    }
                }
                db.SaveChanges();
                return RedirectToAction("AttachmentList", new { id = vm.RiskAttachment.RiskId });
            }
            return View(vm);
        }
コード例 #3
0
ファイル: RiskController.cs プロジェクト: ryanask/MRK
 public ActionResult AttachmentNew(int id)
 {
     RiskAttachmentViewModel vm = new RiskAttachmentViewModel();
     vm.Risk = db.Risks.Where(p => p.RiskId == id).FirstOrDefault();
     vm.RiskAttachment = new RiskAttachment();
     vm.RiskAttachment.RiskId = id;
     return View(vm);
 }
コード例 #4
0
ファイル: RiskController.cs プロジェクト: ryanask/MRK
 public ActionResult AttachmentEdit(int id)
 {
     RiskAttachmentViewModel vm = new RiskAttachmentViewModel();
     vm.RiskAttachment = db.RiskAttachments.Where(p => p.AttachId == id).FirstOrDefault();
     return View(vm);
 }