Esempio n. 1
0
        public async Task <IActionResult> PutMails(int id, Mails mails)
        {
            if (id != mails.Id)
            {
                return(BadRequest());
            }

            _context.Entry(mails).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MailsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <Mail> > Post(Mail mail)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            mail.CreateDate    = DateTime.UtcNow.ToUniversalTime();
            mail.Result        = "Ok";
            mail.FailedMessage = "";
            mail.Recipients    = mail.Recipients.Replace(" ", "");

            /// <value> Recipients должно содержать строку с адресами разделенными ',' </value>
            /// <example>[email protected],[email protected]</example>
            List <string> Recipients = mail.Recipients.Split(',').ToList();

            try
            {
                await Sender.SendAsync(Recipients, mail.Subject, mail.Body);
            }
            catch (Exception ex)
            {
                mail.FailedMessage = ex.Message;
                mail.Result        = "Failed";
            }

            db.Mails.Add(mail);
            await db.SaveChangesAsync();

            return(Ok(mail));
        }