Пример #1
0
        public static void SendMail(long memberID, string title, string body)
        {
            var com = new ComEntities();
            using (var transaction = com.Database.BeginTransaction())
            {

                //send mail
                var emailSender = new EmailSender();

                try
                {
                    string email = (from m in com.Member where m.MemberId == memberID select m.Mail).FirstOrDefault();

                    string result = emailSender.SendEmail2(email, body, title, null);

                    if (result.Equals(Constants.EMAIL_SEND))
                    {
                        List<MailDeliverCond> mailTypeList = new List<MailDeliverCond>();
                        foreach (var item in com.MailDeliverCondMaster)
                        {
                            // Set value for new row in MailDeliverCond table
                            var newMailCondRow = new MailDeliverCond
                            {
                                MemberID = memberID,
                                MailDelivCondID = item.MailDelivCondID,
                                CreatedDate = System.DateTime.Now
                            };
                            mailTypeList.Add(newMailCondRow);
                        }
                        //Insert to MailDeliverCond table
                        com.MailDeliverCond.AddRange(mailTypeList);
                        com.SaveChanges();

                    }
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                }
            }
        }
Пример #2
0
        public JsonResult SaveMailSetting(MyPageSettingViewModel.SendMailConditionInfoModel ViewModel)
        {
            Int64 memberID = GetMemberID();
            bool isResult = false;

            using (var dbContextTransaction = com.Database.BeginTransaction())
            {
                try
                {
                    if (memberID != null)
                    {
                        var del_mailstart = (from md in com.MailDeliverCond
                                             where md.MemberID == memberID && md.MailDelivCondID == 1
                                             select md).FirstOrDefault();
                        if (del_mailstart != null)
                        {
                            com.MailDeliverCond.Remove(del_mailstart);
                        }

                        var del_mailend = (from md in com.MailDeliverCond
                                           where md.MemberID == memberID && md.MailDelivCondID == 2
                                           select md).FirstOrDefault();

                        if (del_mailend != null)
                        {
                            com.MailDeliverCond.Remove(del_mailend);
                        }

                        if (ViewModel.MailSendAtStart != 0)
                        {
                            var newMailStart = new MailDeliverCond
                            {
                                MemberID = memberID,
                                MailDelivCondID = ViewModel.MailSendAtStart,
                                CreatedAccountID = memberID.ToString(),
                                CreatedDate = DateTime.Now
                            };
                            com.MailDeliverCond.Add(newMailStart);
                        }
                        if (ViewModel.MailSendAtEnd != 0)
                        {
                            var newMailEnd = new MailDeliverCond
                            {
                                MemberID = memberID,
                                MailDelivCondID = ViewModel.MailSendAtEnd,
                                CreatedAccountID = memberID.ToString(),
                                CreatedDate = DateTime.Now
                            };
                            com.MailDeliverCond.Add(newMailEnd);
                        }

                        com.SaveChanges();
                        dbContextTransaction.Commit();
                        isResult = true;
                    }
                    else
                    {
                        //Rollback transaction.
                        dbContextTransaction.Rollback();
                    }
                }
                catch (Exception)
                {
                    dbContextTransaction.Rollback();
                }
            }
            return Json(isResult, JsonRequestBehavior.AllowGet);
        }