Ejemplo n.º 1
0
        public async Task AddNewsletterSubscription_ShouldNotAdd_Existing()
        {
            // Arrange
            var logMock            = new Mock <ILogger <NewsletterService> >();
            var fakeContextOptions = new DbContextOptionsBuilder <FakeNewsletterSubDbContext>()
                                     .UseInMemoryDatabase(databaseName: "AddNewsletterSubscription_ShouldNotAdd_Existing")
                                     .Options;

            using (var fakeContext = new FakeNewsletterSubDbContext(fakeContextOptions))
            {
                var service = new NewsletterService(fakeContext, logMock.Object);

                await service.AddNewsletterSubscription(_contact.Email, _newsletterSubscription.ChannelName, _contact.FirstName, _contact.LastName);
            }

            // Act
            using (var fakeContext = new FakeNewsletterSubDbContext(fakeContextOptions))
            {
                var service = new NewsletterService(fakeContext, logMock.Object);

                await service.AddNewsletterSubscription(_contact.Email, _newsletterSubscription.ChannelName, _contact.FirstName, _contact.LastName);
            }

            // Assert
            using (var fakeContext = new FakeNewsletterSubDbContext(fakeContextOptions))
            {
                Assert.AreEqual(1, fakeContext.Contacts.Count());
                Assert.AreEqual(1, fakeContext.NewsletterSubscriptions.Count());
            }
        }
Ejemplo n.º 2
0
 public NewslettersController(IFeatureRepository featureRepository, INewsletterRepository newsletterRepository, INewsletterSubscriberRepository newsletterSubscriberRepository, IBlogPostRepository blogPostRepository, IBlogRepository blogRepository, IUserRepository userRepository) :
     base(userRepository)
 {
     _blogPostRepository             = blogPostRepository;
     _newsletterSubscriberRepository = newsletterSubscriberRepository;
     _newsletterService = new NewsletterService(newsletterRepository);
     _blogRepository    = blogRepository;
 }
Ejemplo n.º 3
0
 protected override void OnCreate(Bundle savedInstanceState)
 {
     base.OnCreate(savedInstanceState);
     SetContentView(Resource.Layout.NewsletterLayout);
     FindMyViews();
     NewsletterService = new NewsletterService();
     Submit.Click     += Submit_Click;
 }
 public void TearDown()
 {
     _database             = null;
     _hostService          = null;
     _tripService          = null;
     _newsletterService    = null;
     _newsletterController = null;
 }
Ejemplo n.º 5
0
        public void ResendVerificationButton_Click(object sender, EventArgs e)
        {
            BaseCollection <NewsletterSubscriber> subscribers = BaseCollection <NewsletterSubscriber> .Get("Name = '" + TextboxEmail.Text.Trim() + "'");

            if (subscribers.Count > 0)
            {
                NewsletterService.SendVerificationEmail(subscribers[0]);
            }
        }
 public void SetUp()
 {
     _database             = new FileSystemDatabase();
     _hostService          = new HostService(_database);
     _tripService          = new TripService(_database);
     _newsletterService    = new NewsletterService(_database);
     _newsletterController = new NewsletterController(_newsletterService,
                                                      _hostService,
                                                      _tripService);
 }
        public JsonResult RemoveEmailNewsletter(string email)
        {
            if (!String.IsNullOrEmpty(email))
            {
                var deleted = new NewsletterService().RemoveEmailNewsletter(email);

                if (deleted)
                {
                    return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Success, Message = Resources.Resource.Newsletter_Signup_Unsubscribe_Successful });    
                }
            }

            return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Alert, Message = Resources.Resource.Newsletter_Signup_Unsubscribe_Error });
        }
Ejemplo n.º 8
0
        public ActionResult CadastrarNewsletter(Newsletter Newsletter)
        {
            NewsletterService newsletterService = new NewsletterService();

            try
            {
                newsletterService.CadastrarNewsletter(Newsletter);
                TempData["mensagem"] = "Cadastro realizado com sucesso";
                return(RedirectToAction("Contato"));
            } catch (Exception e)
            {
                TempData["mensagem"] = e.Message;
                return(RedirectToAction("Contato"));
            }
        }
