Esempio n. 1
0
        public IHttpActionResult getimages([FromBody] string[] subidas)
        {
            List <files> lsMostrar = new List <files>();
            var          response  = new MyReponse();

            try
            {
                foreach (var id in subidas)
                {
                    int   idConvertido = Convert.ToInt32(id);
                    files f            = db.files.Where(x => x.Id == idConvertido).FirstOrDefault();
                    lsMostrar.Add(f);
                }
            }
            catch (Exception e)
            {
                Console.Write(e.Message, e.InnerException);
            }
            return(Ok(lsMostrar));
        }
Esempio n. 2
0
        public IHttpActionResult getByEquipo(int id)
        {
            var response = new MyReponse();

            try
            {
                var img = db.files.Where(x => x.Id == id).FirstOrDefault();

                Images image = new Images();
                image.Id        = img.Id;
                image.FileName  = img.FileName;
                image.ThumbPath = img.ThumbPath;
                image.ImagePath = img.ImagePath;
                image.SectionId = img.SectionId;
                return(Ok(image));
            }
            catch (Exception e)
            {
                Console.Write(e.Message, e.InnerException);
                return(BadRequest());
            }
        }
Esempio n. 3
0
        public async Task <HttpResponseMessage> Upload(string projectId, string sectionId)
        {
            var status = new MyReponse();

            try
            {
                var context = HttpContext.Current.Request;
                if (context.Files.Count > 0)
                {
                    var filesReadToProvider = await Request.Content.ReadAsMultipartAsync();

                    var index = 0;
                    foreach (var streamContent in filesReadToProvider.Contents)
                    {
                        var fileBytes = await streamContent.ReadAsByteArrayAsync();

                        var file = new files();
                        file.ProjectId = projectId;
                        file.SectionId = sectionId;
                        file.FileName  = context.Files[index].FileName;
                        file.FileSize  = fileBytes.Length;
                        file.ImagePath = String.Format("/UploadedFiles/{0}_{1}_{2}", projectId, sectionId, file.FileName);
                        file.ThumbPath = String.Format("/UploadedFiles/{0}_{1}_th_{2}", projectId, sectionId, file.FileName);
                        var img = Image.FromStream(new System.IO.MemoryStream(fileBytes));
                        status.subidas.Add(await SaveFiles(file, img));
                        index++;
                    }
                    status.Status  = true;
                    status.Message = "File uploaded successfully";
                    return(Request.CreateResponse(HttpStatusCode.OK, status));
                }
            }
            catch (Exception ex)
            {
                status.Message = ex.Message;
            }
            return(Request.CreateResponse(HttpStatusCode.OK, status));
        }
Esempio n. 4
0
        public IHttpActionResult getbytorneo(int id)
        {
            var           response = new MyReponse();
            List <Images> lsImages = new List <Images>();

            try
            {
                var imgs = (from tImages in db.files
                            join tEquipos in db.equipos on tImages.Id equals tEquipos.logo
                            where tEquipos.id_torneo == id
                            select new
                {
                    idImg = tImages.Id,
                    fileName = tImages.FileName,
                    thumbPath = tImages.ThumbPath,
                    imagePath = tImages.ImagePath,
                    sectionId = tImages.SectionId
                });

                foreach (var i in imgs)
                {
                    Images img = new Images();
                    img.Id        = i.idImg;
                    img.FileName  = i.fileName;
                    img.ThumbPath = i.thumbPath;
                    img.ImagePath = i.imagePath;
                    img.SectionId = i.sectionId;
                    lsImages.Add(img);
                }
                return(Ok(lsImages));
            }
            catch (Exception e)
            {
                Console.Write(e.Message, e.InnerException);
                return(BadRequest());
            }
        }