Example #1
0
        /// <summary>
        /// Método que guarda el formulario en la base de datos
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public HttpResponseMessage Add(DNNJuliusFormDto model)
        {
            DNNJuliusFormBusiness = new DNNJuliusFormBusiness();

            var mapp = AutoMapp <DNNJuliusFormDto, js_DNNJuliusForm> .Convert(model);

            var add = DNNJuliusFormBusiness.Add(mapp);

            if (!add.IsSuccess)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Error procesando la información, por favor inténtelo más tarde."));
            }

            model.Id = add.Result.Id;
            bool saveFileSuccess = SaveFile(model);

            if (!saveFileSuccess)
            {
                DNNJuliusFormBusiness.RollBack(add.Result);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Error subiendo los archivos al servidor."));
            }

            //var emailSuccess = DNNJuliusFormBusiness.SendEmail(model, fileSuccess);
            //if (!emailSuccess.IsSuccess)
            //    DNNJuliusFormBusiness.RollBack(add.Result);

            return(Request.CreateResponse(add.IsSuccess ? HttpStatusCode.OK : HttpStatusCode.InternalServerError, add));
        }
        /// <summary>
        /// Envía correo electrónico a el usuario
        /// </summary>
        /// <param name="PE"></param>
        public BusinessResult <bool> SendEmail(DNNJuliusFormDto PE, List <FileUploadDto> files)
        {
            try
            {
                List <Attachment> attachment = new List <Attachment>();

                string Plantilla = File.ReadAllText($"{HttpRuntime.AppDomainAppPath}{ThemeEmail}");

                Plantilla = Plantilla.Replace("{{niu}}", PE.CodigoNiu);
                Plantilla = Plantilla.Replace("{{factibilidad}}", PE.Factibilidad);
                Plantilla = Plantilla.Replace("{{observaciones}}", PE.Observaciones);

                Plantilla = Plantilla.Replace("{{strNombreUsuario}}", PE.NombreRazonSocial);
                Plantilla = Plantilla.Replace("{{nombresS}}", PE.NombreRazonSocial);
                Plantilla = Plantilla.Replace("{{tipoDocumentoS}}", PE.TipoDocumentoSolicitante);
                Plantilla = Plantilla.Replace("{{documentoIdentidadS}}", PE.DocumentoIdentidadSolicitante);
                Plantilla = Plantilla.Replace("{{direccionS}}", PE.DireccionSolicitante);
                Plantilla = Plantilla.Replace("{{municipioS}}", GetCityNameById(string.IsNullOrEmpty(PE.DepartamentoSolicitante) ? 0 : Convert.ToInt32(PE.DepartamentoSolicitante), string.IsNullOrEmpty(PE.MunicipioSolicitante) ? 0 : Convert.ToInt32(PE.MunicipioSolicitante)));
                Plantilla = Plantilla.Replace("{{DepartamentoS}}", GetDepartamentNameById(string.IsNullOrEmpty(PE.DepartamentoSolicitante) ? 0 : Convert.ToInt32(PE.DepartamentoSolicitante)));
                Plantilla = Plantilla.Replace("{{telefonoS}}", PE.TelefonoSolicitante);
                Plantilla = Plantilla.Replace("{{celularS}}", PE.CelularSolicitante);
                Plantilla = Plantilla.Replace("{{emailS}}", PE.EmailSolicitante);
                Plantilla = Plantilla.Replace("{{nombresP}}", PE.NombrePropietario);
                Plantilla = Plantilla.Replace("{{tipoDocumentoP}}", PE.TipoDocumentoPropietario);
                Plantilla = Plantilla.Replace("{{documentoIdentidadP}}", PE.DocumentoIdentidadPropietario);
                Plantilla = Plantilla.Replace("{{direccionP}}", PE.DireccionPropietario);
                Plantilla = Plantilla.Replace("{{departamentoP}}", GetDepartamentNameById(string.IsNullOrEmpty(PE.DepartamentoPropietario) ? 0 : Convert.ToInt32(PE.DepartamentoPropietario)));
                Plantilla = Plantilla.Replace("{{municipioP}}", GetCityNameById(string.IsNullOrEmpty(PE.DepartamentoPropietario) ? 0 : Convert.ToInt32(PE.DepartamentoPropietario), string.IsNullOrEmpty(PE.MunicipioPropietario) ? 0 : Convert.ToInt32(PE.MunicipioPropietario)));
                Plantilla = Plantilla.Replace("{{telefonoP}}", PE.TelefonoPropietario);
                Plantilla = Plantilla.Replace("{{celularP}}", PE.CelularPropietario);
                Plantilla = Plantilla.Replace("{{emailP}}", PE.EmailPropietario);
                Plantilla = Plantilla.Replace("{{nombreO}}", PE.NombreObra);
                Plantilla = Plantilla.Replace("{{direccionO}}", PE.DireccionObra);
                Plantilla = Plantilla.Replace("{{estratoO}}", PE.EstratoObra.ToString());
                Plantilla = Plantilla.Replace("{{nombresI}}", PE.NombreIngeniero);
                Plantilla = Plantilla.Replace("{{documentoI}}", PE.DocumentoIdentidadIngeniero);
                Plantilla = Plantilla.Replace("{{MatriculaProfesionalI}}", PE.MatriculaProfesionalIngeniero);
                Plantilla = Plantilla.Replace("{{respuesta}}", (PE.Respuesta) ? "Sí" : "No");

                Mail.SendEmail(FromEmail, FromEmail, PE.EmailSolicitante, SubjectEmail, Plantilla, attachment);

                if (files != null && files.Count > 0)
                {
                    foreach (var item in files)
                    {
                        var    read   = File.ReadAllBytes($"{HttpRuntime.AppDomainAppPath}{item.SavePath.Replace("~", "")}");
                        Stream stream = new MemoryStream(read);
                        attachment.Add(new Attachment(stream, item.fileName));
                        stream.Close();
                    }
                }

                var split = CopyEmail.Split(';');
                if (split != null && split.Count() > 0)
                {
                    foreach (var item in split)
                    {
                        Mail.SendEmail(FromEmail, FromEmail, item.Trim(), SubjectEmail, Plantilla, attachment);
                    }
                }
                return(BusinessResult <bool> .Sucess(true, string.Empty));
            }
            catch (Exception ex)
            {
                return(BusinessResult <bool> .Issue(false, string.Empty, ex));
            }
        }
