/// <summary>
        ///
        /// </summary>
        /// <param name="UserDefinedField"></param>
        /// <returns>The name of the newly created field</returns>
        public string CreateUserDefinedField(UserDefinedField UserDefinedField, string SubTypeID = null)
        {
            string RequestUri =
                (SubTypeID == null || SubTypeID.Length == 0) ?
                string.Format(@"metadata/{0}", this.ResourceName) :
                string.Format(@"metadata/{0}/{1}", ResourceName, SubTypeID);

            Dictionary <string, string> dicQueryStringParameters = new Dictionary <string, string>();
            string postBody    = PepperiJsonSerializer.Serialize(UserDefinedField);                                    //null values are not serialized
            string contentType = "application/json";
            string accept      = "application/json";

            PepperiHttpClient         PepperiHttpClient         = new PepperiHttpClient(this.Authentication, this.Logger);
            PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.PostStringContent(
                ApiBaseUri,
                RequestUri,
                dicQueryStringParameters,
                postBody,
                contentType,
                accept
                );

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

            string result = PepperiJsonSerializer.DeserializeOne <string>(PepperiHttpClientResponse.Body);

            return(result);
        }
Пример #2
0
        /// <summary>
        /// This method will update a UDF Picklist for a given Contact.
        /// </summary>
        /// <param name="contact">Contact to update.</param>
        /// <param name="udfName">UDF Name to update.</param>
        /// <param name="udfPicklistLabel">UDF Picklist Label to update</param>
        /// <returns>Returns the updated Contact.</returns>
        public Contact UpdateContactUdfPicklist(Contact contact, string udfName, string udfPicklistLabel)
        {
            Contact          retContact     = null;
            UserDefinedField fldFieldToFind = FindUserDefinedField(contact.UserDefinedFields, udfName);

            Field[] fieldsUdfContact    = this.atwsServices.getUDFInfo("Contact");
            string  strUdfPickListValue = PickListValueFromField(fieldsUdfContact, udfName, udfPicklistLabel);

            if (fldFieldToFind != null)
            {
                fldFieldToFind.Value = strUdfPickListValue;
            }
            else
            {
                fldFieldToFind = new UserDefinedField {
                    Name = udfName, Value = strUdfPickListValue
                };
                contact.UserDefinedFields = new[] { fldFieldToFind };
            }

            Entity[]     entUpdateContact  = { contact };
            ATWSResponse respUpdateContact = this.atwsServices.update(entUpdateContact);

            if (respUpdateContact.ReturnCode == -1)
            {
                throw new Exception("Could not update the Contact: " + respUpdateContact.EntityReturnInfoResults[0].Message);
            }

            if (respUpdateContact.ReturnCode > 0 && respUpdateContact.EntityResults.Length > 0)
            {
                retContact = (Contact)respUpdateContact.EntityResults[0];
            }

            return(retContact);
        }
Пример #3
0
 public IActionResult Post([FromBody] UserDefinedField userDefinedField)
 {
     using (var scope = new TransactionScope())
     {
         _Repo.Insert(userDefinedField);
         scope.Complete();
         return(CreatedAtAction(nameof(Get), new { id = userDefinedField.Id }, userDefinedField));
     }
 }
Пример #4
0
        /// <summary>
        /// The Page_Load Method.
        /// </summary>
        /// <param name="sender">The Sender.</param>
        /// <param name="e">The EventArgs.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            string ticketId = this.Request.Params["TicketID"];

            if (string.IsNullOrEmpty(ticketId))
            {
                return;
            }

            string rating = this.Request.Params["Rating"];

            ATWS   client = this.GetClient();
            Ticket ticket = this.GetTicket(client, ticketId);

            if (ticket == null)
            {
                return;
            }

            // If the ticket has no UDF values populated the user defined field array will be empty.
            if (ticket.UserDefinedFields.Length == 0)
            {
                UserDefinedField responseRating = new UserDefinedField {
                    Name = "Emoticon Response", Value = rating
                };
                UserDefinedField responseDate = new UserDefinedField {
                    Name = "Emoticon Response Date", Value = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)
                };
                ticket.UserDefinedFields    = new UserDefinedField[2];
                ticket.UserDefinedFields[0] = responseRating;
                ticket.UserDefinedFields[1] = responseDate;
            }
            else
            {
                UserDefinedField responseRating = ticket.UserDefinedFields.First(udf => udf.Name.Equals("Emoticon Response"));
                responseRating.Value = rating;
                UserDefinedField responseDate = ticket.UserDefinedFields.First(udf => udf.Name.Equals("Emoticon Response Date"));
                responseDate.Value = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture);
            }

            ATWSResponse response = client.update(new Entity[] { ticket });

            if (response.ReturnCode != -1)
            {
                return;
            }

            StringBuilder message = new StringBuilder();

            foreach (ATWSError atwsError in response.Errors)
            {
                message.Append(atwsError.Message).Append(Environment.NewLine);
            }

            throw new Exception(message.ToString());
        }
