Last active
December 6, 2017 14:54
-
-
Save Hatecat/9dd8d1c7408ff2b686e160d767bc43a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost] | |
public ActionResult Upload(HttpPostedFileBase fileData) | |
{ | |
try | |
{ | |
string[] tipoArchivo = { "image/jpeg", "image/jpg", "image/bmp", "image/png", "video/mp4", "video/x-matroska", "video/x-msvideo" }; | |
IList<String> imagenes = new List<string> | |
{ | |
"jpg", "jpeg", "bmp", "png" | |
}; | |
IList<String> videos = new List<string> | |
{ | |
"mp4", "avi", "mpeg", "mpg" | |
}; | |
if (fileData != null && (tipoArchivo.Contains(fileData.ContentType))) | |
{ | |
//var ruta = _directorioBase + fileData.FileName; | |
//fileData.SaveAs(ruta); | |
var pl = | |
ServiceFactory.Instance.PlayList().Get(fileData.FileName); | |
var ruta = _directorioBase; | |
if (pl != null) | |
{ | |
ruta += pl.NOMBRE; | |
pl.ACTIVO = 0; | |
} | |
else | |
{ | |
ruta += fileData.FileName; | |
pl = new PLAYLIST | |
{ | |
NOMBRE = fileData.FileName, | |
ACTIVO = 0, | |
FECHA = DateTime.Now.ToString(), | |
TIPO = imagenes.Contains(fileData.FileName.ToLower().Split('.').Last()) ? "IMAGEN" : | |
videos.Contains(fileData.FileName.ToLower().Split('.').Last()) ? "VIDEO" : "" | |
}; | |
} | |
fileData.SaveAs(ruta); | |
ServiceFactory.Instance.PlayList().Add(pl); | |
MensajeModel.GenerarMensaje(pl, "MEDIA"); | |
ViewBag.Exito = "Registro guardado exitosamente"; | |
return View("Index"); | |
} | |
ViewBag.Warning = "Tipo de archivo no valido"; | |
return View("Index"); | |
} | |
catch (Exception e) | |
{ | |
Log.Error("Error " + e); | |
} | |
ViewBag.Error = "Ocurrio un error al guardar, por favor intente nuevamente"; | |
return View("Index"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment