Esempio n. 1
0
        public ActionResult Recover(string UserEmail)
        {
            string res    = "";
            bool   status = false;
            var    admUE  = (from a in ctx.Admins
                             where a.UserName == UserEmail || a.Email == UserEmail
                             select a).FirstOrDefault();

            if (admUE != null)
            {
                string recoverCode = Guid.NewGuid().ToString();
                SendVerificationCode(admUE.Email, recoverCode, "ResetPW");
                admUE.RecoverPWDCode = recoverCode;
                ctx.Configuration.ValidateOnSaveEnabled = false;
                ctx.SaveChanges();
                status = true;
                res    = "Ahora necesitamos verificar que eres tu. " +
                         "Hemos enviado el código de verificación a tu correo electrónico.";
            }
            else
            {
                res = "La cuenta no existe o no se encuentra disponible.";
            }
            ViewBag.Status = status;
            ViewBag.Msg    = res;
            return(View());
        }
Esempio n. 2
0
        public ActionResult AgregarNoticia(Noticias noti)
        {
            if (Request.Files.Count > 0)
            {
                noti.file = Request.Files[0];
            }
            else
            {
                ModelState.AddModelError("postedImg", "Debe seleccionar una imagen.");
                return(View(noti));
            }

            HttpPostedFileBase postedFile    = noti.file;
            string             fileName      = Path.GetFileName(postedFile.FileName);
            string             fileExtension = Path.GetExtension(fileName);

            if (fileExtension.ToLower() == ".jpg" || fileExtension.ToLower() == ".bpm" ||
                fileExtension.ToLower() == ".png" ||
                fileExtension.ToLower() == ".jpeg" ||
                fileExtension.ToLower() == ".tiff")
            {
                Stream       stream = postedFile.InputStream;
                BinaryReader br     = new BinaryReader(stream);
                byte[]       bytes  = br.ReadBytes((int)stream.Length);
                noti.Foto  = bytes;
                noti.Fecha = DateTime.Now;
                ctx.Configuration.ValidateOnSaveEnabled = false;
                ctx.Noticias.Add(noti);
                ctx.SaveChanges();
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                ModelState.AddModelError("postedImg", "Solo se permiten imagenes.");
                return(View(noti));
            }
        }