Example #1
0
 /// <summary>
 /// Create a new RiskAttachment object.
 /// </summary>
 /// <param name="attachId">Initial value of the AttachId property.</param>
 /// <param name="riskId">Initial value of the RiskId property.</param>
 /// <param name="attachName">Initial value of the AttachName property.</param>
 /// <param name="filename">Initial value of the Filename property.</param>
 /// <param name="contentType">Initial value of the ContentType property.</param>
 /// <param name="data">Initial value of the Data property.</param>
 public static RiskAttachment CreateRiskAttachment(global::System.Int32 attachId, global::System.Int32 riskId, global::System.String attachName, global::System.String filename, global::System.String contentType, global::System.Byte[] data)
 {
     RiskAttachment riskAttachment = new RiskAttachment();
     riskAttachment.AttachId = attachId;
     riskAttachment.RiskId = riskId;
     riskAttachment.AttachName = attachName;
     riskAttachment.Filename = filename;
     riskAttachment.ContentType = contentType;
     riskAttachment.Data = data;
     return riskAttachment;
 }
Example #2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the RiskAttachments EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRiskAttachments(RiskAttachment riskAttachment)
 {
     base.AddObject("RiskAttachments", riskAttachment);
 }
Example #3
0
        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);
        }