/// <summary> /// Check GoalSet value and CategoryL1 and CategoryL2 values /// and determine if selections are valid children of each /// </summary> /// <param name="sheetData"></param> public static bool ValidateGoalSetCategories(DomainManager domainManager, Dictionary <string, string> originalLookup, KPListItem item, ImportStatus importErrors) { string ERR_CATL1_MISMATCH = "Row: {0}, CategoryL1 Mismatch: {1}"; string ERR_CATL2_MISMATCH = "Row: {0}, CategoryL2 Mismatch: {1}"; string ERR_CATL1_INVALID = "Row: {0}, CategoryL1 has an invalid value so unable to match CategoryL2: {1}"; string ERR_MISSING_CATEGORY_VALUE = "Row {0} contains a value for Category Level 2, but not for Category Level 1."; string ERR_MISSING_GOALSET_VALUE = "Row {0} does not contain a value for GoalSet, but has values for Category Level 1 or 2. Please include GoalSet."; bool success = true; bool categoryL1Invalid = false; // keep item count to message user int itemCount = 1; // have CL1 or CL2 missing goal set if ((item.ContainsKey("CategoryL1") || item.ContainsKey("CategoryL2")) && !item.ContainsKey("GoalSet")) { importErrors.Messages.Add(string.Format(ERR_MISSING_GOALSET_VALUE, itemCount + 1)); importErrors.SkippedRowCount++; } else { // have CL2 missing CL1 if (item.ContainsKey("CategoryL2") && !item.ContainsKey("CategoryL1")) { importErrors.Messages.Add(string.Format(ERR_MISSING_CATEGORY_VALUE, itemCount + 1)); importErrors.SkippedRowCount++; success = false; } else { // we do have a CL1 if (item.ContainsKey("CategoryL1")) { // get the mapped value CategoryL1 CL1 = domainManager.CategoryL1Repository.Items.Find(cl1 => cl1.KPID.ToString() == item["CategoryL1"].Value); // if we have one check if the CategoryL1 is in the GoalSet if (CL1 == null || CL1.GoalSetId.ToString() != item["GoalSet"].Value) { importErrors.Messages.Add(string.Format(ERR_CATL1_MISMATCH, itemCount, originalLookup["CategoryL1"])); importErrors.SkippedColumns.Add("Category L1: [No GoalSet]"); item["CategoryL1"].Value = string.Empty; categoryL1Invalid = true; success = false; } } if (item.ContainsKey("CategoryL2")) { if (!categoryL1Invalid) { CategoryL2 CL2 = domainManager.CategoryL2Repository.Items.Find(cl2 => cl2.KPID.ToString() == item["CategoryL2"].Value); // check if the CategoryL2 is in the CategoryL1 if (CL2 == null || CL2.CategoryL1Id.ToString() != item["CategoryL1"].Value) { importErrors.Messages.Add(string.Format(ERR_CATL2_MISMATCH, itemCount, originalLookup["CategoryL2"])); importErrors.SkippedColumns.Add("Category L2: [Invalid]"); item["CategoryL2"].Value = string.Empty; success = false; } } else { importErrors.Messages.Add(string.Format(ERR_CATL1_INVALID, itemCount, originalLookup["CategoryL2"])); importErrors.SkippedColumns.Add("Category L2: [No Category L1]"); item["CategoryL2"].Value = string.Empty; success = false; } } itemCount++; } } return(success); }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="entityName"></param> /// <param name="dataMsg"></param> /// <returns></returns> public Message SaveLookup(WebOperationContext ctx, string entityName, Message dataMsg) { Message responseMsg = null; string jsonData = JSON.GetPayload(dataMsg); try { switch (entityName) { case "EntityLinks": EntityLinks entityLinks = this.SaveLookup <EntityLinks>(entityName, jsonData); responseMsg = HttpUtilities.GenerateResponse <EntityLinks>(ctx, entityLinks, this.timer); break; case "EventLogging": EventLogger eventLogger = this.SaveLookup <EventLogger>(entityName, jsonData); responseMsg = HttpUtilities.GenerateResponse <EventLogger>(ctx, eventLogger, this.timer); break; case "KPAdmins": Admin kpAdmin = this.SaveLookup <Admin>(entityName, jsonData); responseMsg = HttpUtilities.GenerateResponse <Admin>(ctx, kpAdmin, this.timer); break; case "KPCategoryL1": CategoryL1 kpCatL1 = this.SaveLookup <CategoryL1>(entityName, jsonData); responseMsg = HttpUtilities.GenerateResponse <CategoryL1>(ctx, kpCatL1, this.timer); break; case "KPCategoryL2": CategoryL2 kpCatL2 = this.SaveLookup <CategoryL2>(entityName, jsonData); responseMsg = HttpUtilities.GenerateResponse <CategoryL2>(ctx, kpCatL2, this.timer); break; case "KPConfigList": ConfigList kpConfigList = this.SaveLookup <ConfigList>(entityName, jsonData); responseMsg = HttpUtilities.GenerateResponse <ConfigList>(ctx, kpConfigList, this.timer); break; //case "KPCountry": // Country kpCountry = this.SaveLookup<Country>(entityName, jsonData); // responseMsg = ctx.CreateJsonResponse<Country>(kpCountry); // break; case "KPCustomers": Customer kpCustomers = this.SaveLookup <Customer>(entityName, jsonData); responseMsg = HttpUtilities.GenerateResponse <Customer>(ctx, kpCustomers, this.timer); break; //case "KPEffortInstances": // EffortInstance kpEffortInstances = this.SaveLookup<EffortInstance>(entityName, jsonData); // responseMsg = ctx.CreateJsonResponse<EffortInstance>(kpEffortInstances); // break; //case "KPEfforts": // Effort kpEfforts = this.SaveLookup<Effort>(entityName, jsonData); // responseMsg = ctx.CreateJsonResponse<Effort>(kpEfforts); // break; case "KPGoalSetLocks": GoalSetLock kpGoalSetLock = this.SaveLookup <GoalSetLock>(entityName, jsonData); responseMsg = HttpUtilities.GenerateResponse <GoalSetLock>(ctx, kpGoalSetLock, this.timer); break; case "KPGoalSets": GoalSet kpGoalSet = this.SaveLookup <GoalSet>(entityName, jsonData); responseMsg = HttpUtilities.GenerateResponse <GoalSet>(ctx, kpGoalSet, this.timer); break; //case "KPPerspectives": // Perspective kpPerspective = this.SaveLookup<Perspective>(entityName, jsonData); // responseMsg = ctx.CreateJsonResponse<Perspective>(kpPerspective); // break; case "KPPerspectiveInstances": PerspectiveInstance kpPerspectiveInstance = this.SaveLookup <PerspectiveInstance>(entityName, jsonData); responseMsg = HttpUtilities.GenerateResponse <PerspectiveInstance>(ctx, kpPerspectiveInstance, this.timer); break; case "KingpinLockdown": KingpinLockdown lockdown = this.SaveLookup <KingpinLockdown>(entityName, jsonData); responseMsg = HttpUtilities.GenerateResponse <KingpinLockdown>(ctx, lockdown, this.timer); break; case "Announcements": Announcement announcement = this.SaveLookup <Announcement>(entityName, jsonData); responseMsg = HttpUtilities.GenerateResponse <Announcement>(ctx, announcement, this.timer); break; case "KPTeams": Team kpTeam = this.SaveLookup <Team>(entityName, jsonData); responseMsg = HttpUtilities.GenerateResponse <Team>(ctx, kpTeam, this.timer); break; case "KPVPs": VP kpVP = this.SaveLookup <VP>(entityName, jsonData); responseMsg = HttpUtilities.GenerateResponse <VP>(ctx, kpVP, this.timer); break; case "OneOffConfigurations": OneOffConfiguration oneOffConfiguration = this.SaveLookup <OneOffConfiguration>(entityName, jsonData); responseMsg = HttpUtilities.GenerateResponse <OneOffConfiguration>(ctx, oneOffConfiguration, this.timer); break; case "UserEventLogging": UserLogging userEvent = this.SaveLookup <UserLogging>(entityName, jsonData); responseMsg = HttpUtilities.GenerateResponse <UserLogging>(ctx, userEvent, this.timer); break; default: string errMsg = string.Format("Error: No lookup list found with the name: {0}", entityName); responseMsg = HttpUtilities.GenerateExceptionResponse(ctx, new Exception(errMsg), "POST/PUT", HttpStatusCode.BadRequest); break; } } catch (Exception ex) { responseMsg = HttpUtilities.GenerateExceptionResponse(ctx, ex, "POST/PUT", HttpStatusCode.InternalServerError); } this.timer.Stop(); return(responseMsg); }
/// <summary> /// Gets the lookup value for an item field /// TODO: Create an IRespository /// </summary> /// <param name="fieldName"></param> /// <param name="fieldValue"></param> /// <returns></returns> public string GetLookupValue(string fieldName, string fieldValue, string lookupField) { string value = string.Empty; switch (fieldName) { case "KPTeam": Team team = this.spDataAccess.Teams.Find(i => i.Nick == fieldValue || i.Title == fieldValue); value = (team != null) ? team.KPID.ToString() : string.Empty; break; case "GoalSet": GoalSet goalSet = this.GoalSetRepository.Items.Find(i => i.Title == fieldValue); value = (goalSet != null) ? goalSet.KPID.ToString() : string.Empty; break; case "KPPrimaryVP": VP vp = this.VPRepository.Items.Find(i => i.Nick == fieldValue); value = (vp != null) ? vp.KPID.ToString() : string.Empty; break; case "KPSecondaryVPs": // handle multiple string[] values; List <string> newValues = new List <string>(); if (fieldValue.Contains(",")) { values = fieldValue.Split(','); foreach (string val in values) { VP svp = this.VPRepository.Items.Find(i => i.Nick == val); value = (svp != null) ? svp.KPID.ToString() : string.Empty; // leave loop since we have a value mismatch if (string.IsNullOrEmpty(value)) { break; } // otherwise we'll continue adding values newValues.Add(value); value = string.Join(",", newValues.ToArray()); } } else { VP svp = this.VPRepository.Items.Find(i => i.Nick == fieldValue); value = (svp != null) ? svp.KPID.ToString() : string.Empty; } break; case "CategoryL1": CategoryL1 catL1 = this.CategoryL1Repository.Items.Find(i => i.Title == fieldValue); value = (catL1 != null) ? catL1.KPID.ToString() : string.Empty; break; case "CategoryL2": CategoryL2 catL2 = this.CategoryL2Repository.Items.Find(i => i.Title == fieldValue); value = (catL2 != null) ? catL2.KPID.ToString() : string.Empty; break; } return(value); }