Ejemplo n.º 9
0
        public ActionResult Excluir(string id)
        {
            NewsletterService _newsletterService = new NewsletterService();

            try
            {
                _newsletterService.ExcluirContato(id);
                TempData["mensagem"] = "Excluido com sucesso";
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                TempData["mensagem"] = e.Message;
                return(RedirectToAction("Index"));
            }
        }
Ejemplo n.º 10
0
        public void GetSubsciptionNotSubscribed()
        {
            Subscription subscription = CreateSubscriptionData("*****@*****.**");
            var          mockDbSet    = GetMockDbSet(subscription);
            var          mockContext  = new Mock <NewsletterContext>();

            mockContext.Setup(m => m.Subscriptions).Returns(mockDbSet.Object);

            SubscriptionRepository repository        = new SubscriptionRepository(mockContext.Object);
            NewsletterService      newsletterService = new NewsletterService(repository);

            SubscriptionRequest request = new SubscriptionRequest();

            request.Subscription = CreateSubscriptionData("*****@*****.**");
            SubscriptionResponse response = newsletterService.GetSubscription(request);

            Assert.AreEqual(response.Status, StatusCode.RecordNotFound);
            Assert.IsNull(response.Subscription);
        }
        public JsonResult AddEmailNewsletter(string email, string genre)
        {
            if (!String.IsNullOrWhiteSpace(email) && !String.IsNullOrWhiteSpace(genre))
            {
                var newsletter = new Newsletter {Email = email, Sexo = genre};

                var existingNewsletter = new NewsletterService().GetRecords(n => n.Email.ToLower().Equals(email.ToLower())).FirstOrDefault();

                if (existingNewsletter != null)
                {
                    return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Alert, Message = Resources.Resource.Newsletter_Signup_Subscribe_DuplicatedMail });        
                }

                new NewsletterService().InsertObject(newsletter);

                return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Success, Message = Resources.Resource.Newsletter_Signup_Subscribe_Successful});
            }

            return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Alert, Message = Resources.Resource.Newsletter_Signup_Subscribe_Error });
        }
Ejemplo n.º 12
0
        public void Unsubscribe()
        {
            Subscription subscription = CreateSubscriptionData("*****@*****.**");
            var          mockDbSet    = GetMockDbSet(subscription);
            var          mockContext  = new Mock <NewsletterContext>();

            mockContext.Setup(m => m.Subscriptions).Returns(mockDbSet.Object);

            SubscriptionRepository repository        = new SubscriptionRepository(mockContext.Object);
            NewsletterService      newsletterService = new NewsletterService(repository);

            SubscriptionRequest request = new SubscriptionRequest();

            request.Subscription = subscription;
            SubscriptionResponse response = newsletterService.Unsubscribe(request);

            mockDbSet.Verify(m => m.Remove(It.IsAny <Subscription>()), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
            Assert.AreEqual(response.Status, StatusCode.Success);
            Assert.IsNull(response.Subscription);
        }
Ejemplo n.º 13
0
        public ActionResult BuscaContato(ContatoViewModel _contatoViewModel)
        {
            Newsletter SearchParams = _contatoViewModel.Newsletter;

            if (String.IsNullOrWhiteSpace(SearchParams.Nome) && String.IsNullOrWhiteSpace(SearchParams.Email))
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                NewsletterService _newsletterService = new NewsletterService();
                try
                {
                    IList <Newsletter> ListaContatos = _newsletterService.FilterContato(_contatoViewModel.Newsletter);
                    _contatoViewModel.Newsletters = ListaContatos;
                    return(View(_contatoViewModel));
                }
                catch (Exception e)
                {
                    return(RedirectToAction("Index"));
                }
            }
        }
