public bool CreateContact(ContactCreate model) { using (var ctx = new ApplicationDbContext()) { var newEntry = ctx.PersonnelDbSet.OrderByDescending(o => o.PersonnelId).FirstOrDefault(); var newId = newEntry.PersonnelId; var entity = new Contact() { PersonnelId = newId, Personnel = model.Personnel, PhoneNumber = model.PhoneNumber, PersonalEmail = model.PersonalEmail, MilEmail = model.MilEmail, HasDriversLicense = model.HasDriversLicense, VehicleMake = model.VehicleMake, VehicleModel = model.VehicleModel, VehicleColor = model.VehicleColor, VehiclePlate = model.VehiclePlate, VehicleYear = model.VehicleYear, VehicleInspected = model.VehicleInspected, CreatedBy = _userId, CreatedUtc = DateTimeOffset.Now, ModifiedLast = Guid.Empty }; ctx.ContactDbSet.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(ContactCreate model, string[] chosenInterests) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateContactService(); if (chosenInterests != null) { model.Interests = new List <InterestListItem>(); foreach (var interest in chosenInterests) { var interestToAdd = model.Interests.FirstOrDefault(i => i.Item == interest); model.Interests.Add(interestToAdd); } } if (service.CreateContact(model)) { TempData["SaveResult"] = "Contact Added."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "An error occured. Please try again."); //PopulateContactInterestData(); return(View(model)); }
public void FuryContactCreateWithPrivacy() { string expected = File.ReadAllText("FuryContactCreateCommand.xml"); var registrantContact = new Contact("agreed6", "Test Contact1", "Test Organization", "Ottawa", "123 Main Street", "ON", "K1R 7S8", "CA", "*****@*****.**", new Telephone { Value = "+1.6471114444", Extension = "333" }, new Telephone { Value = "+1.6471114445" }); //registrantContact.Password = "******"; var command = new ContactCreate(registrantContact); command.Password = "******"; var furyExtension = new FuryContactCreateExtension("EN", "CCT", null); command.Extensions.Add(furyExtension); var xml = command.ToXml().InnerXml; Assert.AreEqual(expected, xml); }
public bool CreateContact(ContactCreate model) { //var interestService = new InterestService(); var entity = new Contact() { UserId = _userId, LastName = model.LastName, FirstName = model.FirstName, Nickname = model.Nickname, Address = model.Address, PhoneNumber = model.PhoneNumber, Birthday = model.Birthday, Notes = model.Notes, CreatedUtc = DateTime.Now, //Interests = interestService.GetInterests(); }; using (var ctx = new ApplicationDbContext()) { ctx.Contacts.Add(entity); return(ctx.SaveChanges() == 1); } }
public static MappingResult Map(Dictionary <string, string> messageHeaders, byte[] crmRawMessage) { // Deserialize CRM message into RemoteExecutionContext var stream = new MemoryStream(crmRawMessage); var remoteExecutionContext = (RemoteExecutionContext) new DataContractJsonSerializer(typeof(RemoteExecutionContext)).ReadObject(stream); //Get the Entity and Action from the header in the raw CRM message from Azure. var entityName = messageHeaders["http://schemas.microsoft.com/xrm/2011/Claims/EntityLogicalName"]; var entityAction = messageHeaders["http://schemas.microsoft.com/xrm/2011/Claims/RequestName"]; var mapperTypeName = entityName.ToLower() + entityAction.ToLower(); IMessage targetMessage; switch (mapperTypeName) { case "contactcreate": targetMessage = new ContactCreate(remoteExecutionContext); break; case "contactupdate": targetMessage = new ContactUpdate(remoteExecutionContext); break; default: //if we don't have a mapper, throw this exception. It is configured as non-recoverable in the adapter endpoint and won't trigger retry. throw new MapperNotFoundException($"A mapping class is not configured for the entity {entityName} and action {entityAction}."); } // serialize the message var serializedObject = JsonConvert.SerializeObject(targetMessage); var bytes = System.Text.Encoding.UTF8.GetBytes(serializedObject); return(new MappingResult(bytes, targetMessage.GetType().FullName)); }
public async Task <IActionResult> CreateContact([FromBody] ContactCreate contactCreate) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } contactCreate.CreatedUserId = _claimsUser.UserId; var contactResult = await _contactService.CreateContact(contactCreate); if (contactResult.IsBadRequest) { return(BadRequest(contactResult.ErrorMessage)); } else if (contactResult.Data == null) { return(NotFound()); } else { var contactId = contactResult.Data.Id; return(Created(string.Format($"/contacts/{contactId}"), contactResult.Data)); } }
private static async Task<Contact> AddNewContact(Dinero dinero, ContactCreate model) { var contactCreatedResult = await dinero.Contacts.AddAsync(model); var guid = contactCreatedResult.ContactGuid; Console.WriteLine("Contact created. Name: " + model.Name + " (" + guid + ")"); return await GetContact(dinero, guid); }
public static async Task<Contact> AddNewContact(Dinero dinero) { //initalize ContactCreated with min required properties var model = new ContactCreate() { Name = GetRandomName(), CountryKey = "DK" }; return await AddNewContact(dinero, model); }
public IActionResult Post([FromBody] Contact contact) { var request = new ContactCreate(contact.Name); using (var rpcClient = new ContactRpcClient <ContactCreate, ContactCreateResponse>(_connectionFactory, _encoding)) { var response = rpcClient.RemoteCall(request); return(Ok(response.Contact)); } }
public ActionResult Create() { //var model = new ContactCreate(); //return View(model); //TODO var model = new ContactCreate(); //model.Interests = new List<InterestListItem>(); //PopulateContactInterestData(); return(View(model)); }
public static async Task<Contact> AddEanContact(Dinero dinero) { //initalize ContactCreated with min required properties var model = new ContactCreate() { Name = GetRandomName() + " Company", CountryKey = "DK", VatNumber = "12345678", EanNumber = "1234567890000", AttPerson = GetRandomName(), }; return await AddNewContact(dinero, model); }
public IHttpActionResult Post(ContactCreate contact) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateContactService(); if (!service.CreateContact(contact)) { return(InternalServerError()); } return(Ok()); }
public void PopulateContactInterestData(ContactCreate contact) { var interestSvc = new InterestService().GetInterests(); var contactInterests = new HashSet <int>(contact.Interests.Select(i => i.InterestId)); var viewModel = new List <ContactInterestData>(); //foreach (var interest in interestSvc) //{ // viewModel.Add(new ContactInterestData // { // InterestId = interest.InterestId, // Item = interest.Interest, // Chosen = contactInterests.Contains(interest.InterestId) // }); //} //ViewBag.Courses = viewModel; }
public async Task ReturnBadRequestObjectResultWhenInvalidModelState() { _sutContactsController.ModelState.AddModelError("SomeProperty", "A test error"); var contactCreate = new ContactCreate(); var result = await _sutContactsController.CreateContact(contactCreate); Assert.IsType <BadRequestObjectResult>(result); var objectResult = result as ObjectResult; Assert.NotNull(objectResult?.Value); var modelState = objectResult.Value as dynamic; Assert.True(modelState?.ContainsKey("SomeProperty")); }
private ContactCreateResponse WorkHandler(ContactCreate request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var contactId = request.CorrelationId ?? Guid.NewGuid(); var contactName = request.Name; var contact = _contactRepository.CreateContact(contactId, contactName); var response = new ContactCreateResponse(contact) { CorrelationId = request.CorrelationId }; return(response); }
public ActionResult Create(ContactCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateContactService(); if (service.CreateContact(model)) { TempData["Save Result"] = "Record created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Unable to create record."); return(View(model)); }
public bool CreateContact(ContactCreate model) { var entity = new Contact() { EmployeeId = model.EmployeeId, PhoneNumber = model.PhoneNumber, Email = model.Email, Address = model.Address }; using (var ctx = new ApplicationDbContext()) { ctx.ContactDbSet.Add(entity); return(ctx.SaveChanges() == 1); } }
public void TestContactCreateNominetPrivacyOn() { string expected = File.ReadAllText("ContactCreateCommandNominetPrivacyOn.xml"); Contact contact = new Contact("sh8013", "John Doe", "Example Inc.", "Dulles", "123 Example Dr.", "Suite 100", null, "VA", "20166-6503", "US", "*****@*****.**", new Telephone("+1.7035555555", "1234"), new Telephone("+1.7035555556", null)); contact.PostalInfo.m_type = PostalAddressType.INT; contact.DiscloseFlag = false; contact.DiscloseMask = ~Contact.DiscloseFlags.OrganizationInt & ~Contact.DiscloseFlags.AddressInt; var command = new ContactCreate(contact); command.TransactionId = "ABC-12345"; command.Password = "******"; Assert.AreEqual(expected, command.ToXml().InnerXml); }
public void GetXmlTest() { string expected = @"<?xml version=""1.0"" encoding=""utf-8""?> <function controlid=""unittest""> <create> <CONTACT> <CONTACTNAME>hello</CONTACTNAME> <PRINTAS>world</PRINTAS> </CONTACT> </create> </function>"; ContactCreate record = new ContactCreate("unittest") { ContactName = "hello", PrintAs = "world" }; this.CompareXml(expected, record); }
public ActionResult Create(ContactCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateContactService(); if (service.CreateContact(model)) { using (var ctx = new ApplicationDbContext()) { var newEntry = ctx.PersonnelDbSet.OrderByDescending(o => o.PersonnelId).FirstOrDefault(); TempData["Key Value"] = newEntry.PersonnelId; TempData["Save Result"] = "Record created."; return(RedirectToAction("CreateHousingRecord", "Record")); } } ; ModelState.AddModelError("", "Unable to create record."); return(View(model)); }
public void GetXmlTest() { string expected = @"<?xml version=""1.0"" encoding=""utf-8""?> <function controlid=""unittest""> <create> <CONTACT> <CONTACTNAME>hello</CONTACTNAME> <PRINTAS>world</PRINTAS> </CONTACT> </create> </function>"; Stream stream = new MemoryStream(); XmlWriterSettings xmlSettings = new XmlWriterSettings(); xmlSettings.Encoding = Encoding.UTF8; xmlSettings.Indent = true; xmlSettings.IndentChars = " "; IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings); ContactCreate record = new ContactCreate("unittest"); record.ContactName = "hello"; record.PrintAs = "world"; record.WriteXml(ref xml); xml.Flush(); stream.Position = 0; StreamReader reader = new StreamReader(stream); Diff xmlDiff = DiffBuilder.Compare(expected).WithTest(reader.ReadToEnd()) .WithDifferenceEvaluator(DifferenceEvaluators.Default) .Build(); Assert.IsFalse(xmlDiff.HasDifferences(), xmlDiff.ToString()); }
private void TestCreateContact() { var createContact = ContactCreate.Make("12345", "Pepe Antonio", "Example Inc.", "Toronto", "301 La Fanfan Ave.", "ON", "444mmm", "CA", "6478913606", "333", "222222344444", "CCT", "*****@*****.**", "en", "Y", "127.0.0.1", "3406310"); createContact.ToXml().Save(Console.OpenStandardOutput()); }
/// <summary> /// Synchronizes a set of employees using a connected IntacctClient /// </summary> /// <param name="client">The Client to sync to</param> /// <param name="orgemployees">Customer Data to Send</param> private async Task SyncOrgEmployees(OnlineClient client, IEnumerable <IntacctEmployee> orgemployees, PerformContext context) { IDictionary <string, string> employeemap = await GetEmployeeIds(client, context); IList <string> contactNames = await GetContacts(client, context); // Filter Existing Out if (SyncOnlyNew) { context.WriteLine("Filtering out Existing Employees"); orgemployees = orgemployees.Where(c => !contactNames.Contains(IntacctCleanString(c.EMPLOYEENAME))).ToArray(); } // Send in batches of Employees int sent = 0; int total = orgemployees.Count(); while (sent < total) { // What's in this batch var batchData = orgemployees.Skip(sent).Take(50).ToList(); context.WriteLine("Preparing Batch of 50 ({0} - {1} of {2})", sent, sent + batchData.Count, total); sent += batchData.Count; // Create the Batch for Intacct List <IFunction> batchFunctions = new List <IFunction>(); foreach (var employee in batchData) { // Process the Contact First if (contactNames.Contains(IntacctCleanString(employee.EMPLOYEENAME))) { // Update the Contact ContactUpdate update = new ContactUpdate { PrintAs = employee.EMPLOYEENAME, ContactName = IntacctCleanString(employee.EMPLOYEENAME), FirstName = employee.FIRSTNAME, LastName = employee.LASTNAME, Active = employee.EMPLOYEEACTIVE == "active", PrimaryPhoneNo = employee.PHONE, PrimaryEmailAddress = employee.EMAIL }; batchFunctions.Add(update); } else { // Create the Contact ContactCreate create = new ContactCreate { PrintAs = employee.EMPLOYEENAME, ContactName = IntacctCleanString(employee.EMPLOYEENAME), FirstName = employee.FIRSTNAME, LastName = employee.LASTNAME, Active = employee.EMPLOYEEACTIVE == "active", PrimaryPhoneNo = employee.PHONE, PrimaryEmailAddress = employee.EMAIL }; batchFunctions.Add(create); // Add to our List, so we don't update duplicates contactNames.Add(employee.EMPLOYEENAME); } // Process the Employee Now if (employeemap.ContainsKey(employee.EMPLOYEEID)) { // Update the Employee EmployeeUpdate update = new EmployeeUpdate { EmployeeId = employee.EMPLOYEEID, ContactName = IntacctCleanString(employee.EMPLOYEENAME), DepartmentId = employee.DEPARTMENTID, LocationId = employee.LOCATIONID, Active = employee.EMPLOYEEACTIVE == "active", StartDate = employee.EMPLOYEESTART, EndDate = employee.EMPLOYEETERMINATION.ToIntacctDate() }; if (!String.IsNullOrWhiteSpace(employee.PE_STAFF_CODE)) { update.CustomFields.Add("PE_STAFF_CODE", employee.PE_STAFF_CODE); } update.CustomFields.Add("RECORDNO", employeemap[employee.EMPLOYEEID]); batchFunctions.Add(update); } else { // Create the Employee EmployeeCreate create = new EmployeeCreate { EmployeeId = employee.EMPLOYEEID, ContactName = IntacctCleanString(employee.EMPLOYEENAME), DepartmentId = employee.DEPARTMENTID, LocationId = employee.LOCATIONID, Active = employee.EMPLOYEEACTIVE == "active", StartDate = employee.EMPLOYEESTART, EndDate = employee.EMPLOYEETERMINATION.ToIntacctDate() }; if (!String.IsNullOrWhiteSpace(employee.PE_STAFF_CODE)) { create.CustomFields.Add("PE_STAFF_CODE", employee.PE_STAFF_CODE); } batchFunctions.Add(create); } } // Send the Batch to Intacct context.WriteLine("Sending Batch to Intacct"); var response = await client.ExecuteBatch(batchFunctions); context.WriteLine("Inspecting Response from Intacct"); foreach (var result in response.Results) { if (result.Errors != null) { context.SetTextColor(ConsoleTextColor.Red); context.WriteLine("=================================="); foreach (var err in result.Errors) { context.WriteLine(err); } context.WriteLine("=================================="); context.WriteLine(); Console.ResetColor(); } } } }
/// <summary> /// POST api/Contacts /// Add new contact. /// </summary> public Contact Create(ContactCreate model) { return(Post <Contact, ContactCreate>(ResourceUrl, model)); }
/// <summary> /// POST api/Contacts /// Add new contact. /// </summary> public async Task <Contact> CreateAsync(ContactCreate model) { return(await PostAsync <Contact, ContactCreate>(ResourceUrl, model)); }
/// <summary> /// Add the contact to the organization's contacts. /// </summary> /// <param name="modelToCreate">The contact to be added.</param> public Task<ContactCreatedResult> AddAsync(ContactCreate modelToCreate) { if (modelToCreate == null) throw new ArgumentNullException("modelToCreate"); return PostAsync<ContactCreatedResult>(modelToCreate); }
/// <summary> /// Add the contact to the organization's contacts. /// </summary> /// <param name="modelToCreate">The contact to be added.</param> public ContactCreatedResult Add(ContactCreate modelToCreate) { return TaskHelper.ExecuteSync(() => AddAsync(modelToCreate)); }
public void TestContactCreateNominetPrivacyOff() { string expected = File.ReadAllText("ContactCreateCommandNominetPrivacyOff.xml"); Contact contact = new Contact("sh8013", "John Doe", "Example Inc.", "Dulles", "123 Example Dr.", "Suite 100", null, "VA", "20166-6503", "US", "*****@*****.**", new Telephone("+1.7035555555", "1234"), new Telephone("+1.7035555556", null)); contact.PostalInfo.m_type = PostalAddressType.INT; //Don't include a disclosure section at all contact.DiscloseFlag = null; var command = new ContactCreate(contact); command.TransactionId = "ABC-12345"; command.Password = "******"; Assert.AreEqual(expected, command.ToXml().InnerXml); }
public void TestContactCreateCommand1() { string expected = File.ReadAllText("ContactCreateCommand1.xml"); Contact contact = new Contact("sh8013", "John Doe", "Example Inc.", "Dulles", "123 Example Dr.", "Suite 100", null, "VA", "20166-6503", "US", "*****@*****.**", new Telephone("+1.7035555555", "1234"), new Telephone("+1.7035555556", null)); contact.PostalInfo.m_type = PostalAddressType.INT; contact.DiscloseFlag = false; contact.DiscloseMask = Contact.DiscloseFlags.All & ~Contact.DiscloseFlags.Email & ~Contact.DiscloseFlags.Voice; var command = new ContactCreate(contact); command.TransactionId = "ABC-12345"; command.Password = "******"; Assert.AreEqual(expected, command.ToXml().InnerXml); }