/// <summary> /// /// </summary> /// <param name="teamUrl"></param> /// <param name="listName"></param> /// <returns></returns> public List <ColumnDefinition> GetEntityColumnDefaultValues(SPDataAccess spDataAccess, string listName) { List <ColumnDefinition> columnDefinitions = new List <ColumnDefinition>(); spDataAccess.InitializeCurrentUser(); string siteUrl = spDataAccess.CurrentUser.Teams[1].SiteUrl; Dictionary <string, string> fields = spDataAccess.GetEntityFields(siteUrl, listName); foreach (KeyValuePair <string, string> kvp in fields) { List <string> defaultValues = new List <string>(); defaultValues = this.GetPropertyDefaultValues(spDataAccess, listName, kvp.Key); if (ImportValidationUtilities.IsValidFieldName(kvp.Key)) { ColumnDefinition columnDefinition = new ColumnDefinition(kvp.Key); columnDefinition.DefaultValues = defaultValues; columnDefinitions.Add(columnDefinition); } } // order by field name alpha so it's easier to read ColumnDefinition kpid = columnDefinitions.Find(c => c.Field.Equals("KPID")); columnDefinitions.Remove(kpid); columnDefinitions = columnDefinitions.OrderBy(c => c.FieldName).ToList(); columnDefinitions.Insert(0, kpid); return(columnDefinitions); }
/// <summary> /// Gets the mappings for the specified entity and worksheet /// </summary> /// <returns></returns> public Message GetEntityMappings() { Message responseMsg = null; ImportUtilities importUtility = new ImportUtilities(); SPDataAccess spDataAccess = new SPDataAccess(); MappedColumns mappedColumns = new MappedColumns(); WorksheetUtilities worksheetUtilities = new WorksheetUtilities(spDataAccess); MappingData mappingData = this.ValidateRequest(spDataAccess, false); // get the columns from the supplied worksheet mappedColumns.WSColumns = worksheetUtilities.GetWorksheetColumns(mappingData); // checks to see if the columns pulled from sheet map to // a predefined template e.g. Bulk Import or Goals Export mappedColumns.TemplateType = ImportUtilities.GetImportTemplateType(mappedColumns.WSColumns); // get the entity columns with the default values for choice columns mappedColumns.ColumnDefinitions = importUtility.GetEntityColumnDefaultValues(spDataAccess, mappingData.ListName); responseMsg = ctx.CreateJsonResponse <MappedColumns>(mappedColumns); return(responseMsg); }
public EntityManager(SPDataAccess spDataAccess, KPUser kpUser) { this.spDataAccess = spDataAccess; // diagnostics timer this.timer = this.spDataAccess.Timer; this.User = kpUser; }
/// <summary> /// Convert the value if it is a DateTime /// </summary> /// <param name="value"></param> /// <returns></returns> //internal static string ConvertCellValueDateTime(string value) //{ // string returnValue; // // need to parse different inputs // DateTime date; // if (string.IsNullOrEmpty(value)) // returnValue = value; // if (!DateTime.TryParse(value, out date)) // { // double dateVal; // if (double.TryParse(value, out dateVal)) // date = DateTime.FromOADate(dateVal); // } // if(date == new DateTime()) // return string.Empty; // else // return date.ToString("MM/dd/yyyy hh:mm:ss tt"); //} /// <summary> /// Sets the team object and id on mapping data /// </summary> /// <param name="spDataAccess"></param> /// <param name="mappingData"></param> internal static void SetTeam(SPDataAccess spDataAccess, MappingData mappingData) { string teamName = mappingData.Mappings["KPTeam"]; Team team = spDataAccess.Teams.Find(t => t.Nick == teamName); mappingData.TeamId = team.KPID; mappingData.Team = team; }
/// <summary> /// Default Ctor /// </summary> /// <param name="worksheetUtilities"></param> /// <param name="spDataAccess"></param> public SheetImport(WorksheetUtilities worksheetUtilities, SPDataAccess spDataAccess) { this.worksheetUtilities = worksheetUtilities; this.spDataAccess = spDataAccess; this.domainManager = new DomainManager(); this.domainManager.SetCurrentUser(); // sets default 'storage' library // uploaded documents are saved here by default this.libraryName = DOCUMENT_UPLOAD_LIBRARY; }
/// <summary> /// Get list of worksheets in the specified file /// </summary> /// <param name="fileName"></param> public Message GetSheets(string listName, string fileName) { Message responseMsg = null; SPDataAccess spDataAccess = new SPDataAccess(); WorksheetUtilities worksheetUtilities = new WorksheetUtilities(new SPDataAccess()); List <string> worksheets = worksheetUtilities.GetWorksheetNames(listName, fileName); responseMsg = ctx.CreateJsonResponse <List <string> >(worksheets); return(responseMsg); }
/// <summary> /// Get the column definitions for the specified list /// </summary> /// <param name="listName"></param> /// <returns></returns> public Message GetItemColumnDefinitions(string listName) { Message responseMsg = null; ImportUtilities importUtility = new ImportUtilities(); SPDataAccess spDataAccess = new SPDataAccess(); List <ColumnDefinition> fields = importUtility.GetEntityColumnDefaultValues(spDataAccess, listName); responseMsg = ctx.CreateJsonResponse <List <ColumnDefinition> >(fields); return(responseMsg); }
/// <summary> /// Save uploaded file to SP document library /// </summary> /// <param name="fileName"></param> /// <param name="fileStream"></param> /// <returns></returns> public Message SaveFile(string teamId, Stream fileStream) { string response = string.Empty; int teamID = Int16.Parse(teamId); string fileGuid = Guid.NewGuid().ToString() + ".docx"; Dictionary <string, string> responseData = new Dictionary <string, string>(); var serializer = new DataContractJsonSerializer(typeof(Dictionary <string, string>), new DataContractJsonSerializerSettings() { UseSimpleDictionaryFormat = true }); try { KPTimer timer = EventLogger.Timer; MultipartParser parser = new MultipartParser(fileStream); if (parser.Success) { // save the file SPDataAccess spDataAccess = new SPDataAccess(); spDataAccess.SaveFileToLibrary(teamID, fileGuid, parser.FileContents); // generate response responseData.Add("FileName", fileGuid); responseData.Add("Elapsed", timer.ElapsedMilliseconds().ToString()); responseData.Add("Bytes", parser.FileContents.Length.ToString()); } else { string errMsg = string.Empty; ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.BadRequest; responseData.Add("Error", "Error parsing filestream"); if (parser.FileContents == null) { responseData.Add("FileContents", "no file content sent in request."); } if (parser.ContentType == null) { responseData.Add("ContentType", "no file content-type found in request."); } } } catch (Exception ex) { ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.BadRequest; responseData.Add("Exception", ex.Message); if (ex.InnerException != null) { responseData.Add("InnerException", ex.InnerException.Message); } } return(this.ctx.CreateJsonResponse <Dictionary <string, string> >(responseData, serializer)); }
/// <summary> /// /// </summary> /// <param name="teamId"></param> /// <param name="fileName"></param> /// <returns></returns> public Message Download(string teamId, string fileName) { string LIBRARY_NAME = "KPReports"; SPDataAccess spDataAccess = new SPDataAccess(); MemoryStream stream = spDataAccess.GetFileStream(Int32.Parse(teamId), LIBRARY_NAME, fileName); Message responseMsg = this.ctx.CreateStreamResponse(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); if (stream != null) { stream.Dispose(); } return(responseMsg); }
/// <summary> /// Default Ctor to create repository instances /// </summary> public DomainManager() { // create DataAccess instance this.spDataAccess = new SPDataAccess(); // create lookup repository instances this.ConfigListRepository = new ConfigListRepository(this.spDataAccess); this.TeamRepository = new TeamRepository(this.spDataAccess); // create entity repository instances this.GoalRepository = new GoalRepository(this.spDataAccess); this.SetCurrentUser(); this.entityManager = new EntityManager(spDataAccess, User); this.lookupManager = new LookupManager(spDataAccess); }
/// <summary> /// /// </summary> /// <param name="filePath"></param> /// <returns></returns> /// public ImportResponse ImportData(string listName, string fileName, string worksheet, string importType, string teamId) public ImportResponse ImportData() { // get the web context for the response WebOperationContext ctx = WebOperationContext.Current; // set default status to 200-OK ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.OK; // initialize objects ImportResponse response = new ImportResponse(); SPDataAccess spDataAccess = new SPDataAccess(); // create an instance of the worksheet and initialize SheetImport SheetImport import = new SheetImport(new WorksheetUtilities(spDataAccess), spDataAccess); try { MappingData mappingData = this.ValidateRequest(spDataAccess, true); // import the file data using the uploaded file as input response = import.ImportFileData(mappingData); // check response status code - set to error if not 200 if (response.StatusCode != 200) { ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.InternalServerError; } } catch (Exception ex) { ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.InternalServerError; response.StatusCode = 520; response.Message = "Error in Import.ImportData"; response.Errors = new List <ErrorObject>(); response.Errors.Add(new ErrorObject(ex.Message, ex.StackTrace)); } return(response); }
/// <summary> /// /// </summary> /// <param name="listName"></param> /// <returns></returns> private List <string> GetPropertyDefaultValues(SPDataAccess spDataAccess, string listName, string propertyName) { // return default values List <string> defaultValues = new List <string>(); switch (propertyName) { case "KPTeam": defaultValues = spDataAccess.CurrentUser.Teams.Select(t => t.Nick).ToList(); break; case "KPStatus": defaultValues = ENTITY_STATUS_STATES[listName]; break; case "KPItemState": defaultValues = ITEM_STATES; break; case "Country": defaultValues = COUNTRIES; break; case "KPPrimaryVP": case "KPSecondaryVPs": defaultValues = this.GetItemValues(spDataAccess.GetLookupItems("KPVPs"), "Nick"); break; case "GoalSet": defaultValues = this.GetItemValues(spDataAccess.GetLookupItems("KPGoalSets"), "Title"); break; case "CategoryL1": case "CategoryL2": defaultValues = this.GetItemValues(spDataAccess.GetLookupItems("KP" + propertyName), "Title"); break; } return(defaultValues); }
public void RunningProcessServiceManual() { var siteUrl = System.Configuration.ConfigurationManager.AppSettings.Get("SPList"); try { Utility.WriteLog("Reading Service Manual " + System.DateTime.Now.ToString(), "Normal"); int counterInsertSuccess = 0; int counterUpdateSuccess = 0; var listConfig = Utility.GetConfiguration(); var sourcePath = listConfig.Where(x => x.Name == Constants.SourceServiceManual).FirstOrDefault(); var backupPath = listConfig.Where(x => x.Name == Constants.BackupPathSVM).FirstOrDefault(); var errorPath = listConfig.Where(x => x.Name == Constants.Error).FirstOrDefault(); if (sourcePath != null) { if (Directory.GetFiles(sourcePath.Values, "*", SearchOption.AllDirectories).Length > 0) { DataAccessModel oldListData = SPDataAccess.GetListServiceManualData("SERVICE_MANUAL_LIST", siteUrl); int maxNumber = 0; if (oldListData.listSVMData != null) { maxNumber = oldListData.listSVMData.Count; } foreach (var item in Directory.GetFiles(sourcePath.Values)) { if (item.ToUpper().Contains(".XLS") || item.ToUpper().Contains(".XLSX")) { var list_svm = FileService.GetListSVMData(item); string fileName = Path.GetFileName(item); if (list_svm.Count > 0) { int index = 0; int tempIndex = 0; foreach (var itemSVM in list_svm) { int DuplicateIndex = oldListData.listSVMData.FindIndex(a => a.Indoor_Model_Name == itemSVM.Indoor_Model_Name && a.Outdoor_Model_Name == itemSVM.Outdoor_Model_Name); if (DuplicateIndex == -1) // case Insert { try { index = index + 1; tempIndex = index + maxNumber; itemSVM.Title = tempIndex.ToString("00000"); SPDataAccess.AddListServiceManual(itemSVM, "SERVICE_MANUAL_LIST", siteUrl, fileName); counterInsertSuccess++; } catch (Exception ex) { Utility.WriteLog(itemSVM.Indoor_Model_Name + " And " + itemSVM.Outdoor_Model_Name + " => " + ex.Message, "Error"); } } else if (DuplicateIndex >= 0) // case Update { try { SPDataAccess.UpdateListServiceManual(oldListData.listSVMData[DuplicateIndex], itemSVM, "SERVICE_MANUAL_LIST", siteUrl, fileName); counterUpdateSuccess++; } catch (Exception ex) { Utility.WriteLog(itemSVM.Indoor_Model_Name + " And " + itemSVM.Outdoor_Model_Name + " => " + ex.Message, "Error"); } } } File.Move(item, backupPath.Values + @"\" + Path.GetFileNameWithoutExtension(item) + "_" + System.DateTime.Now.ToString("MM-dd-yy_HHmmss") + Path.GetExtension(item)); Utility.WriteLog("File Name:" + Path.GetFileName(item) + " (Actual Data: " + list_svm.Count + " records. Inserted: " + counterInsertSuccess + " records. Updated: " + counterUpdateSuccess + " records)", "Success"); SPDataAccess.AddLog(Path.GetFileName(item), "(Actual Data: " + list_svm.Count + " records. Inserted: " + counterInsertSuccess + " records. Updated: " + counterUpdateSuccess + " records) Success", listLogName, siteUrl, "Service Manual"); } else { File.Move(item, errorPath.Values + @"\" + Path.GetFileNameWithoutExtension(item) + "_" + System.DateTime.Now.ToString("MM-dd-yy_HHmmss") + Path.GetExtension(item)); Utility.WriteLog("File: " + item + " is not correct format", "Error"); SPDataAccess.AddLog(Path.GetFileName(item), "File: " + item + " is not correct format Error", listLogName, siteUrl, "Service Manual"); } } else { File.Move(item, errorPath.Values + @"\" + Path.GetFileNameWithoutExtension(item) + "_" + System.DateTime.Now.ToString("MM-dd-yy_HHmmss") + Path.GetExtension(item)); Utility.WriteLog("File: " + item + " is not Excel format", "Error"); SPDataAccess.AddLog(Path.GetFileName(item), "File: " + item + " is not correct format Error", "UPLOAD_LOG", siteUrl, "Service Manual"); } } } } } catch (Exception ex) { var st = new StackTrace(ex, true); var frame = st.GetFrame(0); var line = frame.GetFileLineNumber(); Utility.WriteLog("Running Service Manual : " + ex.ToString() + "Line: " + line.ToString(), "Error"); SPDataAccess.AddLog("Exception", ex.Message, listLogName, siteUrl, "Service Manual"); } finally { // Utility.KillExcel(); } }
public void RunningProcessModelAndPart() { var siteUrl = System.Configuration.ConfigurationManager.AppSettings.Get("SPList"); try { Utility.WriteLog("Reading Model " + System.DateTime.Now.ToString(), "Normal"); var listConfig = Utility.GetConfiguration(); var sourcePath = listConfig.Where(x => x.Name == Constants.SourcePathModel).FirstOrDefault(); var backupPath = listConfig.Where(x => x.Name == Constants.BackupPath).FirstOrDefault(); var errorPath = listConfig.Where(x => x.Name == Constants.Error).FirstOrDefault(); if (sourcePath != null) { if (Directory.GetFiles(sourcePath.Values, "*", SearchOption.AllDirectories).Length > 0) { foreach (var item in Directory.GetFiles(sourcePath.Values)) { string fileName = Path.GetFileName(item); int counterInsertSuccess = 0; int counterUpdateSuccess = 0; DataAccessModel SPListData = SPDataAccess.GetListModelData("SERVICE_PART_LIST", siteUrl); string allModel = ""; if (item.ToUpper().Contains(".XLS") || item.ToUpper().Contains(".XLSX")) { var list_model = FileService.GetListModelData(item); var groupedModel = list_model.OrderBy(x => x.Model_Name).GroupBy(x => x.Model_Name).ToList(); foreach (var name in groupedModel) { allModel += " " + name.Key; } var listModelPart = (from p in list_model where p.Part_No != "" select p).ToList(); foreach (var model in groupedModel) { if (model.Key != "") { var listFilter = (from p in list_model where p.Model_Name == model.Key && p.Part_No != "" select p).ToList(); if (listFilter.Count > 0) { SPDataAccess.DeleteModel(model.Key, listFilter, "SERVICE_PART_LIST", siteUrl); } } } foreach (var itemModel in list_model) { if (itemModel.Model_Name != "" && itemModel.Part_No != "") { var listOldModel = (from p in SPListData.listModelData where p.Model_Name == itemModel.Model_Name && p.Part_No == itemModel.Part_No select p).ToList(); //####### Rewrite Model ####### try { SPDataAccess.UpdateAllPart(itemModel, "SERVICE_PART_LIST", siteUrl); if (listOldModel.Count > 0) { foreach (var oldModel in listOldModel) { SPDataAccess.UpdateListModel(oldModel, itemModel, "SERVICE_PART_LIST", siteUrl, fileName); counterUpdateSuccess++; } } else { SPDataAccess.AddListModel(itemModel, "SERVICE_PART_LIST", siteUrl, fileName); counterInsertSuccess++; } } catch (Exception ex) { Utility.WriteLog(itemModel.Model_Name + " => " + ex.Message, "Add Error"); } } else if (itemModel.Model_Name == "" && itemModel.Part_No != "") { try { SPDataAccess.UpdateAllPart(itemModel, "SERVICE_PART_LIST", siteUrl); counterUpdateSuccess++; } catch (Exception ex) { Utility.WriteLog(itemModel.Part_No + " => " + ex.Message, "Update Error"); } } else if (itemModel.Model_Name != "" && itemModel.Part_No == "") { try { SPDataAccess.UpdateAllModel(itemModel, "SERVICE_PART_LIST", siteUrl); counterUpdateSuccess++; } catch (Exception ex) { Utility.WriteLog(itemModel.Part_No + " => " + ex.Message, "Update Error"); } } } File.Move(item, backupPath.Values + @"\" + Path.GetFileNameWithoutExtension(item) + "_" + System.DateTime.Now.ToString("MM-dd-yy_HHmmss") + Path.GetExtension(item)); Utility.WriteLog("File Name:" + Path.GetFileName(item) + " (Model: " + allModel + " Actual Data: " + list_model.Count + " records. Inserted: " + counterInsertSuccess + " records. Update: " + counterUpdateSuccess + " records.)", "Success"); SPDataAccess.AddLog(Path.GetFileName(item), " (Model: " + allModel + " Actual Data: " + list_model.Count + " records. Inserted: " + counterInsertSuccess + " records. Update: " + counterUpdateSuccess + " records.) Success", listLogName, siteUrl, "Service Part List"); } else { File.Move(item, errorPath.Values + @"\" + Path.GetFileNameWithoutExtension(item) + "_" + System.DateTime.Now.ToString("MM-dd-yy_HHmmss") + Path.GetExtension(item)); Utility.WriteLog("File: " + item + " is not Excel format", "Error"); SPDataAccess.AddLog(Path.GetFileName(item), "File: " + item + " is not Excel format Error", listLogName, siteUrl, "Service Part List"); } } } } } catch (Exception ex) { var st = new StackTrace(ex, true); var frame = st.GetFrame(0); var line = frame.GetFileLineNumber(); Utility.WriteLog("Running Model : " + ex.ToString() + "Line: " + line.ToString(), "Error"); SPDataAccess.AddLog("Exception", ex.Message, "UPLOAD_LOG", siteUrl, "Service Part List"); } finally { // Utility.KillExcel(); } }
public TeamRepository(SPDataAccess dataAccess) { this.dataAccess = dataAccess; }
public VPRepository(SPDataAccess spDataAccess) : base(spDataAccess) { }
public GoalRepository(SPDataAccess dataAccess) { this.dataAccess = dataAccess; }
public GoalSetRepository(SPDataAccess spDataAccess) : base(spDataAccess) { }
public LookupManager(SPDataAccess spDataAccess) { this.spDataAccess = spDataAccess; this.timer = spDataAccess.Timer; }
public void RunningProcessModelBL() { var siteUrl = System.Configuration.ConfigurationManager.AppSettings.Get("BL-SPList"); try { Utility.WriteLog("Reading Model BusinessLounge " + System.DateTime.Now.ToString(), "Normal"); int counterInsertSuccess = 0; int counterUpdateSuccess = 0; var listConfig = Utility.GetConfiguration(); var sourcePath = listConfig.Where(x => x.Name == Constants.SourcePathModelBL).FirstOrDefault(); var backupPath = listConfig.Where(x => x.Name == Constants.BackupPathBL).FirstOrDefault(); var errorPath = listConfig.Where(x => x.Name == Constants.Error).FirstOrDefault(); if (sourcePath != null) { if (Directory.GetFiles(sourcePath.Values, "*", SearchOption.AllDirectories).Length > 0) { DataAccessModel oldListData = SPDataAccess.GetListModelBLData("PRODUCTS", siteUrl); foreach (var item in Directory.GetFiles(sourcePath.Values)) { if (item.ToUpper().Contains(".XLS") || item.ToUpper().Contains(".XLSX")) { var list_ModelBL = FileService.GetListModelBL(item); string fileName = Path.GetFileName(item); if (list_ModelBL.Count > 0) { foreach (var itemModelBL in list_ModelBL) { int DuplicateIndex = oldListData.listModelBLData.FindIndex(a => a.INDOOR == itemModelBL.INDOOR && a.OUTDOOR == a.OUTDOOR); //int[] duplicateSet = oldListData.listModelBLData.Select((b, i) => b.INDOOR == itemModelBL.INDOOR && b.OUTDOOR == itemModelBL.OUTDOOR ? i : -1).Where(i => i != -1).ToArray(); if (DuplicateIndex == -1) // case Insert { try { SPDataAccess.AddListModelBL(itemModelBL, "PRODUCTS", siteUrl, fileName); counterInsertSuccess++; } catch (Exception ex) { Utility.WriteLog(itemModelBL.Id + " => " + ex.Message, "Error"); } } else if (DuplicateIndex >= 0) // case Update { try { SPDataAccess.UpdateListModelBL(oldListData.listModelBLData[DuplicateIndex], itemModelBL, "PRODUCTS", siteUrl, fileName); counterUpdateSuccess++; } catch (Exception ex) { Utility.WriteLog(itemModelBL.Id + " => " + ex.Message, "Error"); } } } File.Move(item, backupPath.Values + @"\" + Path.GetFileNameWithoutExtension(item) + "_" + System.DateTime.Now.ToString("MM-dd-yy_HHmmss") + Path.GetExtension(item)); Utility.WriteLog("File Name:" + Path.GetFileName(item) + " (Actual Data: " + list_ModelBL.Count + " records. Inserted: " + counterInsertSuccess + " records. Updated: " + counterUpdateSuccess + " records)", "Success"); SPDataAccess.AddLog(Path.GetFileName(item), "(Actual Data: " + list_ModelBL.Count + " records. Inserted: " + counterInsertSuccess + " records. Updated: " + counterUpdateSuccess + " records) Success", listLogName, siteUrl, "Model BL"); } else { File.Move(item, errorPath.Values + @"\" + Path.GetFileNameWithoutExtension(item) + "_" + System.DateTime.Now.ToString("MM-dd-yy_HHmmss") + Path.GetExtension(item)); Utility.WriteLog("File: " + item + " is not correct format", "Error"); SPDataAccess.AddLog(Path.GetFileName(item), "File: " + item + " is not correct format Error", listLogName, siteUrl, "Models BL"); } } else { File.Move(item, errorPath.Values + @"\" + Path.GetFileNameWithoutExtension(item) + "_" + System.DateTime.Now.ToString("MM-dd-yy_HHmmss") + Path.GetExtension(item)); Utility.WriteLog("File: " + item + " is not Excel format", "Error"); SPDataAccess.AddLog(Path.GetFileName(item), "File: " + item + " is not Excel format", listLogName, siteUrl, "Models BL"); } } } } } catch (Exception ex) { var st = new StackTrace(ex, true); var frame = st.GetFrame(0); var line = frame.GetFileLineNumber(); Utility.WriteLog("Running Model BL : " + ex.ToString() + "Line: " + line.ToString(), "Error"); SPDataAccess.AddLog("Exception", ex.Message, listLogName, siteUrl, "Models BL"); } finally { // Utility.KillExcel(); } }
public ConfigListRepository(SPDataAccess dataAccess) { this.dataAccess = dataAccess; }
/// <summary> /// Validate the import mapping request /// </summary> /// <param name="spDataAccess"></param> /// <param name="isImport"></param> /// <returns></returns> private MappingData ValidateRequest(SPDataAccess spDataAccess, bool isImport) { // get the message (body) Message message = OperationContext.Current.RequestContext.RequestMessage; ImportResponse response = new ImportResponse(); MappingData mappingData = null; string jsonData = string.Empty; // get the convert the body text jsonData = JSON.GetPayload(message); // deserialize the JSON body mappingData = JsonConvert.DeserializeObject <MappingData>(jsonData); if (string.IsNullOrEmpty(mappingData.ListName)) { throw new Exception("List name is required (listName)"); } if (string.IsNullOrEmpty(mappingData.FileName)) { throw new Exception("File name is required (fileName)"); } if (mappingData.TemplateType == null && isImport) { throw new Exception("Template type is required (templateType)"); } if (mappingData.TemplateType.Equals(ImportType.Import) && mappingData.TeamId < 0) { throw new Exception("TeamId is required for Import templates"); } // initialize user to get their teams spDataAccess.InitializeCurrentUser(); // if we have a dynamic template then we need to set the // team to what was passed in and add the required field to the mappings if (mappingData.TemplateType.Equals(ImportType.Dynamic)) { // get team mappingData.Team = spDataAccess.CurrentUser.Teams.Find(t => t.KPID == mappingData.TeamId); // create the mapping value with the delimiter mappingData.Mappings.Add("KPTeam", string.Format("#{0}", mappingData.Team.Nick)); } else { if (mappingData.TeamId.HasValue && mappingData.TeamId > -1) { Team team = spDataAccess.CurrentUser.Teams.Find(t => t.KPID == mappingData.TeamId); if (team != null) { mappingData.Team = team; } else { throw new Exception(string.Format("Error Validating: TeamId {0} does not exist.", mappingData.TeamId)); } } else { if (spDataAccess.CurrentUser.Teams.Count > 0) { mappingData.Team = spDataAccess.CurrentUser.Teams[0]; } else { throw new Exception(string.Format("Error Validating: User does not have any Teams assigned.")); } } } return(mappingData); }
public EntityRepository(SPDataAccess dataAccess, string listName) { this.ListName = listName; this.dataAccess = dataAccess; }
public CategoryL2Repository(SPDataAccess spDataAccess) : base(spDataAccess) { }
public LookupRepository(SPDataAccess dataAccess) { this.dataAccess = dataAccess; this.Init(); }
public WorksheetUtilities(SPDataAccess dataAccess) { this.spDataAccess = dataAccess; }