//// GET: SancrisoftMails
        //public ActionResult SendMail()
        //{
        //	return View();
        //}

        // POST: SancrisoftMails
        //[HttpPost]
        public ActionResult SendMail([Bind(Include = "IdAplicante,Nombres,Apellidos,FechaNacimiento,Email,IdCargo,UrlFoto,FotoSubida")] Aplicantes aplicantes, HttpPostedFileBase fileUploader)
        {
            //	if (ModelState.IsValid)
            //	{
            string from = "*****@*****.**";                     //any valid GMail ID

            using (MailMessage mail = new MailMessage(from, aplicantes.Email))
            {
                mail.Subject = "Hemos recibido tu aplicación";
                mail.Body    = "Estimado" + ' ' + aplicantes.Nombres + ' ' + aplicantes.Apellidos;
                if (fileUploader != null)
                {
                    string fileName = Path.GetFileName(fileUploader.FileName);
                    mail.Attachments.Add(new Attachment(fileUploader.InputStream, fileName));
                }
                mail.IsBodyHtml = false;
                SmtpClient smtp = new SmtpClient();
                smtp.Host      = "smtp.gmail.com";
                smtp.EnableSsl = true;
                NetworkCredential networkCredential = new NetworkCredential(from, "ARQ6102le7");
                smtp.UseDefaultCredentials = true;
                smtp.Credentials           = networkCredential;
                smtp.Port = 587;
                smtp.Host = "localhost";
                smtp.Send(mail);
                ViewBag.Message = "Sent";
                return(View("Index", aplicantes));
            }
            //}
            //else
            //{
            //	return View();
            //}
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Aplicantes aplicantes = db.Aplicantes.Find(id);

            db.Aplicantes.Remove(aplicantes);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: Aplicantes/Create
        public ActionResult Create()
        {
            var nuevoAplicante = new Aplicantes()
            {
                FechaNacimiento = DateTime.Now
            };

            ViewBag.IdCargo = new SelectList(db.Cargos, "IdCargo", "Descripcion");
            return(View(nuevoAplicante));
        }
 public ActionResult Edit([Bind(Include = "IdAplicante,Nombres,Apellidos,IdCargo,UrlFoto")] Aplicantes aplicantes)
 {
     if (ModelState.IsValid)
     {
         db.Entry(aplicantes).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.IdCargo = new SelectList(db.Cargos, "IdCargo", "Descripcion", aplicantes.IdCargo);
     return(View(aplicantes));
 }
        // GET: Aplicantes/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Aplicantes aplicantes = db.Aplicantes.Find(id);

            if (aplicantes == null)
            {
                return(HttpNotFound());
            }
            return(View(aplicantes));
        }
        //// POST: SancrisoftMails
        ////[HttpPost]
        //public ActionResult SendMail([Bind(Include = "IdAplicante,Nombres,Apellidos,FechaNacimiento,Email,IdCargo,UrlFoto,FotoSubida")] Aplicantes aplicantes, HttpPostedFileBase fileUploader)
        //{
        //	//	if (ModelState.IsValid)
        //	//	{
        //	string from = "*****@*****.**"; //any valid GMail ID
        //	using (MailMessage mail = new MailMessage(from, aplicantes.Email))
        //	{
        //		mail.Subject = "Hemos recibido tu aplicación";
        //		mail.Body = "Estimado" + ' ' + aplicantes.Nombres + ' ' + aplicantes.Apellidos;
        //		if (fileUploader != null)
        //		{
        //			string fileName = Path.GetFileName(fileUploader.FileName);
        //			mail.Attachments.Add(new Attachment(fileUploader.InputStream, fileName));
        //		}
        //		mail.IsBodyHtml = false;
        //		SmtpClient smtp = new SmtpClient();
        //		smtp.Host = "smtp.gmail.com";
        //		smtp.EnableSsl = true;
        //		NetworkCredential networkCredential = new NetworkCredential(from, "ARQ6102le7");
        //		smtp.UseDefaultCredentials = true;
        //		smtp.Credentials = networkCredential;
        //		smtp.Port = 587;
        //		smtp.Host = "localhost";
        //		smtp.Send(mail);
        //		ViewBag.Message = "Sent";
        //		return View("Index", aplicantes);
        //	}
        //}

        // GET: Aplicantes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Aplicantes aplicantes = db.Aplicantes.Find(id);

            if (aplicantes == null)
            {
                return(HttpNotFound());
            }
            ViewBag.IdCargo = new SelectList(db.Cargos, "IdCargo", "Descripcion", aplicantes.IdCargo);
            return(View(aplicantes));
        }
        public ActionResult Create([Bind(Include = "IdAplicante,Nombres,Apellidos,FechaNacimiento,Email,IdCargo,UrlFoto,FotoSubida")] Aplicantes aplicantes)
        {
            if (ModelState.IsValid)
            {
                var guardarFoto = new GuardarFoto();

                string filename = Guid.NewGuid().ToString();

                aplicantes.UrlFoto = guardarFoto.ResizeAndSave(filename, aplicantes.FotoSubida.InputStream, Tamanos.Miniatura, false);

                db.Aplicantes.Add(aplicantes);
                db.SaveChanges();

                string from = "*****@*****.**";                 //any valid GMail ID
                using (MailMessage mail = new MailMessage(from, aplicantes.Email))
                {
                    mail.Subject = "Hemos recibido tu aplicación";
                    mail.Body    = "Estimado" + ' ' + aplicantes.Nombres + ' ' + aplicantes.Apellidos;
                    //if (fileUploader != null)
                    //{
                    //	string fileName = Path.GetFileName(fileUploader.FileName);
                    //	mail.Attachments.Add(new Attachment(fileUploader.InputStream, fileName));
                    //}
                    mail.IsBodyHtml = false;
                    SmtpClient smtp = new SmtpClient();
                    smtp.Host      = "smtp.gmail.com";
                    smtp.EnableSsl = true;
                    NetworkCredential networkCredential = new NetworkCredential(from, "ARQ6102le7");
                    smtp.UseDefaultCredentials = true;
                    smtp.Credentials           = networkCredential;
                    smtp.Port = 587;
                    //smtp.Host = "localhost";
                    smtp.Send(mail);

                    mail.Dispose();
                    smtp.Dispose();

                    ViewBag.Message = "Sent";
                    //return View("Index", aplicantes);
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.IdCargo = new SelectList(db.Cargos, "IdCargo", "Descripcion", aplicantes.IdCargo);
            return(View(aplicantes));
        }