示例#1
0
        public ActionResult Approved(int CompanyId, bool IsApproved)
        {
            try
            {
                #region mail cho người dùng
                var company = _dataobject.GetById(CompanyId);
                var user    = company.UserProfile;
                //IWebHelper webhelper = new WebHelper(this.HttpContext);
                //var urlactive = Url.Action("RegisterActive").Remove(0, 1);
                //string RegisterActiveUrl = string.Format("{0}{1}?id={2}", webhelper.GetStoreLocation(), urlactive, user.UserId);
                string emailto = user.Email;

                // xử lí tạm cần dùng một mẫu tạm để gửi cho khách hàng
                #region thiết lập token
                //GlobalToken.setToken("Account.RegisterActiveURL", RegisterActiveUrl);
                GlobalToken.setToken("Account.Name", user.UserName);
                GlobalToken.setToken("SenCompany.Name", company.Name);
                #endregion

                string SenMessageTemplate_Name = "sencompany.isapproved";
                if (!IsApproved)
                {
                    SenMessageTemplate_Name = "sencompany.notapproved";
                }


                var db = new SenContext();
                var messagetemplate = db.SenMessageTemplates.SingleOrDefault(m => m.Name == SenMessageTemplate_Name && m.IsActive == true);

                var queuedemail = new WebApp.Models.SenQueuedEmail();
                queuedemail.CreatedOnUtc   = DateTime.UtcNow;
                queuedemail.EmailAccountId = messagetemplate.EmailAccountId;
                queuedemail.From           = messagetemplate.SenEmailAccount.Email;
                queuedemail.FromName       = messagetemplate.SenEmailAccount.DisplayName;
                queuedemail.Bcc            = messagetemplate.BccEmailAddresses;
                queuedemail.Subject        = GlobalToken.MappingToken(messagetemplate.Subject);
                queuedemail.To             = emailto;
                queuedemail.ToName         = user.UserName;
                queuedemail.Priority       = 0;
                queuedemail.Body           = GlobalToken.MappingToken(messagetemplate.Body);

                db.SenQueuedEmails.Add(queuedemail);
                db.SaveChanges();
                #endregion
            }
            catch (Exception ex)
            {
                return(Json(new { ketqua = ex.Message }));
            }

            return(Json(new { ketqua = "Đã email Ok." }));
        }
示例#2
0
        public ActionResult Notification(int Id)
        {
            try
            {
                #region mail cho người dùng
                var giftcard = _dataobject.GetById(Id);

                if (giftcard == null)
                {
                    throw new Exception("phải chọn thẻ");
                }
                if (giftcard.RecipientName == null)
                {
                    throw new Exception("phải nhập tên người nhận");
                }
                if (giftcard.RecipientEmail == null)
                {
                    throw new Exception("phải nhập email người nhận");
                }


                //IWebHelper webhelper = new WebHelper(this.HttpContext);
                //var urlactive = Url.Action("RegisterActive").Remove(0, 1);
                //string RegisterActiveUrl = string.Format("{0}{1}?id={2}", webhelper.GetStoreLocation(), urlactive, user.UserId);
                string emailto = giftcard.RecipientEmail;

                // xử lí tạm cần dùng một mẫu tạm để gửi cho khách hàng
                #region thiết lập token

                GlobalToken.setToken("SenGiftCard.RecipientEmail", giftcard.RecipientEmail);
                GlobalToken.setToken("SenGiftCard.RecipientName", giftcard.RecipientName);

                GlobalToken.setToken("SenGiftCard.SenderEmail", giftcard.SenderEmail);
                GlobalToken.setToken("SenGiftCard.SenderName", giftcard.SenderName);

                GlobalToken.setToken("SenGiftCard.Message", giftcard.Message);
                GlobalToken.setToken("SenGiftCard.GiftCardCouponCode", giftcard.GiftCardCouponCode);
                GlobalToken.setToken("SenGiftCard.Amount", ExConvert.Data2String(giftcard.Amount, "numeric", "n0", ""));

                #endregion

                string SenMessageTemplate_Name = "sengiftcard.notification";


                var db = new SenContext();
                var messagetemplate = db.SenMessageTemplates.SingleOrDefault(m => m.Name == SenMessageTemplate_Name && m.IsActive == true);

                var queuedemail = new WebApp.Models.SenQueuedEmail();
                queuedemail.CreatedOnUtc   = DateTime.UtcNow;
                queuedemail.EmailAccountId = messagetemplate.EmailAccountId;
                queuedemail.From           = messagetemplate.SenEmailAccount.Email;
                queuedemail.FromName       = messagetemplate.SenEmailAccount.DisplayName;
                queuedemail.Bcc            = messagetemplate.BccEmailAddresses;
                queuedemail.Subject        = GlobalToken.MappingToken(messagetemplate.Subject);
                queuedemail.To             = emailto;
                queuedemail.ToName         = giftcard.RecipientName;
                queuedemail.Priority       = 0;
                queuedemail.Body           = GlobalToken.MappingToken(messagetemplate.Body);

                db.SenQueuedEmails.Add(queuedemail);
                db.SaveChanges();
                #endregion

                giftcard.IsRecipientNotified = true;
                _dataobject.Update(giftcard);
            }
            catch (Exception ex)
            {
                return(Json(new { ketqua = ex.Message }));
            }



            return(Json(new { ketqua = "Đã email Ok." }));
        }