Пример #1
0
        public ActionResult InsertaComunidad(
            HttpPostedFileBase ImgDestino,
            int IdViaje,
            string sNombre,
            string sTestimonio,
            int iCalificacion
            )
        {
            byte[] baImagen = null;
            if (ImgDestino != null && ImgDestino.ContentLength > 0)
            {
                BinaryReader rdrImagen = new BinaryReader(ImgDestino.InputStream);
                baImagen = rdrImagen.ReadBytes((int)ImgDestino.ContentLength);
            }
            cmComunidad Comunidad =
                new cmComunidad
            {
                IdViaje       = IdViaje,
                sNombre       = sNombre,
                sTestimonio   = sTestimonio,
                iCalificacion = iCalificacion,
                ImgDestino    = baImagen
            };
            var                resultado       = new JObject();
            CD_Comunidad       ComunidadTravel = new CD_Comunidad();
            List <cmComunidad> ComunidadT      = new List <cmComunidad>();

            if (ComunidadTravel.bInsertaComunidad(Comunidad))
            {
                resultado["Exito"]       = true;
                ComunidadT               = ComunidadTravel.lsObtieneComunidad();
                resultado["LsComunidad"] =
                    new JArray(
                        from c in ComunidadT
                        select new JObject(
                            new JProperty("Nom", c.sNombre),
                            new JProperty("Tes", c.sTestimonio),
                            new JProperty("Cal", c.iCalificacion),
                            new JProperty("IDes", c.IdViaje),
                            new JProperty("Des", c.sDestino),
                            new JProperty("FR", c.dtFechaRegistro),
                            new JProperty("Img", Convert.ToBase64String(c.ImgDestino))
                            ));
            }
            else
            {
                resultado["Exito"] = false;
            }
            return(Content(resultado.ToString()));
        }