Пример #5
0
 public IActionResult Put([FromBody] UserDefinedField userDefinedField)
 {
     if (userDefinedField != null)
     {
         using (var scope = new TransactionScope())
         {
             _Repo.Update(userDefinedField);
             scope.Complete();
             return(new OkResult());
         }
     }
     return(new NoContentResult());
 }
Пример #6
0
        public string GetUserDefinedField(int userid, string key)
        {
            BBSDataDataContext bbs = GetDataContext();
            UserDefinedField   udf = bbs.UserDefinedFields.FirstOrDefault(p => p.UserId.Equals(userid) && p.Key.ToUpper().Equals(key.ToUpper()));

            if (udf != null)
            {
                return(udf.FieldValue);
            }
            else
            {
                return("");
            }
        }
Пример #7
0
        public void SaveUserDefinedField(int userid, string key, string value)
        {
            BBSDataDataContext bbs = GetDataContext();
            UserDefinedField   udf = bbs.UserDefinedFields.FirstOrDefault(p => p.UserId.Equals(userid) && p.Key.ToUpper().Equals(key.ToUpper()));

            if (udf != null)
            {
                //Modify
                udf.FieldValue = value;
            }
            else
            {
                //New
                udf = new UserDefinedField()
                {
                    Key = key, FieldValue = value, UserId = userid
                };
                bbs.UserDefinedFields.InsertOnSubmit(udf);
            }
            bbs.SubmitChanges();
        }
Пример #8
0
		/// <summary>
		/// Ensures that all contacts have a value for the uIsPrimaryContact field.
		/// Defaults said field to false.
        /// We do this because as of this time (June 2014) AutoTask doesn't allow the API to query against the IsPrimaryContact field.
		/// </summary>
		public static void GiveBasePrimaryContactStatus() {
			int maxID = 0;
			bool queryActive = true;

			Console.WriteLine("Ready to give primary contact status.");
			QuitChoice();

			Console.WriteLine("Beginning status update...");

			List<Entity> buffer = new List<Entity>();

			while (queryActive) {
				StringBuilder query = new StringBuilder();
				query.Append("<queryxml><entity>Contact</entity><query>");
				query.Append("<condition><field>id<expression op=\"greaterthan\">" + maxID + "</expression></field></condition>");
				query.Append("<condition><field udf=\"true\">uIsPrimaryContact<expression op=\"equals\"></expression></field></condition>");
				query.Append("</query></queryxml>");

				Console.WriteLine("Querying for set...");

				ATWSResponse response = handle.Query(query.ToString());

				if (handle.Success(response)) {
					Entity[] entities = response.EntityResults;

					if (entities.Length == 0) {
						break;
					}

					foreach (var entity in entities) {
						Contact contact = (Contact)entity;
						Console.WriteLine("Contact: " + contact.FirstName + " " + contact.LastName);
						Console.WriteLine("Buffer level: " + buffer.Count);

						int aid = (int)contact.id;

						if (aid > maxID) {
							maxID = aid;
						}

						bool skip = false;
						foreach (UserDefinedField field in contact.UserDefinedFields) {
							if (field.Name == "uIsPrimaryContact") {
								if (field.Value == "0" || field.Value == "1") {
									skip = true;
								}
								break;
							}
						}

						if (skip) {
							Console.WriteLine("Already has uIsPrimaryContact field, skipping...");
							continue;
						}

						Console.WriteLine("Giving value for uIsPrimaryContact...");

						UserDefinedField uIsPrimaryContact = new UserDefinedField();
						uIsPrimaryContact.Name = "uIsPrimaryContact";
						uIsPrimaryContact.Value = "0";

						contact.UserDefinedFields = new UserDefinedField[] { uIsPrimaryContact };

						buffer.Add(contact);

						if (buffer.Count >= AutoTaskHandle.MAX_UPDATE) {
							Console.WriteLine("Flushing buffer and writing results to AutoTask...");
							handle.Update(buffer.ToArray());
							buffer.Clear();
						}
					}
				} else {
					return;
				}
			}

			if (buffer.Count > 0) {
				Console.WriteLine("Flushing final buffer and writing results to AutoTask...");
				handle.Update(buffer.ToArray());
				buffer.Clear();
			}

			Console.WriteLine("Status update finished.");
		}
