public void SuffixToIndexDoubleCharTest() { var result = PartSuffixGenerator.SuffixToIndex("BA"); Assert.AreEqual(26, result); result = PartSuffixGenerator.SuffixToIndex("BB"); Assert.AreEqual(27, result); result = PartSuffixGenerator.SuffixToIndex("ZZ"); Assert.AreEqual(675, result); }
public void SuffixToIndexSingleCharTest() { var result = PartSuffixGenerator.SuffixToIndex("A"); Assert.AreEqual(0, result); result = PartSuffixGenerator.SuffixToIndex("B"); Assert.AreEqual(1, result); result = PartSuffixGenerator.SuffixToIndex("Z"); Assert.AreEqual(25, result); }
public async Task <IActionResult> Initialize(WorkType workType, Guid id, [Bind("WorkItemId,WorkItem,StaticPartInfoId,NumPartsForWork,StartDate,CompleteDate,ProcessSheetNotesFile,WorkId")] WorkItemViewModel vm) { if (id != vm.WorkItemId) { return(NotFound()); } ViewBag.WorkType = workType; var resultList = await _repo.GetPartsForWorksWithPartInfo(vm.StaticPartInfoId); var count = resultList.Count(); int max = 0; foreach (PartForWork pForWork in resultList) { var temp = PartSuffixGenerator.SuffixToIndex(pForWork.Suffix); if (temp > max) { max = temp; } } if (ModelState.IsValid) { var workItem = await _repo.GetWorkItem(vm.WorkItemId); workItem.StaticPartInfoId = vm.StaticPartInfoId; workItem.StartDate = vm.StartDate; workItem.InvoiceDate = vm.CompleteDate; workItem.IsInitialized = true; // look to see if this part/job already exists. If so, name suffix from that point var existingBatch = await _repo.GetExistingPartBatch((Guid)workItem.WorkId); var initCount = vm.NumPartsForWork; vm.NumPartsForWork += existingBatch.Count(); // update the number of parts in each PartForJob foreach (PartForWork part in existingBatch) { vm.NumPartsForWork += existingBatch.Count(); } if (workItem.ProcessSheetNotesFile != null) { workItem.ProcessSheetNotesPdfBytes = await FileURL.GetFileBytes(workItem.ProcessSheetNotesFile); } // create each part for the part batch for (int i = count; i < initCount + count; i++) { try { var tempPartForWork = new PartForWork { PartForWorkId = Guid.NewGuid(), WorkItemId = workItem.WorkItemId, }; tempPartForWork.Suffix = Utility.PartSuffixGenerator.IndexToSuffix(i); tempPartForWork.PartForWorkId = Guid.NewGuid(); SetUIDs(); await _repo.AddPartForWork(tempPartForWork); } catch (Exception ex) { ex.ToString(); continue; } } await _repo.UpdateWorkItem(workItem); return(RedirectToAction("Index", "WorkItems", new { workType = workType, workId = workItem.WorkId })); } return(View(vm)); }