Esempio n. 1
0
        public JsonResult SaveFilePdf(IEnumerable <HttpPostedFileBase> attachmentPost)
        {
            int res = 0;

            foreach (var file in attachmentPost)
            {
                if (file.ContentLength > 0)
                {
                    String FileExt = Path.GetExtension(file.FileName).ToUpper();


                    if (FileExt == ".PDF")
                    {
                        //string title_temp = Convert.ToString(Request["title"]);
                        //string fileClabe = Convert.ToString(Request["fileClabe"]);
                        //string title =  fileClabe + Path.GetExtension(file.FileName);

                        string title        = file.FileName;
                        int    idAttachment = 0;

                        string _path = Path.Combine(Server.MapPath("~/UploadedFiles/attachments/"), title);
                        file.SaveAs(_path);

                        Attachment attachment = new Attachment()
                        {
                            AttachmentName      = title,
                            AttachmentDirectory = "~/UploadedFiles/attachments/" + title,
                            AttachmentActive    = "1",
                        };

                        AttachmentHelper at = new AttachmentHelper();
                        //save references attachment
                        idAttachment = at.CreateAttachment(attachment);

                        if (idAttachment == 0)
                        {
                            logger.Error("Error al intentar guardar el registro la información del documento en la db. " + Environment.NewLine + DateTime.Now);
                        }
                        if (idAttachment != 0)
                        {
                            int idTag    = Convert.ToInt32(Request["idTag"]);
                            int idParent = Convert.ToInt32(Request["idParent"]);
                            int idDepto  = Convert.ToInt32(Request["idDepto"]);

                            //create relationship
                            res = at.CreateRelationAttachment(idTag, idParent, idDepto, idAttachment);
                        }
                    }
                }
            }

            if (res == 1)
            {
                model = (SessionModel)this.Session["SessionData"];

                logger.Info("Documento guardado for username: "******"El Documento se guardo correctamente." }));
            }
            else
            {
                logger.Error("Error al intentar guardar la información del documento en la db. " + Environment.NewLine + DateTime.Now);
                return(Json(new { success = false, msgError = "La información del documento no se pudo guardar." }));
            }
        }