Пример #9
0
		/// <summary>
		/// Makes sure that all accounts with only one contact have that contact set as the primary contact.
		/// Any accounts with more than one contact have their lowest key active contact set as the primary.
		/// Also removes any account's emails that match the pattern /unk\.com$/
		/// </summary>
		public static void InferPrimaryContacts() {
			const int maxBufferSize = 20;// AutoTaskHandle.MAX_UPDATE;
			int one_count = 0;
			int oneplus_count = 0;
			int none_count = 0;
			long maxID = 29686517;
			bool queryActive = true;

			Regex unkatunk = new Regex(@"unk\.com$");

			Console.WriteLine("Ready to infer single contact primary contact status.");
			QuitChoice();

			Console.WriteLine("Beginning status update...");

			Dictionary<string, PickListValue> territories = new Dictionary<string, PickListValue>();
			Field[] fields = handle.client.GetFieldInfo(handle.integrations, "Account");

			foreach (Field field in fields) {
				if (field.Name == "TerritoryID") {
					foreach (PickListValue value in field.PicklistValues) {
						territories[value.Label] = value;
					}

					foreach (KeyValuePair<string, string> pair in TerritoryAliases) {
						territories[pair.Key] = territories[pair.Value];
					}
				}
			}

			List<Entity> contactBuffer = new List<Entity>();
			List<Entity> accountBuffer = new List<Entity>();

			while (queryActive) {
				StringBuilder query = new StringBuilder();
				query.Append("<queryxml><entity>Account</entity><query>");
				query.Append("<condition><field>id<expression op=\"greaterthan\">" + maxID + "</expression></field></condition>");
				query.Append("</query></queryxml>");

				Console.WriteLine("Querying for set...");

				ATWSResponse response = handle.Query(query.ToString());

				if (handle.Success(response)) {
					Entity[] entities = response.EntityResults;

					if (entities.Length == 0) {
						break;
					}

					foreach (var entity in entities) {
						Account account = (Account)entity;

						long aid = (long)account.id;

						if (aid > maxID) {
							maxID = aid;
						}

						Console.WriteLine("Account: " + account.AccountName);
						Console.WriteLine("ID: " + account.id);
						Console.WriteLine("City: " + account.City);

						string city = (string)account.City;

						if (city != null && territories.ContainsKey(city)) {
							Console.WriteLine("Setting territory ID.");
							account.TerritoryID = territories[city].Value;
							accountBuffer.Add(account);
						} else {
							Console.WriteLine("Unknown city '" + city + "'");
						}

						Contact[] accountContacts = getContactsByAccountID(account.id);
						
						if (accountContacts.Length >= 1) {
							if (accountContacts.Length == 1) {
								Console.WriteLine("Account has one contact.");
								one_count++;
							} else {
								Console.WriteLine("Account has more than one contact!");
								oneplus_count++;
							}

							long? lowKey = null;
							Contact lowestContact = null;

							foreach (Contact contact in accountContacts) {
								Console.WriteLine(contact.FirstName + " " + contact.LastName);
								Console.WriteLine("EMAIL: '" + (string)contact.EMailAddress + "'");

								string email = (string)contact.EMailAddress;
								if (email != null && unkatunk.IsMatch(email)) {
									Console.WriteLine("Fixing email of contact...");
									contact.EMailAddress = "";
								}
								if (lowKey == null || (int)contact.Active == 1 && contact.id < lowKey) {
									lowKey = contact.id;
									lowestContact = contact;
								}

								contactBuffer.Add(contact);
							}

							Console.WriteLine("Contact: " + lowestContact.FirstName + " " + lowestContact.LastName);

							UserDefinedField uIsPrimaryContact = new UserDefinedField();
							uIsPrimaryContact.Name = "uIsPrimaryContact";
							uIsPrimaryContact.Value = "1";

							lowestContact.UserDefinedFields = new UserDefinedField[] { uIsPrimaryContact };
						} else {
							none_count++;
							Console.WriteLine("Account has no contacts!");
						}

						Console.WriteLine("");

						FlushAndWrite(contactBuffer, maxBufferSize);
						FlushAndWrite(accountBuffer, maxBufferSize);
					}
				} else {
					return;
				}
			}

			FlushAndWrite(contactBuffer, 0);
			FlushAndWrite(accountBuffer, 0);

			Console.WriteLine("Status update finished.");
			Console.WriteLine("Accounts with no contacts: " + none_count);
			Console.WriteLine("Accounts with one contact: " + one_count);
			Console.WriteLine("Accounts with two or more contacts: " + oneplus_count);
		}