/// <summary> /// Assigns the property values. /// </summary> /// <param name="objMaster">The object master.</param> /// <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> /// master object /// </returns> private IMaster AssignPropertyValues(dynamic objMaster, ClientContext context, Web web, ListItemCollection items, Type itemType) { List <IMasterItem> masterItems = new List <IMasterItem>(); foreach (ListItem item in items) { dynamic listItem = Activator.CreateInstance(itemType); PropertyInfo[] itemProperties = listItem.GetType().GetProperties(); foreach (PropertyInfo property in itemProperties) { if (property.GetCustomAttribute <FieldColumnNameAttribute>() != null && !string.IsNullOrEmpty(property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation)) { if (property.GetCustomAttribute <IsPersonAttribute>() != null && property.GetCustomAttribute <IsPersonAttribute>().IsPerson&& property.GetCustomAttribute <IsPersonAttribute>().ReturnID) { if (item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation] is FieldUserValue[]) { property.SetValue(listItem, BELDataAccessLayer.GetUserIDsFromPersonField(context, web, (FieldUserValue[])item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation])); } else { property.SetValue(listItem, BELDataAccessLayer.GetUserIDsFromPersonField(context, web, (FieldUserValue)item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation])); } } else if (property.GetCustomAttribute <IsPersonAttribute>() != null && property.GetCustomAttribute <IsPersonAttribute>().IsPerson&& property.GetCustomAttribute <IsPersonAttribute>().ReturnName) { if (item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation] is FieldUserValue[]) { property.SetValue(listItem, BELDataAccessLayer.GetPersonValueFromPersonField(context, web, (FieldUserValue[])item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation], Person.Name)); } else { property.SetValue(listItem, BELDataAccessLayer.GetPersonValueFromPersonField(context, web, (FieldUserValue)item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation], Person.Name)); } } else if (property.GetCustomAttribute <IsPersonAttribute>() != null && property.GetCustomAttribute <IsPersonAttribute>().IsPerson&& property.GetCustomAttribute <IsPersonAttribute>().ReturnAlias) { if (item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation] is FieldUserValue[]) { property.SetValue(listItem, BELDataAccessLayer.GetPersonValueFromPersonField(context, web, (FieldUserValue[])item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation], Person.Alias)); } else { property.SetValue(listItem, BELDataAccessLayer.GetPersonValueFromPersonField(context, web, (FieldUserValue)item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation], Person.Alias)); } } else if (property.GetCustomAttribute <FieldColumnNameAttribute>().IsLookup) { if (item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation] is FieldLookupValue[]) { FieldLookupValue[] lookupFields = item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation] as FieldLookupValue[]; List <string> reletedto = new List <string>(); foreach (FieldLookupValue lookupField in lookupFields) { reletedto.Add(lookupField.LookupValue); } property.SetValue(listItem, reletedto); } else { FieldLookupValue lookupField = item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation] as FieldLookupValue; if (lookupField != null) { property.SetValue(listItem, lookupField.LookupValue); } } } else { property.SetValue(listItem, item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation]); } } } masterItems.Add(listItem); } PropertyInfo prop = objMaster.GetType().GetProperty("Items"); prop.SetValue(objMaster, masterItems, null); return(objMaster); }
/// <summary> /// Gets the report details. /// </summary> /// <param name="report">The report.</param> /// <returns> /// list of Reportdetails /// </returns> public List <ReportDetails> GetReportDetails(Report report) { try { List <ReportDetails> reportList = new List <ReportDetails>(); string appendStatusClause = string.Empty, appendWhereClause = string.Empty, startStatusAndClause = string.Empty, endStatusAndClause = string.Empty, startAndClause = string.Empty, endAndClause = string.Empty; if (report != null) { string fromDate = string.Format("{0:yyyy-MM-dd}", report.FromDate); string toDate = string.Format("{0:yyyy-MM-dd}", report.ToDate); string pendingWith = report.PendingWith; string[] arrFilter = !string.IsNullOrWhiteSpace(pendingWith) ? pendingWith.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries) : null; string status = report.Status; string[] arrStatusFilter = !string.IsNullOrWhiteSpace(status) ? status.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries) : null; List statusList = this.web.Lists.GetByTitle(ICCPListNames.ICCPMAINLIST); if (statusList != null) { CamlQuery query = new CamlQuery(); //if (!string.IsNullOrWhiteSpace(report.Status)) //{ // startStatusAndClause = "<And>"; // EndStatusAndClause = "</And>"; // appendStatusClause = @"<Eq> // <FieldRef Name='Status' /> // <Value Type='Text'>" + report.Status + @"</Value> // </Eq>"; //} string paraStatusValue = string.Empty; if (arrStatusFilter != null) { foreach (string item in arrStatusFilter) { paraStatusValue += "<Value Type='Text'>" + item + @"</Value>"; } } if (!string.IsNullOrWhiteSpace(paraStatusValue)) { startStatusAndClause = "<And>"; endStatusAndClause = "</And>"; appendStatusClause = @"<In> <FieldRef Name='Status' /> <Values> " + paraStatusValue + @" </Values> </In>"; } string paraValue = string.Empty; if (arrFilter != null) { foreach (string item in arrFilter) { paraValue += "<Value Type='Text'>" + item + @"</Value>"; } } if (!string.IsNullOrWhiteSpace(paraValue)) { if (string.IsNullOrWhiteSpace(report.Status)) { startStatusAndClause = "<And>"; endStatusAndClause = "</And>"; } else { startAndClause = "<And>"; endAndClause = "</And>"; } appendWhereClause = @"<In> <FieldRef Name='PendingWith' /> <Values> " + paraValue + @" </Values> </In>"; } query.ViewXml = @"<View> <Query> <Where> <And> <Geq> <FieldRef Name='RequestDate' /> <Value IncludeTimeValue='FALSE' Type='DateTime'>" + fromDate + @"</Value> </Geq> " + startStatusAndClause + @" <Leq> <FieldRef Name='RequestDate' /> <Value IncludeTimeValue='FALSE' Type='DateTime'>" + toDate + @"</Value> </Leq> " + startAndClause + @" " + appendStatusClause + @" " + appendWhereClause + @" " + endAndClause + @" " + endStatusAndClause + @" </And> </Where> <OrderBy> <FieldRef Name='ID' Ascending='True' /> </OrderBy> </Query> </View>"; ListItemCollection items = statusList.GetItems(query); this.context.Load(items); this.context.ExecuteQuery(); if (items != null && items.Count > 0) { foreach (ListItem item in items) { ReportDetails reportDetails = new ReportDetails(); reportDetails.ICCPNo = Convert.ToString(item["Title"]); reportDetails.ItemCode = Convert.ToString(item["ItemCode"]); reportDetails.ItemDescription = Convert.ToString(item["ItemDescription"]); reportDetails.BuyMake = Convert.ToString(item["BuyMake"]); reportDetails.CostPrice = Convert.ToString(item["CostPrice"]); reportDetails.GSTRate = Convert.ToString(item["GSTRate"]); reportDetails.PendingWith = Convert.ToString(item["PendingWith"]); reportDetails.ProductGroup = Convert.ToString(item["ProductGroup"]); reportDetails.Quantity = Convert.ToString(item["Quantity"]); reportDetails.Status = Convert.ToString(item["Status"]); if (!string.IsNullOrWhiteSpace(reportDetails.Status)) { switch (reportDetails.Status.ToLower()) { case "submitted": reportDetails.Status = "Pending"; break; case "sent back": reportDetails.Status = "Rework"; break; } } reportDetails.TypeofPackaging = Convert.ToString(item["TypeOfPackaging"]); reportDetails.CreatedBy = BELDataAccessLayer.GetPersonValueFromPersonField(this.context, this.web, (FieldUserValue)item["ProposedBy"], Person.Name); reportDetails.CreatedDate = Convert.ToString(item["RequestDate"]); reportList.Add(reportDetails); } } } } reportList.RemoveAll(m => m.Status == "Draft"); return(reportList); } catch (Exception ex) { Logger.Error(ex.StackTrace); return(null); } }