예제 #1
0
        public async Task <IActionResult> Notify(dtoNotifyS dto)
        {
            var memberCounter = dto.dtoNotify.FirstOrDefault().Member_Counter;

            bool isCheckMail = false;

            foreach (var p in dto.dtoNotify)
            {
                if (p.Mail == true)
                {
                    isCheckMail = true;
                    break;
                }
            }
            // check email format
            if (isCheckMail == true)
            {
                if (dto.MAIL == "" || dto.MAIL == null)
                {
                    return(RedirectToAction("Notify", "Account", new {
                        memberCounter = memberCounter,
                        memberEmail = "",
                        errMsg = "請輸入電子郵件"
                    }));
                }
                var s = new Tool().IsValidEmail(dto.MAIL);
                if (s == false)
                {
                    return(RedirectToAction("Notify", "Account", new {
                        memberCounter = memberCounter,
                        memberEmail = dto.MAIL,
                        errMsg = "電子郵件格式不正確"
                    }));
                }

                // 更新mail
                await this._IMembersService.SetUserMail(memberCounter, dto.MAIL);
            }

            // 更新或新增訂閱資料
            await this._INotifyService.SetNotify(dto.dtoNotify);

            // 顯示訂閱結果
            return(RedirectToAction("ShowNotify", "Account", new { memberCounter = memberCounter }));
        }
예제 #2
0
        public async Task <IActionResult> Notify(int memberCounter, string memberEmail, string errMsg = "")
        {
            var qNotify = await this._INotifyService.GetNotify(memberCounter);

            var _dtoNotifyS = new dtoNotifyS();

            _dtoNotifyS.MAIL = memberEmail;

            if (errMsg != "")
            {
                _dtoNotifyS.errMsg = errMsg;
            }
            else
            {
                _dtoNotifyS.errMsg = "";
            }

            if (qNotify.Count == 0)
            {
                // 無訂閱資料
                var q = await this._INotifyItemService.GetNotifyItem();

                List <dtoNotify> d = new List <dtoNotify> ();
                foreach (var p in q)
                {
                    var notify = new dtoNotify();
                    notify.NotifyItem_Counter = p.Counter;
                    notify.NotifyItem_Name    = p.Name;
                    notify.Member_Counter     = memberCounter;
                    notify.Line = false;
                    notify.Mail = false;

                    d.Add(notify);
                }
                _dtoNotifyS.dtoNotify = d;
            }
            else
            {
                _dtoNotifyS.dtoNotify = qNotify;
            }

            return(View(_dtoNotifyS));
        }