public async Task Add_New_Records() { var autoMapperConfig = new MapperConfiguration(cfg => { cfg.AddProfile <DtoProfile>(); }); var mapper = autoMapperConfig.CreateMapper(); var options = new DbContextOptionsBuilder <AppDataContext>() .UseInMemoryDatabase(databaseName: "TestDb") .Options; using (var dataContext = new AppDataContext(options)) { var companyDs = new CompanyDataService(dataContext, mapper); var contactDs = new ContactDataService(dataContext, mapper); var service = new DataImportService(companyDs, contactDs); using (var stringReader = new StringReader(Csv_Contacts_3)) { await service.ImportContactsAsync(stringReader, 1); } var contacts = dataContext.Contacts.ToArray(); var companies = dataContext.Companies.ToArray(); Assert.True(contacts.Length == 3); Assert.True(companies.Length == 3); } }
public ActionResult EditShoppingHours() { CommonDataService cds = new CommonDataService(); CommonModel cm = new CommonModel(); cm = cds.GenerateCommonModel(); Session["FaceBook"] = cm.FaceBook; Session["Twitter"] = cm.Twitter; Session["Youtube"] = cm.Youtube; Session["Instagram"] = cm.Instagram; Session["PhoneNumber"] = cm.PhoneNumber; Session["Email"] = cm.Email; Session["ShoppingHours"] = cm.ShoppingHours; ContactDataService dataService = new ContactDataService(); try { string description = (string)Request.Form["description"]; string id = (string)Request.Form["id"]; dataService.UpdateShoppingHours(int.Parse(id), description); return(RedirectToAction("Edit", "Contact")); } catch (Exception ex) { throw ex; } finally { dataService = null; } }
public ActionResult EditSocial(int socialMediaId) { CommonDataService cds = new CommonDataService(); CommonModel cm = new CommonModel(); cm = cds.GenerateCommonModel(); Session["FaceBook"] = cm.FaceBook; Session["Twitter"] = cm.Twitter; Session["Youtube"] = cm.Youtube; Session["Instagram"] = cm.Instagram; Session["PhoneNumber"] = cm.PhoneNumber; Session["Email"] = cm.Email; Session["ShoppingHours"] = cm.ShoppingHours; try { ContactDataService dataService = new ContactDataService(); SocialMediaModel model = new SocialMediaModel(); model = dataService.GenerateSocialMediaModelById(socialMediaId); return(View(model)); } catch (Exception ex) { throw ex; } }
public ActionResult EditCompanyAddress() { CommonDataService cds = new CommonDataService(); CommonModel cm = new CommonModel(); cm = cds.GenerateCommonModel(); Session["FaceBook"] = cm.FaceBook; Session["Twitter"] = cm.Twitter; Session["Youtube"] = cm.Youtube; Session["Instagram"] = cm.Instagram; Session["PhoneNumber"] = cm.PhoneNumber; Session["Email"] = cm.Email; Session["ShoppingHours"] = cm.ShoppingHours; ContactDataService dataService = new ContactDataService(); try { string addressId = (string)Request.Form["addressId"]; string addressLine1 = (string)Request.Form["addressLine1"]; string addressLine2 = (string)Request.Form["addressLine2"]; string country = (string)Request.Form["country"]; string postCode = (string)Request.Form["postCode"]; return(RedirectToAction("Edit", "Contact")); } catch (Exception ex) { throw ex; } finally { dataService = null; } }
public async Task ShouldReturnInfo_When_Correct_Parrameters_Are_Passed() { const int contactId = 1; const string message = "message"; const string email = "*****@*****.**"; var contactInfo = new ContactInfo() { ContactInfoId = contactId, Email = email, Message = message }; var requestProviderMock = new Mock <IRequestProvider>(); requestProviderMock .Setup(e => e.PostAsync <ContactInfo>(It.IsAny <string>(), It.IsAny <ContactInfo>(), It.IsAny <string>())) .Returns(Task.FromResult <ContactInfo>(contactInfo)); var contactService = new ContactDataService(requestProviderMock.Object); var contactServiceResult = await contactService.AddContactInfoAsync(message, email); Assert.IsNotNull(contactServiceResult); Assert.AreEqual(contactId, contactServiceResult.ContactInfoId); Assert.AreEqual(message, contactServiceResult.Message); Assert.AreEqual(email, contactServiceResult.Email); }
public MainViewModel() { var dataService = new ContactDataService(); var dialogService = new DialogService(); //var dataService = new JsonContactDataService(); this.BookVM = new BookViewModel(dataService, dialogService); this.CurrentView = this.BookVM; }
public ActionResult Index() { CommonDataService cds = new CommonDataService(); CommonModel cm = new CommonModel(); cm = cds.GenerateCommonModel(); Session["FaceBook"] = cm.FaceBook; Session["Twitter"] = cm.Twitter; Session["Youtube"] = cm.Youtube; Session["Instagram"] = cm.Instagram; Session["PhoneNumber"] = cm.PhoneNumber; Session["Email"] = cm.Email; Session["ShoppingHours"] = cm.ShoppingHours; ContactDataService dataService = new ContactDataService(); try { string body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p> <br/><p>{3}</p><p>{4}</p>"; string name = (string)Request.Form["contact_name"]; string email = (string)Request.Form["contact_email"]; string company = (string)Request.Form["contact_company"]; string phone = (string)Request.Form["contact_phone"]; string subject = (string)Request.Form["contact_subject"]; string message = (string)Request.Form["contact_message"]; // Create the email object first, then add the properties. SendGridMessage myMessage = new SendGridMessage(); myMessage.AddTo(dataService.GenerateEmailAddressModelById(1).EmailAddress); myMessage.From = new MailAddress(email, name); myMessage.Subject = subject; myMessage.Html = string.Format(body, name, email, message, company, phone); // Create credentials, specifying your user name and password. var credentials = new NetworkCredential("*****@*****.**", "Passw0rd123##"); // Create an Web transport for sending email. var transportWeb = new Web(credentials); // Send the email, which returns an awaitable task. transportWeb.DeliverAsync(myMessage); return(RedirectToAction("Sent")); } catch (System.Exception ex) { throw ex; } }
public ActionResult EditContactAdditional(int contactAdditionalId) { CommonDataService cds = new CommonDataService(); CommonModel cm = new CommonModel(); cm = cds.GenerateCommonModel(); Session["FaceBook"] = cm.FaceBook; Session["Twitter"] = cm.Twitter; Session["Youtube"] = cm.Youtube; Session["Instagram"] = cm.Instagram; Session["PhoneNumber"] = cm.PhoneNumber; Session["Email"] = cm.Email; Session["ShoppingHours"] = cm.ShoppingHours; ContactDataService dataService = new ContactDataService(); try { ContactAdditionalModel model = new ContactAdditionalModel(); model = dataService.GenerateContactAdditionalModelById(1); return(View(model)); //string id = (string)Request.Form["id"]; //if (ModelState.IsValid) //{ // dataService.UpdateContactAdditional(int.Parse(id), "", model.ContactAdditionalModel.ContactDescription); // return RedirectToAction("Edit", "Contact"); //} //else //{ // model = new ContactViewModel(); // model.ContactAdditionalModel = new Models.ContactAdditionalModel(); // model.ContactAdditionalModel.ContactAdditionalId = int.Parse(id); // model.ContactAdditionalModel.ContactDescription = model.ContactAdditionalModel.ContactDescription; // return View(model.ContactAdditionalModel); //} } catch (Exception ex) { throw ex; } finally { dataService = null; } }
public async Task TakeAllAnswered_WhenThereIsNon_ShouldReturnZero() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var repository = new EfDeletableEntityRepository <ContactFormData>(new ApplicationDbContext(options)); var service = new ContactDataService(repository); var takeAll = await service.TakeAllUnAnswered <ContactFormDataView>(); var count = takeAll.Count(); Assert.Equal(0, count); }
public ActionResult Edit() { CommonDataService cds = new CommonDataService(); CommonModel cm = new CommonModel(); cm = cds.GenerateCommonModel(); Session["FaceBook"] = cm.FaceBook; Session["Twitter"] = cm.Twitter; Session["Youtube"] = cm.Youtube; Session["Instagram"] = cm.Instagram; Session["PhoneNumber"] = cm.PhoneNumber; Session["Email"] = cm.Email; Session["ShoppingHours"] = cm.ShoppingHours; ContactDataService dataService = new ContactDataService(); ContactViewModel viewModel = new ContactViewModel(); try { viewModel.ContactModel = dataService.GenerateContactModel(); viewModel.AddressModel = dataService.GenerateAddressModel(); viewModel.ContactNumbersModel1 = dataService.GenerateContactNumbersModelById(1); viewModel.ContactNumbersModel2 = dataService.GenerateContactNumbersModelById(2); viewModel.ContactNumbersModel3 = dataService.GenerateContactNumbersModelById(3); viewModel.ContactNumbersModel4 = dataService.GenerateContactNumbersModelById(4); viewModel.ContactNumbersModel5 = dataService.GenerateContactNumbersModelById(5); viewModel.EmailAddressModel = dataService.GenerateEmailAddressModelById(1); viewModel.ShoppingHoursModel = dataService.GenerateShoppingHoursModelById(1); viewModel.ContactAdditionalModel = dataService.GenerateContactAdditionalModelById(1); viewModel.SocialMediaModelFacebook = dataService.GenerateSocialMediaModelById(1); viewModel.SocialMediaModelTwitter = dataService.GenerateSocialMediaModelById(2); viewModel.SocialMediaModelYoutube = dataService.GenerateSocialMediaModelById(3); viewModel.SocialMediaModelInstagram = dataService.GenerateSocialMediaModelById(4); return(View(viewModel)); } catch (Exception ex) { throw ex; } finally { dataService = null; viewModel = null; } }
public ActionResult EditSocial(SocialMediaModel model) { CommonDataService cds = new CommonDataService(); CommonModel cm = new CommonModel(); cm = cds.GenerateCommonModel(); Session["FaceBook"] = cm.FaceBook; Session["Twitter"] = cm.Twitter; Session["Youtube"] = cm.Youtube; Session["Instagram"] = cm.Instagram; Session["PhoneNumber"] = cm.PhoneNumber; Session["Email"] = cm.Email; Session["ShoppingHours"] = cm.ShoppingHours; ContactDataService dataService = new ContactDataService(); try { string id = (string)Request.Form["id"]; if (ModelState.IsValid) { dataService.UpdateSocialMedia(int.Parse(id), model.SocialMediaUrl); return(RedirectToAction("Edit", "Contact")); } else { model = new SocialMediaModel(); model.SocialMediaId = int.Parse(id); model.SocialMediaUrl = model.SocialMediaUrl; return(View(model)); } } catch (Exception ex) { throw ex; } finally { dataService = null; } }
public async Task TakeAllAnswered_ShouldReturnAllUnAnsweredQuestions() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var repository = new EfDeletableEntityRepository <ContactFormData>(new ApplicationDbContext(options)); var service = new ContactDataService(repository); var form = await this.CreateContactForm("Pesho", "*****@*****.**", "Test", "Test", true, repository); var form2 = await this.CreateContactForm("Pesho2", "*****@*****.**", "Test2", "Test2", false, repository); var form3 = await this.CreateContactForm("Pesho2", "*****@*****.**", "Test2", "Test2", false, repository); var takeAll = await service.TakeAllAnswered <ContactFormDataView>(); var count = takeAll.Count(); Assert.Equal(1, count); }
public async Task MoveToAnswered_ShouldMoveUnAnsweredQuestionToAnswered() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var repository = new EfDeletableEntityRepository <ContactFormData>(new ApplicationDbContext(options)); var service = new ContactDataService(repository); var form = await this.CreateContactForm("Pesho", "*****@*****.**", "Test", "Test", true, repository); var form2 = await this.CreateContactForm("Pesho2", "*****@*****.**", "Test2", "Test2", false, repository); var form3 = await this.CreateContactForm("Pesho2", "*****@*****.**", "Test2", "Test2", false, repository); var formIdToString = form2.ToString(); await service.MoveToAnswered(formIdToString); var check = await repository.AllWithDeleted().Where(x => x.Id == form2 && x.IsDeleted).FirstOrDefaultAsync(); Assert.NotNull(check); }
public void Throws_When_Message_Is_Invalid(string message) { const int contactId = 1; const string email = "*****@*****.**"; var contactInfo = new ContactInfo() { ContactInfoId = contactId, Email = email, Message = message }; var requestProviderMock = new Mock <IRequestProvider>(); requestProviderMock .Setup(e => e.PostAsync <ContactInfo>(It.IsAny <string>(), It.IsAny <ContactInfo>(), It.IsAny <string>())) .Returns(Task.FromResult <ContactInfo>(contactInfo)); var contactService = new ContactDataService(requestProviderMock.Object); Assert.ThrowsAsync <ContactDataException>( async() => await contactService.AddContactInfoAsync(message, email)); }
public async Task Execute(string csvPath, int userId, string dbProviderName, string connectionString) { // DB Context var optionsBuilder = new DbContextOptionsBuilder <AppDataContext>(); optionsBuilder.ConfigureDbContext(dbProviderName, connectionString); // Automapper var autoMapperConfig = new MapperConfiguration(cfg => { cfg.AddProfile <DtoProfile>(); }); var mapper = autoMapperConfig.CreateMapper(); // Start execution using (var dbContext = new AppDataContext(optionsBuilder.Options)) { var companyDataService = new CompanyDataService(dbContext, mapper); var contactDataService = new ContactDataService(dbContext, mapper); var dataImportService = new DataImportService(companyDataService, contactDataService); Console.WriteLine("Importing data..."); await ImportContactsAsync(dataImportService, csvPath, userId); Console.WriteLine("Done"); } }