public void UploadFile() { if (System.Web.HttpContext.Current.Request.Files.AllKeys.Any()) { // Obtener la imagen subida var httpPostedFile = System.Web.HttpContext.Current.Request.Files["UploadedImage"]; String usuarioId = User.Identity.Name; String tienda = Session["Tienda_Nombre"].ToString(); if (httpPostedFile != null) { byte[] imageBytes = null; using (var binaryReader = new BinaryReader(httpPostedFile.InputStream)) { imageBytes = binaryReader.ReadBytes(httpPostedFile.ContentLength); } ImagenUsuario iu = new ImagenUsuario{ UsuarioID = usuarioId, Imagen = imageBytes }; //uC.EliminarImagenUsuario(usuarioId, tienda); uC.AgregarImagenUsuario(iu, tienda); } } }
//--IMAGENES-- public void AgregarImagenUsuario(ImagenUsuario iu, string idTienda) { try { chequearTienda(idTienda); using (var context = ChebayDBContext.CreateTenant(idTienda)) { var qImagen = from img in context.imagenesusuario where img.UsuarioID == iu.UsuarioID select img; if (qImagen.Count() == 0) { //Agregar Imágen context.imagenesusuario.Add(iu); context.SaveChanges(); } else { //Modificar imágen ImagenUsuario imgu = qImagen.FirstOrDefault(); imgu.Imagen = iu.Imagen; context.SaveChanges(); } } } catch (Exception e) { Debug.WriteLine(e.Message); throw e; } }