private CompartSearchViewModel CompartViewModelConverter(LU_COMPART item) { var make = item.TRACK_COMPART_EXT.FirstOrDefault(t => t.compartid_auto == item.compartid_auto)?.MAKE; var makeName = ""; var makeid = 0; if (make != null) { makeName = make.makedesc; makeid = make.make_auto; } return(new CompartSearchViewModel { CompartId = item.compartid_auto, CompartName = item.compart, CompartType = ((CompartTypeEnum)item.comparttype_auto).ToString(), Make = makeName, Models = _context.TRACK_COMPART_MODEL_MAPPING.FirstOrDefault(m => m.compartid_auto == item.compartid_auto)?.Model?.modeldesc, MakeId = makeid, }); }
/// <summary> /// By using this method parent of the current compart will be set or updated /// This method will be used for mining shovel comparts /// </summary> /// <param name="parentCompartId">Parent Compartment Id to be set for this compartment</param> /// <returns></returns> public ServerReturnMessage AssignParent(int parentCompartId) { ServerReturnMessage result = new ServerReturnMessage { Id = 0, Message = "Compartment is not found!", Succeed = false }; if (Id == 0) { return(result); } var thisCompartAschildList = _context.COMPART_PARENT_RELATION.Where(m => m.ChildCompartId == Id); LU_COMPART parentCompart = _context.LU_COMPART.Find(parentCompartId); if (thisCompartAschildList.Count() > 0) //Update or Remove { COMPART_PARENT_RELATION relationRecord = thisCompartAschildList.First(); if (parentCompartId == 0) //Remove { _context.COMPART_PARENT_RELATION.Remove(relationRecord); } else if (parentCompart != null) //Update { relationRecord.ParentCompartId = parentCompart.compartid_auto; _context.Entry(relationRecord).State = EntityState.Modified; } else //Not remove and not able to update because parent compart not found { result.Succeed = true; result.Message = "Operation partially successful! Parent compart not found to be updated"; return(result); } } else if (parentCompart != null) //Add { _context.COMPART_PARENT_RELATION.Add( new COMPART_PARENT_RELATION { ChildCompartId = Id, ParentCompartId = parentCompartId } ); } // Not a change or not an update. Just doing nothing about parent else { result.Succeed = true; result.Message = "Operation was successful! No parent assigned or updated for this component."; return(result); } try { _context.SaveChanges(); result.Succeed = true; result.Message = "Operation was successful!"; return(result); } catch (Exception e1) { result.Message = "Operation failed! please try again!"; result.ExceptionMessage = e1.Message; if (e1.InnerException != null) { result.InnerExceptionMessage = e1.InnerException.Message; } result.Succeed = false; return(result); } }
/// <summary> /// Mining Shovel APIs /// </summary> /// <param name="Equip"></param> /// <returns></returns> public Stream PostValidateMiningShovelEquipInfo(BLL.Core.MiningShovel.Models.SyncModel Equip) { List <BLL.Core.Domain.ResultMessageExtended> rmList = new List <BLL.Core.Domain.ResultMessageExtended>(); try { /////////////////////////////////////////////////////////// // Update TRACK_INSPECTION and TRACK_INSPECTION_DETAIL EquipmentInspectionListEntity EquipList = new EquipmentInspectionListEntity(); /////////////////// // Equipment count EquipList.EquipmentsCount = 1; /////////////////// // New equipment List <NewEquipmentEntity> newEquip = new List <NewEquipmentEntity>(); EquipList.NewEquipmentsInspectionsList = newEquip; /////////////////// // Equipment list List <UndercarriageInspectionEntity> EquipmentsInspectionsList = new List <UndercarriageInspectionEntity>(); UndercarriageInspectionEntity equipInspection = new UndercarriageInspectionEntity(); equipInspection.Abrasive = Equip.abrasive; equipInspection.Impact = Equip.impact; equipInspection.Moisture = Equip.moisture; equipInspection.Packing = Equip.packing; equipInspection.SMU = Equip.smu.ToString(); equipInspection.DryJointsLeft = 0; equipInspection.DryJointsRight = 0; equipInspection.EquipmentIdAuto = Equip.equipmentid_auto; equipInspection.Examiner = Equip.examiner; equipInspection.ExtCannonLeft = 0; equipInspection.ExtCannonRight = 0; equipInspection.InspectionDate = Equip.currentDateandTime; equipInspection.InspectorComments = Equip.notes; equipInspection.JobsiteComments = Equip.Jobsite_Comms; equipInspection.leftCannonExtComment = ""; equipInspection.leftCannonExtImage = ""; equipInspection.leftScallop = 0; equipInspection.leftTrackSagComment = ""; equipInspection.leftTrackSagImage = ""; equipInspection.rightCannonExtComment = ""; equipInspection.rightCannonExtImage = ""; equipInspection.rightScallop = 0; equipInspection.rightTrackSagComment = ""; equipInspection.rightTrackSagImage = ""; equipInspection.TrackSagLeft = 0; equipInspection.TrackSagRight = 0; equipInspection.travelForward = 0; equipInspection.travelReverse = 0; equipInspection.TrammingHours = Equip.TrammingHours; equipInspection.CustomerContact = Equip.CustomerContact; // InspectionDetails //equipInspection.Details = ??? List <InspectionDetails> inspectionDetailList = new List <InspectionDetails>(); foreach (var item in Equip.InspectionDetails) { InspectionDetails inspectionDetail = new InspectionDetails(); inspectionDetail.AttachmentType = 0; inspectionDetail.Comments = ""; inspectionDetail.TrackUnitAuto = item.EqunitAuto; DAL.LU_COMPART compart = new LU_COMPART(); BLL.Core.Domain.Component component = new BLL.Core.Domain.Component(new UndercarriageContext()); compart = component.getCompart(item.EqunitAuto); inspectionDetail.CompartIdAuto = compart.compartid_auto; inspectionDetail.FlangeType = ""; inspectionDetail.Image = ""; inspectionDetail.InspectionImage = ""; inspectionDetail.PercentageWorn = 0; inspectionDetail.Reading = ""; inspectionDetail.ToolUsed = ""; inspectionDetailList.Add(inspectionDetail); } equipInspection.Details = inspectionDetailList; EquipmentsInspectionsList.Add(equipInspection); EquipList.EquipmentsInspectionsList = EquipmentsInspectionsList; ///////////// // Validate //List<BLL.Core.Domain.ResultMessageExtended> returnList = SaveEquipmentsInspectionsData(EquipList); try { rmList = EquipmentInspectionList.Instance.SaveRopeShovelEquipmentInspections(EquipList); } catch (Exception ex) { BLL.Core.Domain.ResultMessageExtended rmException = new BLL.Core.Domain.ResultMessageExtended(); rmException.ActionLog = "In Service " + ex.Message; if (ex.InnerException != null) { rmException.ActionLog += ex.InnerException.Message; } rmException.OperationSucceed = false; rmException.Id = -1; rmException.LastMessage = ex.Message; rmList.Add(rmException); } } catch (Exception ex) { BLL.Core.Domain.ResultMessageExtended rmException = new BLL.Core.Domain.ResultMessageExtended(); rmException.ActionLog = "In Service " + ex.Message; if (ex.InnerException != null) { rmException.ActionLog += ex.InnerException.Message; } rmException.OperationSucceed = false; rmException.Id = -1; rmException.LastMessage = ex.Message; rmList.Add(rmException); } //return rmList.First().Id; var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(JsonConvert.SerializeObject(rmList)); writer.Flush(); stream.Position = 0; return(stream); }