Example #3
0
        /// <summary>
        /// Método que valida el tipo de documento, le hace un filtro de seguridad y lo sube al servidor
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SaveFile(DNNJuliusFormDto model)
        {
            if (model.Files != null && model.Files.Count > 0)
            {
                fileSuccess = new List <FileUploadDto>();

                foreach (var file in model.Files)
                {
                    FileUploadHandler       fileUploadHandler = new FileUploadHandler();
                    BusinessResult <string> success           = null;
                    switch (file.Source)
                    {
                    case "planos":
                        file.AllowedExtensions = new string[] { ".dwg", ".dwf", ".zip" };
                        file.SavePath          = Constants.PathPlans;
                        success       = fileUploadHandler.Upload(file);
                        file.SavePath = success.Result;
                        fileSuccess.Add(file);
                        if (!AddFileDNNJuliusForm(file.Source, success.Result, model.Id))
                        {
                            return(false);
                        }
                        break;

                    case "memorias":
                        file.AllowedExtensions = new string[] { ".xls", ".xlsx", ".docx", ".pdf", ".zip" };
                        file.SavePath          = Constants.PathMemories;
                        success       = fileUploadHandler.Upload(file);
                        file.SavePath = success.Result;
                        fileSuccess.Add(file);
                        if (!AddFileDNNJuliusForm(file.Source, success.Result, model.Id))
                        {
                            return(false);
                        }
                        break;

                    case "licencia":
                        file.AllowedExtensions = new string[] { ".pdf" };
                        file.SavePath          = Constants.PathLicense;
                        success       = fileUploadHandler.Upload(file);
                        file.SavePath = success.Result;
                        fileSuccess.Add(file);
                        if (!AddFileDNNJuliusForm(file.Source, success.Result, model.Id))
                        {
                            return(false);
                        }
                        break;

                    case "permiso":
                        file.AllowedExtensions = new string[] { ".pdf" };
                        file.SavePath          = Constants.PathPermissions;
                        success       = fileUploadHandler.Upload(file);
                        file.SavePath = success.Result;
                        fileSuccess.Add(file);
                        if (!AddFileDNNJuliusForm(file.Source, success.Result, model.Id))
                        {
                            return(false);
                        }
                        break;
                    }
                }
            }
            return(true);
        }