Ejemplo n.º 14
0
        public void SubmitButton_Click(object sender, EventArgs e)
        {
            if ((TextboxEmail.Text.Trim() != "" && BitPlate.Domain.Utils.EmailManager.isValidEmailAddress(TextboxEmail.Text.Trim())) || (TextboxEmail.Text.Trim() == "*****@*****.**"))
            {
                BaseCollection <NewsletterSubscriber> subscribers = BaseCollection <NewsletterSubscriber> .Get("Name = '" + TextboxEmail.Text.Trim() + "'");

                if (subscribers.Count > 0)
                {
                    //if (this.PanelErrorRegister != null) this.PanelErrorRegister.Visible = true;
                    this.ErrorPanel.Visible = true;
                    this.ErrorLabel.Text    = "Dit emailadres is al geabonneerd.";
                }
                else
                {
                    NewsletterSubscriber subscriber = new NewsletterSubscriber();
                    subscriber.Email       = TextboxEmail.Text.Trim();
                    subscriber.Name        = (this.TextboxName != null) ? this.TextboxName.Text : "";
                    subscriber.NamePrefix  = (this.TextboxNamePrefix != null) ? this.TextboxNamePrefix.Text : "";
                    subscriber.ForeName    = (this.TextboxForeName != null) ? this.TextboxForeName.Text : "";
                    subscriber.CompanyName = (this.TextboxCompany != null) ? this.TextboxCompany.Text : "";

                    if (RadioSexeMale != null && RadioSexeMale.Checked)
                    {
                        subscriber.Gender = BaseUser.SexeEnum.Male;
                    }

                    if (RadioSexeFemale != null && RadioSexeFemale.Checked)
                    {
                        subscriber.Gender = BaseUser.SexeEnum.Female;
                    }

                    if (RadioSexeCompany != null && RadioSexeCompany.Checked)
                    {
                        subscriber.Gender = BaseUser.SexeEnum.Company;
                    }

                    //simple user link
                    //BaseCollection<SiteUser> Users = BaseCollection<SiteUser>.Get("Email = '" + subscriber.Email + "'");
                    //if (Users.Count > 0)
                    //{
                    //    subscriber.User = Users[0];
                    //}
                    subscriber.Save();

                    foreach (NewsletterGroup group in this.NewsletterGroups.Where(c => c.IsMandatoryGroup))
                    {
                        subscriber.SubscribedGroups.Add(group);
                    }

                    foreach (ListItem li in this.NewsGroupCheckBoxList.Items)
                    {
                        if (li.Selected)
                        {
                            Guid ID;
                            Guid.TryParse(li.Value, out ID);
                            NewsletterGroup group = BaseObject.GetById <NewsletterGroup>(ID);
                            subscriber.SubscribedGroups.Add(group);
                        }
                    }

                    subscriber.Save();

                    if (subscriber.SubscribedGroups.Count > 0)
                    {
                        this.TextboxEmail.Visible = false;
                        this.LoadSettings();
                        //Koppel siteuser met subscriber (als aanwezig)
                        //SiteUser user = BaseObject.GetFirst<SiteUser>("FK_Site = '" + SessionObject.CurrentSite.ID.ToString() + "' AND Email = '" + subscriber.Email + "'");
                        //if (user != null)
                        //{
                        //    subscriber.User = user;
                        //    subscriber.Save();
                        //}

                        if (this.PanelRegisterFrom != null)
                        {
                            this.PanelRegisterFrom.Visible = false;
                        }
                        if (this.Settings.ContainsKey("SendVerifiationEmail") && (bool)this.Settings["SendVerifiationEmail"])
                        {
                            NewsletterService.SendVerificationEmail(subscriber);
                            this.LoadModuleObject();
                            //if (this.PanelVerificationRequest != null) this.PanelVerificationRequest.Visible = true;
                            this.SuccessPanel.Visible = true;
                            this.SuccessLabel.Text    = "Wij hebben u een verificatie email verstuurd. In deze email zit een link om uw emailadres te activeren.";
                        }
                        else
                        {
                            //if (this.PanelSuccessRegister != null) this.PanelSuccessRegister.Visible = true;
                            this.SuccessPanel.Visible = true;
                            this.SuccessLabel.Text    = "U ontvangt vanaf nu onze nieuwsbrief.";
                            subscriber.Confirmed      = true;
                            subscriber.Save();
                        }
                        this.HandleNavigation();
                    }
                    else
                    {
                        //if (this.PanelErrorRegister != null) this.PanelErrorRegister.Visible = true;
                        this.ErrorPanel.Visible = true;
                        this.ErrorLabel.Text    = "U heeft geen interessegebied(en) geselecteerd.";
                        subscriber.Delete();
                    }
                }
            }
            else
            {
                this.ErrorPanel.Visible = true;
                this.ErrorLabel.Text    = "Dit emailadres is ongeldig";
                //if (this.PanelErrorRegister != null) this.PanelErrorRegister.Visible = true;
            }
        }
 public void TearDown()
 {
     _database          = null;
     _newsletterService = null;
 }
