/// <summary> /// Updates the tran item. /// </summary> /// <param name="context">The context.</param> /// <param name="web">The web.</param> /// <param name="item">The item.</param> /// <param name="tran">The tran.</param> /// <param name="objParams">The object parameters.</param> /// <returns> /// return true false /// </returns> private bool UpdateTranItem(ClientContext context, Web web, ref ListItem item, ITrans tran, Dictionary <string, string> objParams) { bool hasFile = false; PropertyInfo[] itemProperties = tran.GetType().GetProperties(); List <FileDetails> files = null; List <string> subTasklistNames = new List <string>(); List <List <ITask> > subTasks = new List <List <ITask> >(); List <string> transListName = new List <string>(); List <List <ITrans> > transList = new List <List <ITrans> >(); Dictionary <string, object> itemValues = new Dictionary <string, object>(); foreach (PropertyInfo property in itemProperties) { bool isListCoumn = property.GetCustomAttribute <IsListColumnAttribute>() == null || property.GetCustomAttribute <IsListColumnAttribute>().IsListColumn; bool isTask = property.GetCustomAttribute <IsTaskAttribute>() != null && property.GetCustomAttribute <IsTaskAttribute>().IsTaskField; bool isTran = property.GetCustomAttribute <IsTranAttribute>() != null && property.GetCustomAttribute <IsTranAttribute>().IsTranField; bool isFile = property.GetCustomAttribute <IsFileAttribute>() != null && property.GetCustomAttribute <IsFileAttribute>().IsFile; bool isPerson = property.GetCustomAttribute <IsPersonAttribute>() != null && property.GetCustomAttribute <IsPersonAttribute>().IsPerson; bool isReturnName = property.GetCustomAttribute <IsPersonAttribute>() != null && property.GetCustomAttribute <IsPersonAttribute>().ReturnName; string listCoumnName = property.GetCustomAttribute <FieldColumnNameAttribute>() != null && !string.IsNullOrEmpty(property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation) ? property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation : property.Name; if (isListCoumn) { if (isPerson) { if (!isReturnName) { string users = Convert.ToString(property.GetValue(tran)).Trim(','); itemValues[listCoumnName] = this.GetMultiplePersonField(context, web, users, property); } } else if (isFile) { files = property.GetValue(tran) != null?property.GetValue(tran) as List <FileDetails> : null; } else { itemValues[listCoumnName] = property.GetValue(tran); } } else if (isTran) { string tranListName = property.GetCustomAttribute <IsTranAttribute>().TranListName; List <ITrans> tranList = property.GetValue(tran) as List <ITrans>; if (tranList != null && tranList.Count > 0 && !string.IsNullOrEmpty(tranListName)) { transListName.Add(tranListName); transList.Add(tranList); } } else if (isTask) { string subTasklistName = property.GetCustomAttribute <IsTaskAttribute>().TaskListName; List <ITask> subTask = property.GetValue(tran) != null?property.GetValue(tran) as List <ITask> : null; if (!string.IsNullOrEmpty(subTasklistName) && subTask != null && subTask.Count > 0) { subTasklistNames.Add(subTasklistName); subTasks.Add(subTask); } } } foreach (KeyValuePair <string, object> itemValue in itemValues) { item[itemValue.Key] = itemValue.Value; } item.Update(); context.Load(item); context.ExecuteQuery(); if (files != null) { this.SaveAttachment(context, files, ref item); hasFile = true; } if (transList != null && transList.Count > 0 && transList.Count == transListName.Count) { string itemId = item["ID"].ToString(); for (int i = 0; i < subTasks.Count; i++) { if (transList[i] != null && transList[i].Count > 0) { transList[i].ForEach(p => p.RequestID = Convert.ToInt32(itemId)); this.SaveTranItems(context, web, transList[i], transListName[i], objParams); } } } return(hasFile); }
/// <summary> /// Gets the transaction list data by identifier. /// </summary> /// <param name="context">The context.</param> /// <param name="web">The web.</param> /// <param name="type">The type.</param> /// <param name="listName">Name of the list.</param> /// <param name="transId">The trans identifier.</param> /// <param name="getSubItems">if set to <c>true</c> [get sub items].</param> /// <returns>Itrans object</returns> public ITrans GetTransactionListDataById(ClientContext context, Web web, Type type, string listName, int transId, bool getSubItems = true) { ITrans tranItem = null; if (context != null && web != null && type != null && transId > 0 && !string.IsNullOrEmpty(listName)) { tranItem = Activator.CreateInstance(type) as ITrans; List transList = web.Lists.GetByTitle(listName); ListItem transListItem = transList.GetItemById(transId); context.Load(transListItem); context.ExecuteQuery(); tranItem = this.SetTranProperties(context, web, transListItem, tranItem, tranItem.GetType().GetProperties(), getSubItems); } return(tranItem); }
/// <summary> /// Assigns the tran property values REST. /// </summary> /// <param name="context">The context.</param> /// <param name="web">The web.</param> /// <param name="items">The items.</param> /// <param name="itemType">Type of the item.</param> /// <returns>List of Transaction data</returns> private List <ITrans> AssignTranPropertyValuesREST(ClientContext context, Web web, JArray items, Type itemType) { List <ITrans> tranItems = new List <ITrans>(); foreach (JToken item in items) { ITrans tranItem = Activator.CreateInstance(itemType) as ITrans; tranItem = this.SetTranPropertiesREST(context, web, item, tranItem, tranItem.GetType().GetProperties()); tranItem.ItemAction = ItemActionStatus.NOCHANGE; tranItem.ID = Convert.ToInt32(item["ID"]); tranItem.Index = tranItems.Count + 1; tranItems.Add(tranItem); } return(tranItems); }