Exemplo n.º 1
0
        public async Task <ActionResult> Send(int?id, string Error)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            correos correos = await db.correos.FindAsync(id);

            var tablas = db.correos_reglas.Where(m => m.EsRegla == false).GroupBy(m => m.Tabla).ToList();
            List <correos_reglas> enumCR = new List <correos_reglas>();

            foreach (IGrouping <string, correos_reglas> g in tablas)
            {
                correos_reglas cr = new correos_reglas();
                cr.Nombre = g.ToList().First().Nombre;
                cr.Tabla  = g.Key;
                enumCR.Add(cr);
            }

            ViewBag.tablas = enumCR;

            if (correos == null)
            {
                return(HttpNotFound());
            }
            if (Error != null)
            {
                ViewBag.errorMessage = Error;
            }
            ViewBag.From = SessionPersister.NombreCliente;
            return(View(correos));
        }
Exemplo n.º 2
0
        // GET: Correos/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            correos correos = await db.correos.FindAsync(id);

            if (correos == null)
            {
                return(HttpNotFound());
            }
            return(View(correos));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Edit(correos correos)
        {
            correos.UpdatedAt = CurrentDate.getNow();
            correos.UpdatedBy = SessionPersister.UserId;

            if (ModelState.IsValid)
            {
                db.Entry(correos).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(correos));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Create(correos correos)
        {
            correos.CreatedAt = CurrentDate.getNow();
            correos.CreatedBy = SessionPersister.UserId;
            correos.UpdatedAt = CurrentDate.getNow();
            correos.UpdatedBy = SessionPersister.UserId;

            if (ModelState.IsValid)
            {
                db.correos.Add(correos);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(correos));
        }
Exemplo n.º 5
0
        public ActionResult Send(correos correos)
        {
            List <string> mails = Newtonsoft.Json.JsonConvert.DeserializeObject <List <string> >(correos.To);

            if (Request.Files[0].ContentLength > 0)
            {
                List <MailFile> mailAttachments = new List <MailFile>();
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    HttpPostedFileBase file = Request.Files[i] as HttpPostedFileBase;

                    byte[] fileB = new byte[file.ContentLength];

                    using (Stream s = file.InputStream)
                    {
                        s.Position = 0;
                        s.Read(fileB, 0, (int)s.Length);
                    }

                    MailFile mf = new MailFile(
                        Name: file.FileName,
                        FileBytes: fileB,
                        FileType: file.ContentType);
                    mailAttachments.Add(mf);
                }

                bool sent = Mail.SendWithAttachments(mails, correos.Asunto, correos.Contenido, mailAttachments);

                if (sent)
                {
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                bool sent = Mail.Send(mails, correos.Asunto, correos.Contenido);

                if (sent)
                {
                    return(RedirectToAction("Index"));
                }
            }

            return(RedirectToAction("Send", new { id = correos.Id, Error = "No se pudo enviar correo, intente de nuevo mas tarde." }));
        }