using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QuintoCaminoV2.Admin
{
    /// <summary>
    /// Descripción breve de FileUploadHandlerCharla
    /// </summary>
    public class FileUploadHandlerCharla : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            if (context.Request.Files.Count > 0)
            {
                HttpFileCollection files = context.Request.Files;
                for (int i = 0; i < files.Count; i++)
                {
                    HttpPostedFile file = files[i];
                    string fname = context.Server.MapPath("~/uploads/Charlas/" + file.FileName);
                    if (file.ContentType.ToString() == "video/mp4" || file.ContentType.ToString() == "video/x-msvideo" || file.ContentType.ToString() == "video/mpeg" || file.ContentType.ToString() == "video/quicktime")
                    {
                        file.SaveAs(fname);
                    }
                    else
                    {
                        context.Response.ContentType = "text/plain";
                        context.Response.Write("El formato del archivo no es correcto intente con: mp4, mpg, mpeg, avi y mov");
                    }


                }
                context.Response.ContentType = "text/plain";
                context.Response.Write("El archivo se cargo correctamente");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}