public IActionResult DeleteContact(int id) { _service = new ContactsService(); _service.DeleteContact(id); return(RedirectToAction("Index")); }
public void ShouldReturnAllContactsFromContactsRepository() { // Arrange var mockedContacts = new List <Contact> { new Contact() { SendOn = new DateTime(2017, 2, 17) }, new Contact() { SendOn = new DateTime(2017, 2, 14) }, new Contact() { SendOn = new DateTime(2017, 2, 16) }, }; var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedGenericRepository = new Mock <IGenericRepository <Contact> >(); mockedGenericRepository.Setup(gr => gr.GetAll <DateTime>(null, It.IsAny <Expression <Func <Contact, DateTime> > >())) .Returns(mockedContacts.OrderBy(s => s.SendOn)); var contactsService = new ContactsService(mockedUnitOfWork.Object, mockedGenericRepository.Object); // Act var result = contactsService.GetContacts().ToList(); // Assert Assert.AreEqual(result[0].SendOn, new DateTime(2017, 2, 17)); Assert.AreEqual(result[1].SendOn, new DateTime(2017, 2, 16)); Assert.AreEqual(result[2].SendOn, new DateTime(2017, 2, 14)); }
/// <summary> /// Authenticates the user to the Contacts API /// </summary> /// <param name="username">The user's username (e-mail)</param> /// <param name="password">The user's password</param> /// <exception cref="AuthenticationException">Thrown on invalid credentials.</exception> public void Login(string username, string password) { if (loggedIn) { throw new ApplicationException("Already logged in."); } try { this.service = new ContactsService("google-ContactsClientExample-v1.0"); ((GDataRequestFactory)this.service.RequestFactory).KeepAlive = false; this.service.setUserCredentials(username, password); this.service.QueryAuthenticationToken(); loggedIn = true; } catch (AuthenticationException e) { loggedIn = false; this.service = null; throw e; } }
protected void grdContacts_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e) { try { ContactsService contactsService = new ContactsService(SessionManager.sessionMemberInfo); int contactId = Convert.ToInt32(e.CommandArgument); switch (e.CommandName) { case "editContact": Response.Redirect(Pages.getContactsEdit(contactId), true); break; case "deleteContact": hdnContactIdToDelete.Value = contactId.ToString(); mpeDeleteContact.Show(); break; case "deactivate": contactsService.deactivateContact(contactId); searchContacts(); break; case "activate": contactsService.activateContact(contactId); searchContacts(); break; } } catch (Exception) { showError(HttpContext.GetGlobalResourceObject("Resource", "ErrorGeneral").ToString()); } }
public void PrintDateMinQueryResults(ContactsRequest cr) { Service service = new ContactsService("EventManagement"); service.setUserCredentials("*****@*****.**", "Vandematram@123"); var token = service.QueryClientLoginToken(); service.SetAuthenticationToken(token); GAuthSubRequestFactory authFactory = new GAuthSubRequestFactory("cl", "EventManagement"); authFactory.Token = (String)token; // CalendarService service2 = new CalendarService(authFactory.ApplicationName); service.RequestFactory = authFactory; ContactsQuery query = new ContactsQuery(ContactsQuery.CreateContactsUri("default")); // query.StartDate = new DateTime(2008, 1, 1); Feed <Contact> feed = cr.Get <Contact>(query); foreach (Contact contact in feed.Entries) { Console.WriteLine(contact.Name.FullName); Console.WriteLine("Updated on: " + contact.Updated.ToString()); } }
public HttpResponseMessage GetContactsByCustClientID(int clientId) { ItemsResponse <Contacts> response = new ItemsResponse <Contacts>(); response.Items = ContactsService.GetContactsByCustClientID(clientId); return(Request.CreateResponse(response)); }
public HttpResponseMessage DeleteContact(int id) { SuccessResponse response = new SuccessResponse(); ContactsService.DeleteContact(id); return(Request.CreateResponse(response)); }
public HttpResponseMessage GetContact(int id) { ItemResponse <Contacts> response = new ItemResponse <Contacts>(); response.Item = ContactsService.GetContactInfo(id); return(Request.CreateResponse(response)); }
public HttpResponseMessage GetListOfContacts() { ItemsResponse <Contacts> response = new ItemsResponse <Contacts>(); response.Items = ContactsService.GetListOfContacts(); return(Request.CreateResponse(response)); }
private static ContactsService CreateService(string username, string password, string appName) { ContactsService service = new ContactsService(appName); service.setUserCredentials(username, password); return(service); }
public static ContactList GetAddressListFromGoogle(string username, string password) { ContactList list = new ContactList(); list.Username = username; string appName = "adrianj-GoogleContactsMap-1"; ContactsService service = CreateService(username, password, appName); int contactsPerQuery = 50; int maxTotal = 32000; ContactsQuery query = new ContactsQuery(ContactsQuery.CreateContactsUri("default")); query.NumberToRetrieve = contactsPerQuery; for (int index = 0; index < maxTotal; index += contactsPerQuery) { query.StartIndex = index; ContactsFeed feed = GetContactsFeed(query, service); list.ValidCredentials = true; list.AddFromFeed(feed); if (feed.Entries.Count < contactsPerQuery) { break; } } return(list); }
public ActionResult DeleteContacts(int project, int id) { ViewBag.Projects = Projectservice.Get(); ContactsService.Delete(id); ViewBag.ProjectId = project; return(RedirectToAction("Index", new { Projects = ViewBag.ProjectId })); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>runs an authentication test</summary> ////////////////////////////////////////////////////////////////////// [Test] public void ContactsAuthenticationTest() { Tracing.TraceMsg("Entering ContactsAuthenticationTest"); ContactsQuery query = new ContactsQuery(ContactsQuery.CreateContactsUri(this.userName + "@googlemail.com")); ContactsService service = new ContactsService("unittests"); if (this.userName != null) { service.Credentials = new GDataCredentials(this.userName, this.passWord); } ContactsFeed feed = service.Query(query); ObjectModelHelper.DumpAtomObject(feed, CreateDumpFileName("ContactsAuthTest")); if (feed != null && feed.Entries.Count > 0) { Tracing.TraceMsg("Found a Feed " + feed.ToString()); foreach (ContactEntry entry in feed.Entries) { Assert.IsTrue(entry.Etag != null, "contact entries should have etags"); } } }
private void BtnDelete_Click(object sender, EventArgs e) { var confirm = new AlertDialog.Builder(this); confirm.SetMessage("Are you sure you want to delete " + selectedContacts.Count + " contacts?"); confirm.SetPositiveButton("Yes", delegate { ContactsService contactsService = new ContactsService(); Button btnDelete = FindViewById <Button>(Resource.Id.btnDelete); for (int i = 0; i < selectedContacts.Count; i++) { contactsService.Delete(selectedContacts[i]); AuthenticationService.LoggedUser.Contacts.Remove(selectedContacts[i]); } var okMessage = new AlertDialog.Builder(this); okMessage.SetMessage(selectedContacts.Count + " contacts deleted!"); okMessage.SetPositiveButton("Okay", delegate { }); okMessage.Show(); ListView listViewContacts = FindViewById <ListView>(Resource.Id.listViewContacts); listViewContacts.Adapter = RefreshAdapter(); selectedContacts.Clear(); btnDelete.Enabled = false; Recreate(); }); confirm.SetNegativeButton("No", delegate { Recreate(); }); confirm.Show(); }
public void ShouldReturnCorrectContactFromContactsRepository(int id, string expectedContactTitle) { // Arrange var mockedContacts = new List <Contact> { new Contact() { Id = 2, Title = "Really important message!" }, new Contact() { Id = 4, Title = "You want to loose weight?" } }; var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedGenericRepository = new Mock <IGenericRepository <Contact> >(); mockedGenericRepository.Setup(gr => gr.GetById(id)) .Returns(mockedContacts.Find(p => p.Id == id)); var contactsService = new ContactsService(mockedUnitOfWork.Object, mockedGenericRepository.Object); // Act var result = contactsService.GetContactById(id); // Assert Assert.AreEqual(expectedContactTitle, result.Title); }
public ActionResult Export() { ContactsService cs = new ContactsService(); cs.vCardExport(); return(this.RedirectToAction(c => c.List())); }
public JsonResult Add(int[] contactIDs, int groupID) { UnitOfWork unitOfWork = new UnitOfWork(); GroupsService groupsService = new GroupsService(unitOfWork); if (contactIDs == null) { contactIDs = new int[0]; } Group group = groupsService.GetByID(groupID); group.Contacts.Clear(); foreach (var id in contactIDs) { Contact contact = new ContactsService(unitOfWork).GetByID(id); group.Contacts.Add(contact); } groupsService.Save(group); var contacts = group.Contacts.Select(c => new { id = c.ID, firstName = c.FirstName, lastName = c.LastName }); return(Json(contacts, JsonRequestBehavior.AllowGet)); }
public JsonResult ShowCities(int countryID) { ContactsService contactsService = new ContactsService(); List <SelectListItem> cities = contactsService.GetCitiesByCountryID(countryID).ToList(); return(Json(cities.ToArray(), JsonRequestBehavior.AllowGet)); }
public ActionResult Edit(int?id) { ContactsService contactsService = new ContactsService(); ContactsEditVM model = new ContactsEditVM(); Contact contact; if (!id.HasValue) { contact = new Contact(); model.CountryID = int.Parse(contactsService.GetSelectedCountries().FirstOrDefault().Value); } else { contact = contactsService.GetByID(id.Value); if (contact == null) { return(this.RedirectToAction(c => c.List())); } model.CountryID = contact.City.CountryID; } Mapper.Map(contact, model); model.Countries = contactsService.GetSelectedCountries(); model.Cities = contactsService.GetCitiesByCountryID(model.CountryID); model.Groups = contactsService.GetSelectedGroups(contact.Groups); return(View(model)); }
public static async Task ExecuteAsync() { var client = new HttpClient(); //client.DefaultRequestVersion = new Version(2, 0); // boost a bit with http2 var service = new ContactsService(client); var contact = await service.GetContactAsync(4123); Console.WriteLine($"{contact.EmailAdress}"); var response = await service.DownloadAsync("234"); await service.UpdateContactAsync(contact); var start = DateTime.Now; var tasks = new List <Task>(); for (int i = 0; i < 500; i++) { var task = Task.Run(async() => { Console.Write(">"); var list = await service.GetAllAsync(); Console.Write("<"); }); tasks.Add(task); } ; Task.WaitAll(tasks.ToArray()); Console.WriteLine($"{DateTime.Now - start}"); }
public ContactsServiceTest() { EmailRepositoryMock = new Mock <IEmailRepository>(); PhoneRepositoryMock = new Mock <IPhoneRepository>(); LoggerMock = new Mock <ILogger <ContactsService> >(); ContactServiceUnderTest = new ContactsService(PhoneRepositoryMock.Object, EmailRepositoryMock.Object, LoggerMock.Object); }
public ActionResult SaveItem(Contacts model) { string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); int IdDC = Int32.Parse(MyModels.Decode(model.Ids, API.Models.Settings.SecretId + ControllerName).ToString()); ContactsModel data = new ContactsModel() { Item = model }; if (ModelState.IsValid) { if (model.Id == IdDC) { model.CreatedBy = int.Parse(HttpContext.Request.Headers["Id"]); model.ModifiedBy = int.Parse(HttpContext.Request.Headers["Id"]); model.CreatedDate = DateTime.ParseExact(model.CreatedDateShow, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture); ContactsService.SaveItem(model); if (model.Id > 0) { TempData["MessageSuccess"] = "Cập nhật thành công"; } else { TempData["MessageSuccess"] = "Thêm mới thành công"; } return(RedirectToAction("Index", new { @Type = model.Type, @EventId = model.EventId })); } } return(View(data)); }
public ActionResult UpdateStatus([FromQuery] string Ids, Boolean Status) { string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); Contacts item = new Contacts() { Id = Int32.Parse(MyModels.Decode(Ids, API.Models.Settings.SecretId + ControllerName).ToString()), Status = Status }; try { if (item.Id > 0) { item.CreatedBy = int.Parse(HttpContext.Request.Headers["Id"]); item.ModifiedBy = int.Parse(HttpContext.Request.Headers["Id"]); dynamic UpdateStatus = ContactsService.UpdateStatus(item); TempData["MessageSuccess"] = "Cập nhật Trạng Thái thành công"; return(Json(new MsgSuccess())); } else { TempData["MessageError"] = "Cập nhật Trạng Thái Không thành công"; return(Json(new MsgError())); } } catch { TempData["MessageSuccess"] = "Cập nhật Trạng Thái không thành công"; return(Json(new MsgError())); } }
public IActionResult SaveItem(string Id = null, int Type = 0) { ContactsModel data = new ContactsModel(); string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); int IdDC = Int32.Parse(MyModels.Decode(Id, API.Models.Settings.SecretId + ControllerName).ToString()); data.SearchData = new SearchContacts() { CurrentPage = 0, ItemsPerPage = 10, Keyword = "" }; if (IdDC == 0) { data.Item = new Contacts() { CreatedDateShow = DateTime.Now.ToString("dd/MM/yyyy HH:mm"), Type = Type }; } else { data.Item = ContactsService.GetItem(IdDC, API.Models.Settings.SecretId + ControllerName); } return(View(data)); }
public ActionResult DeleteItem(string Id) { string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); Contacts model = new Contacts() { Id = Int32.Parse(MyModels.Decode(Id, API.Models.Settings.SecretId + ControllerName).ToString()) }; try { if (model.Id > 0) { model.CreatedBy = int.Parse(HttpContext.Request.Headers["Id"]); model.ModifiedBy = int.Parse(HttpContext.Request.Headers["Id"]); ContactsService.DeleteItem(model); TempData["MessageSuccess"] = "Xóa thành công"; return(Json(new MsgSuccess())); } else { TempData["MessageError"] = "Xóa Không thành công"; return(Json(new MsgError())); } } catch { TempData["MessageSuccess"] = "Xóa không thành công"; return(Json(new MsgError())); } }
public async Task CreateMethodShouldAddCorrectNewContactFormToDb() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var dbContext = new ApplicationDbContext(optionsBuilder.Options); var contactsService = new ContactsService(dbContext); var contactFormToAdd = new ContactFormInputModel { Name = "testName", Content = "testContent", Email = "testEmail", Title = "testTitle", }; await contactsService.CreateAsync(contactFormToAdd, "ip"); Assert.NotNull(dbContext.ContactForms.FirstOrDefaultAsync()); Assert.Equal("testName", dbContext.ContactForms.FirstAsync().Result.Name); Assert.Equal("testContent", dbContext.ContactForms.FirstAsync().Result.Content); Assert.Equal("testEmail", dbContext.ContactForms.FirstAsync().Result.Email); Assert.Equal("testTitle", dbContext.ContactForms.FirstAsync().Result.Title); Assert.Equal("ip", dbContext.ContactForms.FirstAsync().Result.Ip); }
private static void Initialize() { smtp = new SmtpClient(); credential = smtp.Credentials.GetCredential(smtp.Host, smtp.Port, "Basic"); service = new ContactsService("Contacts"); service.setUserCredentials(credential.UserName, credential.Password); }
public GMailClient(string username, string password) { service = new ContactsService(GAppName); service.setUserCredentials(username, password); Contacts = Enumerable.Empty <Item> (); ServicePointManager.CertificatePolicy = new CertHandler(); }
public ContactsPage() { InitializeComponent(); _contactsService = new ContactsService(); _contacts = new ObservableCollection <Contact>(_contactsService.GetContacts()); listView.ItemsSource = _contacts; }
public void CreateNewContact() { try { ContactsService service = new ContactsService("WebGear.GoogleContactsSync"); service.setUserCredentials(ConfigurationManager.AppSettings["Gmail.Username"], ConfigurationManager.AppSettings["Gmail.Password"]); #region Delete previously created test contact. ContactsQuery query = new ContactsQuery(ContactsQuery.CreateContactsUri("default")); query.NumberToRetrieve = 500; ContactsFeed feed = service.Query(query); foreach (ContactEntry entry in feed.Entries) { if (entry.PrimaryEmail != null && entry.PrimaryEmail.Address == "*****@*****.**") { entry.Delete(); break; } } #endregion ContactEntry newEntry = new ContactEntry(); newEntry.Title.Text = "John Doe"; EMail primaryEmail = new EMail("*****@*****.**"); primaryEmail.Primary = true; primaryEmail.Rel = ContactsRelationships.IsWork; newEntry.Emails.Add(primaryEmail); PhoneNumber phoneNumber = new PhoneNumber("555-555-5551"); phoneNumber.Primary = true; phoneNumber.Rel = ContactsRelationships.IsMobile; newEntry.Phonenumbers.Add(phoneNumber); PostalAddress postalAddress = new PostalAddress(); postalAddress.Value = "123 somewhere lane"; postalAddress.Primary = true; postalAddress.Rel = ContactsRelationships.IsHome; newEntry.PostalAddresses.Add(postalAddress); newEntry.Content.Content = "Who is this guy?"; Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default")); ContactEntry createdEntry = (ContactEntry)service.Insert(feedUri, newEntry); Assert.IsNotNull(createdEntry.Id.Uri); //delete this temp contact createdEntry.Delete(); } catch (Exception ex) { } }