Ejemplo n.º 16
0
 public NewsletterFacade(ModelStateDictionary modelState)
     : base(modelState)
 {
     serviceNewsletter = new NewsletterService();
 }
 public void SetUp()
 {
     _database          = new Mock <FileSystemDatabase>();
     _newsletterService = new NewsletterService(_database.Object);
 }
        public JsonResult FilterClients(string[] estados, string[] cidades, string[] perfis, string genre)
        {
            var listaClientes = new List<Ecommerce_Cliente>();

            if (estados != null && estados.Any())
            {
                //Se houver cidade selecionada - Traz por Cidade
                if (cidades != null && cidades.Any())
                {
                    foreach (var i in cidades)
                    {
                        var idCidade = Convert.ToInt32(i);

                        listaClientes.AddRange(new ClienteService().GetRecords(
                                c => c.Ecommerce_Cliente_Endereco.Any(ce => ce.IdCidade == idCidade)));
                    }
                }
                //Se não houver cidade selecionada - Traz apenas por estado
                else
                {
                    foreach (var i in estados)
                    {
                        var idEstado = Convert.ToInt32(i);

                        listaClientes.AddRange(new ClienteService().GetRecords(
                                c => c.Ecommerce_Cliente_Endereco.Any(ce => ce.IdEstado == idEstado)));
                    }
                }
            }else
            {
                listaClientes = new ClienteService().GetAll();
            }

            //Dentro daquela lista que o sistema já trouxe
            //faz o filtro por perfil
            if (perfis != null && perfis.Any())
            {
                var lst = new List<Ecommerce_Cliente>();

                foreach (var i in perfis)
                {
                    var idPerfil = Convert.ToInt32(i);

                    lst.AddRange(listaClientes.Where(c => c.IdPerfil == idPerfil));
                }

                listaClientes = lst;
            }

            if (genre != null && !String.IsNullOrWhiteSpace(genre))
            {
                var genreForSearch = String.Empty;

                //Se for Homem
                if (genre.Equals("1"))
                {
                    genreForSearch = "H";
                }
                //Se for Mulher
                else if (genre.Equals("2"))
                {
                    genreForSearch = "M";
                }
                //Se for todos
                else
                {
                    genreForSearch = "";
                }

                //Cria uma nova lista de Newsletter de "Não-Clientes"
                var lst = new List<Newsletter>();

                //Procura por "sexo" em especial
                if (!String.IsNullOrWhiteSpace(genreForSearch))
                {
                    lst = new NewsletterService().GetRecords(x => x.Sexo.Equals(genreForSearch));    
                }
                //Traz todos os cadastrados
                else
                {
                    lst = new NewsletterService().GetAll();
                }

                //Se houverem registros retornados do banco, gera a lista e envia o link para Download.
                if (lst.Count > 0)
                {
                    var link = GenerateFileFromSite(lst);

                    return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Success, Message = link },
                                JsonRequestBehavior.AllowGet);    
                }

            }

            if (listaClientes.Count > 0)
            {
                var link = GenerateFile(listaClientes);
                return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Success, Message = link}, JsonRequestBehavior.AllowGet);
            }

            return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Error, Message = String.Empty }, JsonRequestBehavior.AllowGet);
        }