Exemplo n.º 1
0
        public ActionResult noviDokument(HttpPostedFileBase postedFile)
        {
            Dokumenti d = new Dokumenti();

            if (postedFile != null)
            {
                string path = Server.MapPath("~/Uploads/");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                d.naziv = postedFile.FileName;
                postedFile.SaveAs(path + Path.GetFileName(postedFile.FileName));

                d.put = path + postedFile.FileName;
            }

            if (d.naziv == null)
            {
                return(View());
            }



            baza.Dokument.Add(d);
            baza.SaveChanges();

            return(RedirectToAction("dokumenti"));
        }
Exemplo n.º 2
0
        public FileResult Download(int id)
        {
            Dokumenti dok = baza.Dokument.SingleOrDefault(s => s.id_dokument == id);

            byte[] fileBytes = System.IO.File.ReadAllBytes(dok.put);
            string fileName  = dok.naziv;

            return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName));
        }
Exemplo n.º 3
0
        public ActionResult DownloadDokumenta(int dokumentId)
        {
            Dokumenti dokument = ctx.Dokumenti.Where(x => x.Id == dokumentId).FirstOrDefault();

            if (dokument.TipDokumenta == "application/pdf")
            {
                Response.ContentType = "application/pdf";
                Response.AddHeader("Content - Disposition", "attachment; filename = " + dokument.NazivDokumenta);
                Response.OutputStream.Write(dokument.Dokument, 0, dokument.Dokument.Length);
                Response.Flush();
                return(RedirectToAction("Index", new { stavkaId = dokument.StavkaProtokolaId }));
            }
            else
            {
                return(File(dokument.Dokument, dokument.TipDokumenta, dokument.NazivDokumenta));
            }
        }
Exemplo n.º 4
0
        public ActionResult SpremiNoviDokument(DokumentiDodajVM model)
        {
            if (model.d != null)
            {
                Dokumenti dokument = new Dokumenti();
                dokument.isDeleted         = false;
                dokument.StavkaProtokolaId = model.stavkaId;
                dokument.NazivDokumenta    = model.d.FileName;
                dokument.TipDokumenta      = model.d.ContentType;
                byte[] noviDokument = new byte[model.d.ContentLength];
                model.d.InputStream.Read(noviDokument, 0, model.d.ContentLength);
                dokument.Dokument = noviDokument;
                ctx.Dokumenti.Add(dokument);
                ctx.SaveChanges();
            }

            return(RedirectToAction("Index", new { stavkaId = model.stavkaId }));
        }