public ActionResult Edit(Subscriber model)
 {
     using (var context = new CustomerContainer())
     {
         var subscriber = context.Subscriber.First(s => s.Id == model.Id);
         TryUpdateModel(subscriber, new[] {"Active","Email"});
         context.SaveChanges();
         return RedirectToAction("Index");
     }
 }
Exemple #2
0
        public ActionResult Subscribe(SubscribeFormModel subscribeForm)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (var context = new CustomerContainer())
                    {
                        var subscriber = context.Subscriber.FirstOrDefault(s => s.Email == subscribeForm.SubscribeEmail);
                        if (subscriber != null)
                        {
                            subscribeForm.ErrorMessage = "Этот email уже есть в базе подписчиков";
                            return PartialView("SubscribeForm", subscribeForm);
                        }

                        subscriber = new Subscriber
                                         {
                                             Guid = Guid.NewGuid().ToString(),
                                             Email = subscribeForm.SubscribeEmail,
                                             Active = false,
                                             SentConfirmation = false
                                         };

                        context.AddToSubscriber(subscriber);




                        //string subscribeEmailFrom = ConfigurationManager.AppSettings["subscribeEmailFrom"];
                        //var emailFrom = new MailAddress(subscribeEmailFrom, "Listelli");
                        //var subscriberEmail = new MailAddress(subscriber.Email);
                        //var result = MailHelper.SendTemplate(emailFrom, new List<MailAddress> { subscriberEmail },
                        //                                             "Подтверждение регистрации", "ConfirmSubscribe.htm",
                        //                                             null, true, subscriber.Guid);

                        //if (!result.EmailSent)
                        //{
                        //    subscribeForm.ErrorMessage = "Ошибка: " + result.ErrorMessage;
                        //    return PartialView("SubscribeForm", subscribeForm);
                        //}

                        context.SaveChanges();

                        return PartialView("SubscribeSuccess");
                    }
                }
            }

            catch (Exception ex)
            {
                if (!String.IsNullOrEmpty(ex.Message))
                    subscribeForm.ErrorMessage = ex.Message;
                else if (!String.IsNullOrEmpty(ex.InnerException.Message))
                    subscribeForm.ErrorMessage = ex.InnerException.Message;
            }

            return PartialView("SubscribeForm", subscribeForm);

        }
Exemple #3
0
 /// <summary>
 /// Create a new Subscriber object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="email">Initial value of the Email property.</param>
 /// <param name="guid">Initial value of the Guid property.</param>
 /// <param name="active">Initial value of the Active property.</param>
 /// <param name="sentConfirmation">Initial value of the SentConfirmation property.</param>
 /// <param name="sentConfirmationAttempt">Initial value of the SentConfirmationAttempt property.</param>
 public static Subscriber CreateSubscriber(global::System.Int32 id, global::System.String email, global::System.String guid, global::System.Boolean active, global::System.Boolean sentConfirmation, global::System.Int32 sentConfirmationAttempt)
 {
     Subscriber subscriber = new Subscriber();
     subscriber.Id = id;
     subscriber.Email = email;
     subscriber.Guid = guid;
     subscriber.Active = active;
     subscriber.SentConfirmation = sentConfirmation;
     subscriber.SentConfirmationAttempt = sentConfirmationAttempt;
     return subscriber;
 }
Exemple #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Subscriber EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSubscriber(Subscriber subscriber)
 {
     base.AddObject("Subscriber", subscriber);
 }