Example #1
0
        public void removeAttach(int attachCode)
        {
            Models.bienestarEntities db = new Models.bienestarEntities();

            Models.BE_BECA_ADJUNTO ba = db.BE_BECA_ADJUNTO.Where(a => a.CODIGO == attachCode).First();
            if (ba != null)
            {
                db.BE_BECA_ADJUNTO.DeleteObject(ba);
                db.SaveChanges();
            }
            writeResponse("ok");
        }
Example #2
0
        public void getAttach(int code)
        {
            Models.bienestarEntities db = new Models.bienestarEntities();

            Models.BE_BECA_ADJUNTO ba = db.BE_BECA_ADJUNTO.Where(a => a.CODIGO == code).First();

            byte[] response = null;

            if (ba != null && ba.ADJUNTO != null)
            {
                response = ba.ADJUNTO;
            }

            Context.Response.ContentType = ba.CONTENTTYPE;
            Context.Response.AddHeader("content-disposition", "attachment; filename=" + ba.NOMBRE);
            Context.Response.BinaryWrite(response);
            Context.Response.Flush();
            Context.Response.End();
        }
Example #3
0
        public void addUploadedFileDataBase()
        {
            Models.bienestarEntities db = new Models.bienestarEntities();

            System.Web.HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;

            int codigoSolicitud = Int32.Parse(System.Web.HttpContext.Current.Request.Params.Get("codigoSolicitud"));

            string descripcion = System.Web.HttpContext.Current.Request.Params.Get("descripcion");

            int cantidadDocSolicitados = db.BE_BECA_TIPO.Join(db.BE_BECA_TIPO_DOCUMENTO, bt => bt.CODIGO, btd => btd.CODIGOTIPO, (bt, btd) => new { bt, btd }).
                                         Join(db.BE_BECA_SOLICITUD, btbtd => btbtd.bt.CODIGO, bs => bs.CODIGOTIPO, (btbtd, bs) => new { btbtd, bs }).
                                         Where(w => w.bs.CODIGO == codigoSolicitud).Count();

            int cantidadAdjuntos = db.BE_BECA_ADJUNTO.Where(w => w.CODIGOSOLICITUD == codigoSolicitud).Count();

            // set attach if only if have files, and if attach count is more than count of document to attach
            if (hfc.Count > 0 && codigoSolicitud != 0 && cantidadAdjuntos < cantidadDocSolicitados + Utils.DOCUMENTMAXCANT)
            {
                Models.BE_BECA_ADJUNTO[] becaAdjunto = new Models.BE_BECA_ADJUNTO[hfc.Count];
                // CHECK THE FILE COUNT.
                for (int i = 0; i < hfc.Count; i++)
                {
                    System.Web.HttpPostedFile hpf = hfc[i];
                    if (hpf.ContentLength > 0)
                    {
                        // SAVE THE FILES IN THE FOLDER.
                        using (var memoryStream = new MemoryStream())
                        {
                            hpf.InputStream.CopyTo(memoryStream);
                            byte[] fileBytes = memoryStream.ToArray();

                            becaAdjunto[i] = new Models.BE_BECA_ADJUNTO();
                            becaAdjunto[i].CODIGOSOLICITUD    = codigoSolicitud;
                            becaAdjunto[i].CONTENTTYPE        = hfc[i].ContentType;
                            becaAdjunto[i].ADJUNTO            = fileBytes;
                            becaAdjunto[i].NOMBRE             = hfc[i].FileName;
                            becaAdjunto[i].DESCRIPCION        = hfc.AllKeys[i] == "documentoSolicitud" ? "Solicitud personal dirigida al Coordinador del Departamento de Bienestar Universitario" : descripcion;
                            becaAdjunto[i].DOCUMENTOSOLICITUD = hfc.AllKeys[i] == "documentoSolicitud";
                        }
                    }
                }

                int inserted = 0;
                for (int i = 0; i < becaAdjunto.Length; i++)
                {
                    if (becaAdjunto[i] != null && becaAdjunto[i].ADJUNTO != null && becaAdjunto[i].ADJUNTO.Length > 0)
                    {
                        db.BE_BECA_ADJUNTO.AddObject(becaAdjunto[i]);
                        inserted++;
                    }
                }

                if (inserted > 0)
                {
                    db.SaveChanges();
                }
            }

            var beca_solicitud = db.BE_BECA_SOLICITUD.Single(bs => bs.CODIGO == codigoSolicitud);

            writeResponseObject(new
            {
                beca_solicitud,
                System.Web.HttpContext.Current.Request.Params
            });
        }