Exemple #1
0
        public ActionResult Subscribe(SubscriptionModel model)
        {
            if (ModelState.IsValid)
            {
                SubscriptionRequest  request  = new SubscriptionRequest();
                SubscriptionResponse response = new SubscriptionResponse();

                Subscription subscription = new Subscription();
                subscription.EmailAddress     = model.EmailAddress;
                subscription.SubscriptionDate = DateTime.Now;
                subscription.MarketingSource  = MapMarketingSource(model.MarketingSource);
                subscription.Other            = model.Other;
                subscription.Reason           = model.Reason;

                request.Subscription = subscription;

                try
                {
                    response = service.GetSubscription(request);
                    if (response.Status.Equals(StatusCode.RecordNotFound))
                    {
                        response = service.Subscribe(request);
                    }

                    if (response.Status != StatusCode.Success)
                    {
                        model.Subscribed = false;
                        model.Message    = response.Message;
                        return(View("Index", model));
                    }

                    model.Subscribed = true;
                    model.Message    = response.Message;
                }
                catch (Exception ex)
                {
                    Log(ex.Message, ex.StackTrace);
                    return(View("Error"));
                }
            }

            return(View("Index", model));
        }