public async Task <Guid> CreatePhoneMessage(Guid application, string from, List <string> to, string message, int status)
        {
            var result = Guid.Empty;

            var id = Guid.NewGuid();

            var entity = new Entities.PhoneMessage()
            {
                Id          = id,
                Application = application,
                From        = from,
                To          = new List <Entities.PhoneNumber>(),
                Message     = message,
                Status      = status
            };

            foreach (var i in to)
            {
                entity.To.Add(new Entities.PhoneNumber()
                {
                    PhoneMessageId = id, Number = i
                });
            }

            await db.PhoneMessages.AddAsync(entity);

            if (await db.SaveChangesAsync() > 0)
            {
                result = id;
            }

            return(result);
        }
Exemplo n.º 2
0
        public async Task <Guid> CreateEmail(Guid application, string from, List <string> to, List <string> cc, List <string> bcc, string subject, string body, bool html, int status)
        {
            var result = Guid.Empty;

            var id = Guid.NewGuid();

            var entity = new Entities.Email()
            {
                Id          = id,
                Application = application,
                From        = from,
                Subject     = subject,
                Body        = body,
                HTML        = html,
                Status      = status,
            };

            foreach (var i in to)
            {
                entity.To.Add(new Entities.EmailAddress()
                {
                    EmailId = id, Address = i
                });
            }

            foreach (var i in cc)
            {
                entity.To.Add(new Entities.EmailAddress()
                {
                    EmailId = id, Address = i, Copy = true
                });
            }

            foreach (var i in bcc)
            {
                entity.To.Add(new Entities.EmailAddress()
                {
                    EmailId = id, Address = i, Blind = true
                });
            }

            await db.Emails.AddAsync(entity);

            if (await db.SaveChangesAsync() > 0)
            {
                result = id;
            }

            return(result);
        }