Пример #1
0
        public async Task <ActionResult <AppEmail> > PostAppEmail(AppEmail appEmail)
        {
            //_appEmailService.(appEmail);
            await _appEmailService.SaveAsync();

            return(CreatedAtAction("GetAppEmail", new { id = appEmail.App_id }, appEmail));
        }
Пример #2
0
        public async Task <ActionResult <AppEmail> > PostAppEmail(AppEmail appEmail)
        {
            _context.AppEmail.Add(appEmail);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetAppEmail", new { id = appEmail.App_id }, appEmail));
        }
Пример #3
0
        public IActionResult Register([FromBody] UserDto userDto)
        {
            User user = _mapper.Map <User>(userDto);

            try
            {
                _userService.Create(user, userDto.Password);

                _logger.LogInformation($"New User #{user.Id}");

                var mailer = new AppEmail(_appSettings.SmtpServer);
                var body   = $"Для подтверждения перейдите по <a href=\"{_appSettings.ConfirmUrl}{user.Login}\">ссылке</a>";
                mailer.Send(user.Email, body, "Подтверждение регистрации", true);

                return(Ok(new
                {
                    Message = "Учетная запиь создана. Подтвердите через почту!"
                }
                          ));
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                _logger.LogCritical($"{ex}");
                return(BadRequest("Service error!"));
            }
        }
Пример #4
0
        public async Task <IActionResult> PutAppEmail(int id, AppEmail appEmail)
        {
            if (id != appEmail.App_id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #5
0
        public bool SaveWaitSendEmailData(AppEmailData email)
        {
            DateTime now = DateTime.Now;

            SqlCmdHelper.SqlRuleMapResult mapSql = new SqlCmdHelper.SqlRuleMapResult();
            //数据存储到数据表
            AppEmail ae = new AppEmail()
            {
                Body       = email.Body,
                Subject    = email.Subject,
                CreateTime = now,
                IsDelete   = false,
                ParentId   = new Guid(),
                SendBy     = email.From,
                BodyType   = (short)email.BodyType.GetHashCode()
            };

            if (email.EmailId.Equals(new Guid()))
            {
                ae.Id = Guid.NewGuid();
            }
            else
            {
                ae.Id = email.EmailId;
            }
            SqlCmdHelper help = new SqlCmdHelper()
            {
                SqlConnString = SqlConnString
            };

            help.InsertSqlParam(ae.GetInsertSql(), ae, mapSql);
            if (!email.SendTime.HasValue)
            {//这条邮件数据是此刻进行发送
                email.SendTime = now;
            }
            //进行定时计划存储
            AppEmailPlan plan = new AppEmailPlan()
            {
                CreateTime   = now,
                Id           = Guid.NewGuid(),
                PrimaryMsgId = ae.Id,
                SendNumber   = 0,
                SendTime     = email.SendTime.Value
            };

            if (plan.SendTime <= now)
            {//已发送
                plan.SendNumber = 1;
            }
            help.InsertSqlParam(plan.GetInsertSql(), plan, mapSql);
            AppEmailReceiverPlan emailTo = new AppEmailReceiverPlan()
            {
                CreateTime   = now,
                Id           = Guid.NewGuid(),
                IsMailer     = false,
                PrimaryMsgId = ae.Id,
                SendTo       = email.To
            };

            help.InsertSqlParam(emailTo.GetInsertSql(), emailTo, mapSql);
            List <AppEmailReceiverPlan> emailToColl = new List <AppEmailReceiverPlan>();

            emailToColl.Add(emailTo);
            if (email.Mailer != null)
            {
                foreach (var item in email.Mailer)
                {//抄送人
                    AppEmailReceiverPlan emailers = new AppEmailReceiverPlan()
                    {
                        IsMailer     = true,
                        SendTo       = item,
                        PrimaryMsgId = ae.Id,
                        Id           = Guid.NewGuid(),
                        CreateTime   = now
                    };
                    help.InsertSqlParam(emailers.GetInsertSql(), emailers, mapSql);
                    //emailToColl.Add(emailers);
                }
            }
            if (!string.IsNullOrEmpty(string.Join("", mapSql.NoMapRule)))
            {
                //日志输出没有匹配的规则
                return(false);
            }
            string sql = string.Join(";", mapSql.WaitExcuteSql);

            return(help.ExcuteNoQuery(sql, mapSql.SqlParams.ToArray()) == mapSql.WaitExcuteSql.Count);
        }