/// <summary> /// Copy Block item of LocalAreaRotationList item /// </summary> /// <param name="dbContext"></param> /// <param name="oldObject"></param> /// <param name="instance"></param> /// <param name="systemId"></param> private static void CopyToInstance(DbAppContext dbContext, Block oldObject, ref LocalAreaRotationList instance, string systemId) { if (oldObject.Area_Id <= 0) { return; } // add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database User createdBy = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId); int equipmentTypeId = oldObject.Equip_Type_Id ?? 0; int blockNum = Convert.ToInt32(float.Parse(oldObject.Block_Num == null ? "0.0" : oldObject.Block_Num)); if (instance == null) { instance = new LocalAreaRotationList(); DistrictEquipmentType disEquipType = dbContext.DistrictEquipmentTypes.FirstOrDefault(x => x.Id == equipmentTypeId); if (disEquipType != null) { instance.DistrictEquipmentType = disEquipType; instance.DistrictEquipmentTypeId = disEquipType.Id; } // extract AskNextBlock*Id which is the secondary key of Equip.Id int equipId = oldObject.Last_Hired_Equip_Id ?? 0; if (dbContext.Equipments.Any(x => x.Id == equipId)) { switch (blockNum) { case 1: instance.AskNextBlockOpenId = equipId; break; case 2: instance.AskNextBlock1Id = equipId; break; case 3: instance.AskNextBlock2Id = equipId; break; } } instance.CreateUserid = createdBy.SmUserId; if (oldObject.Created_Dt != null) { instance.CreateTimestamp = DateTime.ParseExact(oldObject.Created_Dt.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); } dbContext.LocalAreaRotationLists.Add(instance); } }
/// <summary> /// Get local area rotation list by id /// </summary> /// <param name="id">id of DumpTruck to fetch</param> /// <response code="200">OK</response> /// <response code="404">DumpTruck not found</response> public virtual IActionResult LocalarearotationlistsIdGetAsync(int id) { bool exists = _context.LocalAreaRotationLists.Any(a => a.Id == id); if (exists) { LocalAreaRotationList result = _context.LocalAreaRotationLists.First(a => a.Id == id); return(new ObjectResult(new HetsResponse(result))); } // record not found return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration)))); }
/// <summary> /// /// </summary> /// <param name="item"></param> /// <response code="201">DumpTruck created</response> public virtual IActionResult LocalarearotationlistsPostAsync(LocalAreaRotationList item) { var exists = _context.LocalAreaRotationLists.Any(a => a.Id == item.Id); if (exists) { _context.LocalAreaRotationLists.Update(item); } else { // record not found _context.LocalAreaRotationLists.Add(item); } // Save the changes _context.SaveChanges(); return(new ObjectResult(item)); }
/// <summary> /// /// </summary> /// <param name="id">id of DumpTruck to fetch</param> /// <param name="item"></param> /// <response code="200">OK</response> /// <response code="404">DumpTruck not found</response> public virtual IActionResult LocalarearotationlistsIdPutAsync(int id, LocalAreaRotationList item) { var exists = _context.LocalAreaRotationLists.Any(a => a.Id == id); if (exists && id == item.Id) { _context.LocalAreaRotationLists.Update(item); // Save the changes _context.SaveChanges(); return(new ObjectResult(item)); } else { // record not found return(new StatusCodeResult(404)); } }
/// <summary> /// Update local area rotation list /// </summary> /// <param name="id">id of DumpTruck to fetch</param> /// <param name="item"></param> /// <response code="200">OK</response> /// <response code="404">DumpTruck not found</response> public virtual IActionResult LocalarearotationlistsIdPutAsync(int id, LocalAreaRotationList item) { bool exists = _context.LocalAreaRotationLists.Any(a => a.Id == id); if (exists && id == item.Id) { _context.LocalAreaRotationLists.Update(item); // Save the changes _context.SaveChanges(); return(new ObjectResult(new HetsResponse(item))); } // record not found return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration)))); }
/// <summary> /// Delete local area rotation list /// </summary> /// <param name="id">id of DumpTruck to delete</param> /// <response code="200">OK</response> /// <response code="404">DumpTruck not found</response> public virtual IActionResult LocalarearotationlistsIdDeletePostAsync(int id) { bool exists = _context.LocalAreaRotationLists.Any(a => a.Id == id); if (exists) { LocalAreaRotationList item = _context.LocalAreaRotationLists.First(a => a.Id == id); if (item != null) { _context.LocalAreaRotationLists.Remove(item); // Save the changes _context.SaveChanges(); } return(new ObjectResult(new HetsResponse(item))); } // record not found return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration)))); }
private void BuildRentalRequestRotationList(RentalRequest item) { // validate input parameters if (item != null && item.LocalArea != null && item.DistrictEquipmentType != null && item.DistrictEquipmentType.EquipmentType != null) { int currentSortOrder = 1; item.RentalRequestRotationList = new List <RentalRequestRotationList>(); // first get the localAreaRotationList.askNextBlock1 for the given local area. LocalAreaRotationList localAreaRotationList = _context.LocalAreaRotationLists .Include(x => x.LocalArea) .Include(x => x.AskNextBlock1) .Include(x => x.AskNextBlock2) .Include(x => x.AskNextBlockOpen) .FirstOrDefault(x => x.LocalArea.Id == item.LocalArea.Id); int numberOfBlocks = item.DistrictEquipmentType.EquipmentType.NumberOfBlocks; for (int currentBlock = 1; currentBlock <= numberOfBlocks; currentBlock++) { // start by getting the current set of equipment for the given equipment type List <Equipment> blockEquipment = _context.Equipments .Where(x => x.DistrictEquipmentType == item.DistrictEquipmentType && x.BlockNumber == currentBlock && x.LocalArea.Id == item.LocalArea.Id) .OrderByDescending(x => x.Seniority) .ToList(); int listSize = blockEquipment.Count; // find the starting position. int currentPosition = 0; Equipment seeking = null; if (localAreaRotationList != null) { switch (currentBlock) { case 1: seeking = localAreaRotationList.AskNextBlock1; break; case 2: seeking = localAreaRotationList.AskNextBlock2; break; case 3: seeking = localAreaRotationList.AskNextBlockOpen; break; } } if (localAreaRotationList != null && seeking != null) { for (int i = 0; i < listSize; i++) { if (blockEquipment[i] != null && blockEquipment[i].Id == seeking.Id) { currentPosition = i; } } } // next pass sets the rotation list sort order. for (int i = 0; i < listSize; i++) { RentalRequestRotationList rentalRequestRotationList = new RentalRequestRotationList(); rentalRequestRotationList.Equipment = blockEquipment[currentPosition]; rentalRequestRotationList.CreateTimestamp = DateTime.UtcNow; rentalRequestRotationList.RotationListSortOrder = currentSortOrder; item.RentalRequestRotationList.Add(rentalRequestRotationList); currentPosition++; currentSortOrder++; if (currentPosition >= listSize) { currentPosition = 0; } } } } }
/// <summary> /// Import Rotaion List /// </summary> /// <param name="performContext"></param> /// <param name="dbContext"></param> /// <param name="fileLocation"></param> /// <param name="systemId"></param> public static void Import(PerformContext performContext, DbAppContext dbContext, string fileLocation, string systemId) { // check the start point. If startPoint == sigId then it is already completed int startPoint = ImportUtility.CheckInterMapForStartPoint(dbContext, OldTableProgress, BCBidImport.SigId); if (startPoint == BCBidImport.SigId) // this means the import job it has done today is complete for all the records in the xml file. { performContext.WriteLine("*** Importing " + XmlFileName + " is complete from the former process ***"); return; } try { string rootAttr = "ArrayOf" + OldTable; //Create Processer progress indicator performContext.WriteLine("Processing " + OldTable); IProgressBar progress = performContext.WriteProgressBar(); progress.SetValue(0); // create serializer and serialize xml file XmlSerializer ser = new XmlSerializer(typeof(Block[]), new XmlRootAttribute(rootAttr)); MemoryStream memoryStream = ImportUtility.MemoryStreamGenerator(XmlFileName, OldTable, fileLocation, rootAttr); Block[] legacyItems = (Block[])ser.Deserialize(memoryStream); int ii = startPoint; // skip the portion already processed if (startPoint > 0) { legacyItems = legacyItems.Skip(ii).ToArray(); } foreach (Block item in legacyItems.WithProgress(progress)) { int areaId = item.Area_Id ?? 0; int equipmentTypeId = item.Equip_Type_Id ?? 0; int blockNum = Convert.ToInt32(float.Parse(item.Block_Num ?? "0.0")); // this is for conversion record hope this is unique string oldUniqueId = ((areaId * 10000 + equipmentTypeId) * 100 + blockNum).ToString(); // see if we have this one already ImportMap importMap = dbContext.ImportMaps.FirstOrDefault(x => x.OldTable == OldTable && x.OldKey == oldUniqueId); // new entry if (importMap == null) { if (areaId > 0) { LocalAreaRotationList instance = null; CopyToInstance(dbContext, item, ref instance, systemId); ImportUtility.AddImportMap(dbContext, OldTable, oldUniqueId, NewTable, instance.Id); } } else // update { LocalAreaRotationList instance = dbContext.LocalAreaRotationLists.FirstOrDefault(x => x.Id == importMap.NewKey); // record was deleted if (instance == null) { CopyToInstance(dbContext, item, ref instance, systemId); // update the import map importMap.NewKey = instance.Id; dbContext.ImportMaps.Update(importMap); } else // ordinary update { CopyToInstance(dbContext, item, ref instance, systemId); // touch the import map importMap.LastUpdateTimestamp = DateTime.UtcNow; dbContext.ImportMaps.Update(importMap); } } // save change to database periodically to avoid frequent writing to the database if (++ii % 500 == 0) { try { ImportUtility.AddImportMapForProgress(dbContext, OldTableProgress, ii.ToString(), BCBidImport.SigId); dbContext.SaveChangesForImport(); } catch (Exception e) { performContext.WriteLine("Error saving data " + e.Message); } } } try { performContext.WriteLine("*** Importing " + XmlFileName + " is Done ***"); ImportUtility.AddImportMapForProgress(dbContext, OldTableProgress, BCBidImport.SigId.ToString(), BCBidImport.SigId); dbContext.SaveChangesForImport(); } catch (Exception e) { performContext.WriteLine("Error saving data " + e.Message); } } catch (Exception e) { performContext.WriteLine("*** ERROR ***"); performContext.WriteLine(e.ToString()); } }
public virtual IActionResult LocalarearotationlistsIdPut([FromRoute] int id, [FromBody] LocalAreaRotationList item) { return(this._service.LocalarearotationlistsIdPutAsync(id, item)); }
public virtual IActionResult LocalarearotationlistsPost([FromBody] LocalAreaRotationList item) { return(this._service.LocalarearotationlistsPostAsync(item)); }
/// <summary> /// Update the Local Area Rotation List /// </summary> /// <param name="item"></param> /// <param name="numberOfBlocks"></param> private void UpdateLocalAreaRotationList(RentalRequest item, int numberOfBlocks) { // ******************************************************************************* // first get the localAreaRotationList.askNextBlock"N" for the given local area // ******************************************************************************* bool exists = _context.LocalAreaRotationLists.Any(a => a.LocalArea.Id == item.LocalArea.Id); LocalAreaRotationList localAreaRotationList = new LocalAreaRotationList(); if (exists) { localAreaRotationList = _context.LocalAreaRotationLists .AsNoTracking() .Include(x => x.LocalArea) .Include(x => x.AskNextBlock1) .Include(x => x.AskNextBlock2) .Include(x => x.AskNextBlockOpen) .FirstOrDefault(x => x.LocalArea.Id == item.LocalArea.Id && x.DistrictEquipmentTypeId == item.DistrictEquipmentTypeId); } // determine what the next id is int?nextId = null; if (localAreaRotationList != null && localAreaRotationList.Id > 0) { if (localAreaRotationList.AskNextBlock1Id != null) { nextId = localAreaRotationList.AskNextBlock1Id; } else if (localAreaRotationList.AskNextBlock2Id != null) { nextId = localAreaRotationList.AskNextBlock2Id; } else { nextId = localAreaRotationList.AskNextBlockOpenId; } } // ******************************************************************************* // populate: // 1. the "next on the list" table for the Local Area // (HET_LOCAL_AREA_ROTATION_LIST) // 2. the first on the list id for the Rental Request // (HET_RENTAL_REQUEST.FIRST_ON_ROTATION_LIST_ID) // ******************************************************************************* if (item.RentalRequestRotationList.Count > 0) { item.RentalRequestRotationList = item.RentalRequestRotationList.OrderBy(x => x.RotationListSortOrder).ToList(); item.FirstOnRotationListId = item.RentalRequestRotationList[0].Equipment.Id; LocalAreaRotationList newAreaRotationList = new LocalAreaRotationList { LocalAreaId = item.LocalAreaId, DistrictEquipmentTypeId = item.DistrictEquipmentTypeId }; if (nextId != null) { newAreaRotationList.Id = localAreaRotationList.Id; newAreaRotationList.AskNextBlock1 = localAreaRotationList.AskNextBlock1; newAreaRotationList.AskNextBlock1Id = localAreaRotationList.AskNextBlock1Id; newAreaRotationList.AskNextBlock1Seniority = localAreaRotationList.AskNextBlock1Seniority; newAreaRotationList.AskNextBlock2 = localAreaRotationList.AskNextBlock2; newAreaRotationList.AskNextBlock2Id = localAreaRotationList.AskNextBlock2Id; newAreaRotationList.AskNextBlock2Seniority = localAreaRotationList.AskNextBlock2Seniority; newAreaRotationList.AskNextBlockOpen = localAreaRotationList.AskNextBlockOpen; newAreaRotationList.AskNextBlockOpenId = localAreaRotationList.AskNextBlockOpenId; } // find our next record int nextRecordToAskIndex = 0; bool foundCurrentRecord = false; if (nextId != null) { for (int i = 0; i < item.RentalRequestRotationList.Count; i++) { bool forcedHire; bool hired; if (foundCurrentRecord && item.RentalRequestRotationList[i].IsForceHire == null || item.RentalRequestRotationList[i].IsForceHire == false) { forcedHire = false; } else { forcedHire = true; } if (foundCurrentRecord && item.RentalRequestRotationList[i].OfferResponse == null || !item.RentalRequestRotationList[i].OfferResponse.Equals("Yes", StringComparison.InvariantCultureIgnoreCase)) { hired = false; } else { hired = true; } if (foundCurrentRecord && !forcedHire && !hired) { // we've found our next record - exit and update the lists nextRecordToAskIndex = i; break; } if (!foundCurrentRecord && item.RentalRequestRotationList[i].Equipment.Id == nextId) { foundCurrentRecord = true; } } } if (item.RentalRequestRotationList[nextRecordToAskIndex].Equipment.BlockNumber == 1 && item.RentalRequestRotationList[nextRecordToAskIndex].Equipment.BlockNumber <= numberOfBlocks) { newAreaRotationList.AskNextBlock1 = item.RentalRequestRotationList[nextRecordToAskIndex].Equipment; newAreaRotationList.AskNextBlock1Id = newAreaRotationList.AskNextBlock1.Id; newAreaRotationList.AskNextBlock1Seniority = item.RentalRequestRotationList[nextRecordToAskIndex].Equipment.Seniority; newAreaRotationList.AskNextBlock2Id = null; newAreaRotationList.AskNextBlock2Seniority = null; newAreaRotationList.AskNextBlockOpenId = null; } else if (item.RentalRequestRotationList[nextRecordToAskIndex].Equipment.BlockNumber == 2 && item.RentalRequestRotationList[nextRecordToAskIndex].Equipment.BlockNumber <= numberOfBlocks) { newAreaRotationList.AskNextBlock2 = item.RentalRequestRotationList[nextRecordToAskIndex].Equipment; newAreaRotationList.AskNextBlock2Id = newAreaRotationList.AskNextBlock2.Id; newAreaRotationList.AskNextBlock2Seniority = item.RentalRequestRotationList[nextRecordToAskIndex].Equipment.Seniority; newAreaRotationList.AskNextBlock1Id = null; newAreaRotationList.AskNextBlock1Seniority = null; newAreaRotationList.AskNextBlockOpenId = null; } else { newAreaRotationList.AskNextBlockOpen = item.RentalRequestRotationList[nextRecordToAskIndex].Equipment; newAreaRotationList.AskNextBlockOpenId = newAreaRotationList.AskNextBlockOpen.Id; newAreaRotationList.AskNextBlock1Id = null; newAreaRotationList.AskNextBlock1Seniority = null; newAreaRotationList.AskNextBlock2Id = null; newAreaRotationList.AskNextBlock2Seniority = null; } if (nextId == null) { _context.LocalAreaRotationLists.Add(newAreaRotationList); } else { _context.LocalAreaRotationLists.Update(newAreaRotationList); } } }
/// <summary> /// Import Rotaion List /// </summary> /// <param name="performContext"></param> /// <param name="dbContext"></param> /// <param name="fileLocation"></param> /// <param name="systemId"></param> public static void Import(PerformContext performContext, DbAppContext dbContext, string fileLocation, string systemId) { // check the start point. If startPoint == sigId then it is already completed int startPoint = ImportUtility.CheckInterMapForStartPoint(dbContext, OldTableProgress, BcBidImport.SigId, NewTable); if (startPoint == BcBidImport.SigId) // this means the import job it has done today is complete for all the records in the xml file. { performContext.WriteLine("*** Importing " + XmlFileName + " is complete from the former process ***"); return; } int maxBlockIndex = 0; if (dbContext.RentalRequestRotationLists.Any()) { maxBlockIndex = dbContext.RentalRequestRotationLists.Max(x => x.Id); } try { string rootAttr = "ArrayOf" + OldTable; //Create Processer progress indicator performContext.WriteLine("Processing " + OldTable); IProgressBar progress = performContext.WriteProgressBar(); progress.SetValue(0); // create serializer and serialize xml file XmlSerializer ser = new XmlSerializer(typeof(Block[]), new XmlRootAttribute(rootAttr)); MemoryStream memoryStream = ImportUtility.MemoryStreamGenerator(XmlFileName, OldTable, fileLocation, rootAttr); Block[] legacyItems = (Block[])ser.Deserialize(memoryStream); int ii = startPoint; // skip the portion already processed if (startPoint > 0) { legacyItems = legacyItems.Skip(ii).ToArray(); } Debug.WriteLine("Importing Block Data. Total Records: " + legacyItems.Length); foreach (Block item in legacyItems.WithProgress(progress)) { string areaId = item.Area_Id.ToString(); string equipmentTypeId = item.Equip_Type_Id.ToString(); string createdDate = item.Created_Dt; string oldUniqueId = string.Format("{0}-{1}-{2}", areaId, equipmentTypeId, createdDate); // see if we have this one already ImportMap importMap = dbContext.ImportMaps.FirstOrDefault(x => x.OldTable == OldTable && x.OldKey == oldUniqueId); // new entry if (importMap == null && item.Area_Id > 0) { LocalAreaRotationList instance = null; CopyToInstance(dbContext, item, ref instance, systemId, ref maxBlockIndex); if (instance != null) { ImportUtility.AddImportMap(dbContext, OldTable, oldUniqueId, NewTable, instance.Id); } } // save change to database periodically to avoid frequent writing to the database if (++ii % 500 == 0) { try { ImportUtility.AddImportMapForProgress(dbContext, OldTableProgress, ii.ToString(), BcBidImport.SigId, NewTable); dbContext.SaveChangesForImport(); } catch (Exception e) { performContext.WriteLine("Error saving data " + e.Message); } } } try { performContext.WriteLine("*** Importing " + XmlFileName + " is Done ***"); ImportUtility.AddImportMapForProgress(dbContext, OldTableProgress, BcBidImport.SigId.ToString(), BcBidImport.SigId, NewTable); dbContext.SaveChangesForImport(); } catch (Exception e) { string temp = string.Format("Error saving data (BlockIndex: {0}): {1}", maxBlockIndex, e.Message); performContext.WriteLine(temp); throw new DataException(temp); } } catch (Exception e) { performContext.WriteLine("*** ERROR ***"); performContext.WriteLine(e.ToString()); throw; } }
/// <summary> /// Copy Block item of LocalAreaRotationList item /// </summary> /// <param name="dbContext"></param> /// <param name="oldObject"></param> /// <param name="rotationList"></param> /// <param name="systemId"></param> /// <param name="maxBlockIndex"></param> private static void CopyToInstance(DbAppContext dbContext, Block oldObject, ref LocalAreaRotationList rotationList, string systemId, ref int maxBlockIndex) { try { bool isNew = false; if (oldObject.Area_Id <= 0) { return; // ignore these records } if (oldObject.Equip_Type_Id <= 0) { return; // ignore these records } if (oldObject.Last_Hired_Equip_Id <= 0) { return; // ignore these records } // *********************************************** // we only need records from the current fiscal // so ignore all others // *********************************************** DateTime fiscalStart; DateTime fiscalEnd; if (DateTime.UtcNow.Month == 1 || DateTime.UtcNow.Month == 2 || DateTime.UtcNow.Month == 3) { fiscalEnd = new DateTime(DateTime.UtcNow.Year, 3, 31); } else { fiscalEnd = new DateTime(DateTime.UtcNow.AddYears(1).Year, 3, 31); } if (DateTime.UtcNow.Month == 1 || DateTime.UtcNow.Month == 2 || DateTime.UtcNow.Month == 3) { fiscalStart = new DateTime(DateTime.UtcNow.AddYears(-1).Year, 4, 1); } else { fiscalStart = new DateTime(DateTime.UtcNow.Year, 4, 1); } string tempRecordDate = oldObject.Created_Dt; if (string.IsNullOrEmpty(tempRecordDate)) { return; // ignore if we don't have a created date } if (!string.IsNullOrEmpty(tempRecordDate)) { DateTime?recordDate = ImportUtility.CleanDateTime(tempRecordDate); if (recordDate == null || recordDate < fiscalStart || recordDate > fiscalEnd) { return; // ignore this record - it is outside of the current fiscal year } } // *********************************************** // get the area record // *********************************************** string tempOldAreaId = oldObject.Area_Id.ToString(); ImportMap mapArea = dbContext.ImportMaps.AsNoTracking() .FirstOrDefault(x => x.OldKey == tempOldAreaId && x.OldTable == ImportLocalArea.OldTable && x.NewTable == ImportLocalArea.NewTable); if (mapArea == null) { throw new DataException(string.Format("Area Id cannot be null (BlockIndex: {0})", maxBlockIndex)); } LocalArea area = dbContext.LocalAreas.AsNoTracking() .FirstOrDefault(x => x.Id == mapArea.NewKey); if (area == null) { throw new ArgumentException(string.Format("Cannot locate Local Area record (Local Area Id: {0})", tempOldAreaId)); } // *********************************************** // get the equipment type record // *********************************************** string tempOldEquipTypeId = oldObject.Equip_Type_Id.ToString(); ImportMap mapEquipType = dbContext.ImportMaps.AsNoTracking() .FirstOrDefault(x => x.OldKey == tempOldEquipTypeId && x.OldTable == ImportDistrictEquipmentType.OldTable && x.NewTable == ImportDistrictEquipmentType.NewTable); if (mapEquipType == null) { throw new DataException(string.Format("Equipment Type Id cannot be null (BlockIndex: {0})", maxBlockIndex)); } DistrictEquipmentType equipmentType = dbContext.DistrictEquipmentTypes.AsNoTracking() .FirstOrDefault(x => x.Id == mapEquipType.NewKey); if (equipmentType == null) { throw new ArgumentException(string.Format("Cannot locate District Equipment Type record (Equipment Type Id: {0})", tempOldEquipTypeId)); } // *********************************************** // see if a record already exists // *********************************************** rotationList = dbContext.LocalAreaRotationLists .FirstOrDefault(x => x.LocalAreaId == area.Id && x.DistrictEquipmentTypeId == equipmentType.Id); if (rotationList == null) { isNew = true; // create new list rotationList = new LocalAreaRotationList { Id = ++maxBlockIndex, LocalAreaId = area.Id, DistrictEquipmentTypeId = equipmentType.Id, AppCreateUserid = systemId, AppCreateTimestamp = DateTime.UtcNow }; } else { // record already exists - just testing updates Debug.WriteLine("Record Id: " + rotationList.Id); } // *********************************************** // get the equipment record // *********************************************** string tempOldEquipId = oldObject.Last_Hired_Equip_Id.ToString(); ImportMap mapEquip = dbContext.ImportMaps.AsNoTracking() .FirstOrDefault(x => x.OldKey == tempOldEquipId && x.OldTable == ImportEquip.OldTable && x.NewTable == ImportEquip.NewTable); if (mapEquip == null) { throw new DataException(string.Format("Equipment Id cannot be null (BlockIndex: {0})", maxBlockIndex)); } Equipment equipment = dbContext.Equipments.AsNoTracking() .FirstOrDefault(x => x.Id == mapEquip.NewKey); if (equipment == null) { throw new ArgumentException(string.Format("Cannot locate Equipment record (Equipment Id: {0})", tempOldEquipId)); } // *********************************************** // update the "Ask Next" values // *********************************************** float?blockNum = ImportUtility.GetFloatValue(oldObject.Block_Num); if (blockNum == null) { throw new DataException(string.Format("Block Number cannot be null (BlockIndex: {0}", maxBlockIndex)); } // extract AskNextBlock*Id which is the secondary key of Equip.Id switch (blockNum) { case 1: rotationList.AskNextBlock1Id = equipment.Id; rotationList.AskNextBlock1Seniority = equipment.Seniority; break; case 2: rotationList.AskNextBlock2Id = equipment.Id; rotationList.AskNextBlock2Seniority = equipment.Seniority; break; case 3: rotationList.AskNextBlockOpenId = equipment.Id; break; } // *********************************************** // update or create equipment // *********************************************** equipment.AppLastUpdateUserid = systemId; equipment.AppLastUpdateTimestamp = DateTime.UtcNow; if (isNew) { dbContext.LocalAreaRotationLists.Add(rotationList); } else { dbContext.LocalAreaRotationLists.Update(rotationList); } } catch (Exception ex) { Debug.WriteLine("***Error*** - Master Block Index: " + maxBlockIndex); Debug.WriteLine(ex.Message); throw; } }
/// <summary> /// /// </summary> /// <param name="id">id of LocalAreaRotationList to fetch</param> /// <param name="item"></param> /// <response code="200">OK</response> /// <response code="404">LocalAreaRotationList not found</response> public virtual IActionResult LocalarearotationlistsIdPutAsync(int id, LocalAreaRotationList item) { var result = ""; return(new ObjectResult(result)); }
/// <summary> /// Setup the test. /// </summary> public LocalAreaRotationListModelTests() { instance = new LocalAreaRotationList(); }