Ejemplo n.º 1
0
        public IActionResult Get(int id)
        {
            Respuesta resp = new Respuesta();

            resp.status = "Error";
            resp.data   = null;
            try
            {
                using (DB_A6ED12_testmototekDBContext db = new DB_A6ED12_testmototekDBContext())
                {
                    var     idSearch = new SqlParameter("Id", id);
                    Imagene data     = db.Imagenes.FromSqlRaw("Select * from Imagenes where IdImagen = @Id", idSearch)
                                       .FirstOrDefault();
                    resp.status  = "Ok";
                    resp.message = "Success";
                    resp.data    = data;
                    return(Ok(resp));
                }
            }
            catch (Exception message)
            {
                resp.message = message.Message;
                return(BadRequest(resp));
            }
        }
 public ActionResult CreateForPublicacion(Imagene imagene)
 {
     IRepositorio<Imagene> repoImagen = new ImageneRepositorio();
     if (imagene.File != null)
     {
         imagene.DatosOriginal = ConvertFile(imagene.File);
         imagene.DatosTrans = Resize(ConvertFile(imagene.File));
         repoImagen.Save(imagene);
         return RedirectToAction("Index");
     }
     return View(imagene);
 }
Ejemplo n.º 3
0
        public IActionResult Post([FromBody] Imagene value)
        {
            Respuesta resp = new Respuesta();

            resp.status = "Error";
            resp.data   = null;
            try
            {
                using (DB_A6ED12_testmototekDBContext db = new DB_A6ED12_testmototekDBContext())
                {
                    SqlParameter[] sqlParams = new SqlParameter[]
                    {
                        new SqlParameter("@IDIMAGENES", value.PathImagen),
                        new SqlParameter("@PATHIMAGEN", value.PathImagen),
                        new SqlParameter("@FECHADECREACION", DateTime.Now),
                        new SqlParameter("@FECHADEMODIFICACION", DateTime.Now),
                    };
                    var data = db.Database.ExecuteSqlRaw("INSERT INTO [dbo].[IMAGENES] ([PathImagen],[FechaDeCreacion],[FechaDeModificacion]) VALUES (@PATHIMAGEN, @FECHADECREACION, @FECHADEMODIFICACION)", sqlParams);

                    /*
                     * SqlParameter[] sqlParamsLogs = new SqlParameter[]
                     * {
                     *  new SqlParameter("@IDUSER", "0"),
                     *  new SqlParameter("@TABLE", "IMAGENES"),
                     *  new SqlParameter("@FIELD", "AGREGO"),
                     *  new SqlParameter("@ANTERIOR", ""),
                     *  new SqlParameter("@NUEVO", ""),
                     *  new SqlParameter("@DATE", ""),
                     * };
                     * db.Database.ExecuteSqlRaw("[dbo].[sp_insertIntoLogs] @IDUSER, @TABLE, @FIELD, @ANTERIOR, @NUEVO, @DATE", sqlParamsLogs);
                     */

                    resp.status  = "Ok";
                    resp.message = "Success";
                    resp.data    = data;
                    return(Ok(resp));
                }
            }
            catch (Exception message)
            {
                resp.message = message.Message;
                return(BadRequest(resp));
            }
        }
 public ActionResult UploadForEdit(IEnumerable<HttpPostedFileBase> files)
 {
     var repoImagen = new ImageneRepositorio();
     var myImagene = new Imagene();
     if (files != null)
     {
         foreach (var miArchivo in from file in files where file != null select ConvertFile(file))
         {
             myImagene.DatosOriginal = miArchivo;
             myImagene.DatosTrans = Resize(miArchivo);
             myImagene.Tipo = "P";
             myImagene.IdPublicacion = Convert.ToInt32(Session["IdPublicacion"]);
             repoImagen.Save(myImagene);
         }
     }
     return RedirectToAction("EditForPublicacion", "Imagene", new { idPubli = Session["IdPublicacion"] });
 }
 partial void DeleteImagene(Imagene instance);
 partial void UpdateImagene(Imagene instance);
 partial void InsertImagene(Imagene instance);
        public ActionResult Edit(Patrocinante patrocinante)
        {
            patrocinante.Contacto[0].Tipo = "P";
            patrocinante.Contacto[0].IdPatrocinante = patrocinante.IdPatrocinante;
            foreach (var telefono in patrocinante.Contacto[0].ListaTelefonos)
            {
                telefono.Tipo = "P";
            }
            patrocinante.Contacto[0].IdEmpresa = null;

            IRepositorio<Imagene> repoImagen = new ImageneRepositorio();
            Imagene myImagene = new Imagene();
            if (patrocinante.File != null)
            {
                HttpFileCollectionBase files = ControllerContext.HttpContext.Request.Files;
                myImagene.DatosOriginal = ConvertFile(patrocinante.File);
                myImagene.DatosTrans = Resize(ConvertFile(patrocinante.File));
                patrocinante.Contacto[0].IdEmpresa = null;

                IList<Imagene> imagenes = repoImagen.GetAll();
                foreach (var imagene in imagenes)
                {
                    if (imagene.IdPatrocinante == patrocinante.IdPatrocinante)
                        myImagene.IdImagen = imagene.IdImagen;
                }

                var tipo = Request["Logo"] as string;
                if (tipo == "Sponsor")
                {
                    myImagene.Tipo = "S";
                }
                else
                {
                    myImagene.Tipo = "L";
                }
            }

            if (ModelState.IsValid)
            {
                IRepositorio<Patrocinante> repoPatrocinante = new PatrocinanteRepositorio();
                repoPatrocinante.Update(patrocinante);

                IRepositorio<Contacto> repoContacto = new ContactoRepositorio();
                patrocinante.Contacto[0].IdPatrocinante = patrocinante.IdPatrocinante;
                repoContacto.Update(patrocinante.Contacto[0]);

                IRepositorio<Telefono> repoTelefono = new TelefonoRepositorio();
                foreach (var telefono in patrocinante.Contacto[0].ListaTelefonos)
                {
                    telefono.IdContacto = patrocinante.Contacto[0].IdContacto;
                    repoTelefono.Save(telefono);
                }

                myImagene.IdPatrocinante = patrocinante.IdPatrocinante;
                repoImagen.Update(myImagene);

                return RedirectToAction("Index");
            }
            // Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario
            while (patrocinante.Contacto[0].ListaTelefonos.Count < 4)
            {
                patrocinante.Contacto[0].ListaTelefonos.Add(new Telefono());
            }
            return View(patrocinante);
        }