public ResultMessage TransitFromMobileInspection(long EquipmentId, long MblEquipmentId, int InspectionId, Interfaces.IUser user) { var rm = new BLL.Core.Domain.ResultMessage { OperationSucceed = false, ActionLog = "Operation failed in TransitFromMobileInspection", LastMessage = "Operation failed!", Id = 0 }; if (user == null) { rm.LastMessage = "Operation failed! User not found!"; rm.ActionLog = "user is null"; return(rm); } var equipment = _context.EQUIPMENTs.Find(EquipmentId); var equipmentInspection = _context.Mbl_Track_Inspection.Where(m => m.inspection_auto == InspectionId && m.equipmentid_auto == MblEquipmentId).FirstOrDefault(); Mbl_NewEquipment mobileEquipment = _context.Mbl_NewEquipment.Where(m => m.equipmentid_auto == MblEquipmentId).FirstOrDefault(); if (equipment == null || equipmentInspection == null || mobileEquipment == null) { rm.LastMessage = "Operation failed! equipment or inspection not found!"; rm.ActionLog = "(equipment == null || equipmentInspection == null || mobileEquipment == null) detected!"; return(rm); } var mobileEqInspection = _context.Mbl_Track_Inspection.Where(m => m.equipmentid_auto == MblEquipmentId).FirstOrDefault(); if (mobileEqInspection == null) { rm.LastMessage = "Operation failed! Inspection from mobile not found!"; rm.ActionLog = "Mbl_Track_Inspection(this inspection).count() is 0"; return(rm); } var mobileInspectionDetails = _context.Mbl_Track_Inspection_Detail.Where(m => m.inspection_auto == mobileEqInspection.inspection_auto).ToList(); var mobileComponents = _context.Mbl_NewGENERAL_EQ_UNIT.Where(m => m.equipmentid_auto == MblEquipmentId).ToList(); var geuComponents = _context.GENERAL_EQ_UNIT.Where(m => m.equipmentid_auto == EquipmentId).ToList(); BLL.Core.Domain.InspectionImpact impact = equipmentInspection.impact == 2 ? BLL.Core.Domain.InspectionImpact.High : BLL.Core.Domain.InspectionImpact.Low; DAL.TRACK_INSPECTION EquipmentInspectionParam = new TRACK_INSPECTION { abrasive = equipmentInspection.abrasive, allowableWear = equipmentInspection.allowableWear, inspection_comments = equipmentInspection.inspection_comments, impact = equipmentInspection.impact, inspection_date = equipmentInspection.inspection_date, Jobsite_Comms = equipmentInspection.Jobsite_Comms, quote_auto = equipmentInspection.quote_auto, last_interp_date = equipmentInspection.last_interp_date, last_interp_user = equipmentInspection.last_interp_user, location = equipmentInspection.location, ltd = equipmentInspection.ltd, confirmed_date = equipmentInspection.confirmed_date, confirmed_user = equipmentInspection.confirmed_user, created_date = equipmentInspection.created_date, created_user = equipmentInspection.created_user, docket_no = equipmentInspection.docket_no + DateTime.Now.Millisecond, dry_joints_left = equipmentInspection.dry_joints_left, dry_joints_right = equipmentInspection.dry_joints_right, evalcode = equipmentInspection.evalcode, eval_comment = equipmentInspection.eval_comment, equipmentid_auto = EquipmentId, examiner = equipmentInspection.examiner, ext_cannon_left = equipmentInspection.ext_cannon_left, ext_cannon_right = equipmentInspection.ext_cannon_right, frame_ext_left = equipmentInspection.frame_ext_left, frame_ext_right = equipmentInspection.frame_ext_right, moisture = equipmentInspection.moisture, notes = equipmentInspection.notes, packing = equipmentInspection.packing, released_by = equipmentInspection.released_by, released_date = equipmentInspection.released_date, smu = equipmentInspection.smu, sprocket_left_status = equipmentInspection.sprocket_left_status, sprocket_right_status = equipmentInspection.sprocket_right_status, track_sag_left = equipmentInspection.track_sag_left, track_sag_left_status = equipmentInspection.track_sag_left_status, track_sag_right = equipmentInspection.track_sag_right, track_sag_right_status = equipmentInspection.track_sag_right_status, ucbrand = equipmentInspection.ucbrand, uccode = equipmentInspection.uccode, uccodedesc = equipmentInspection.uccodedesc, wear = equipmentInspection.wear, LeftTrackSagComment = equipmentInspection.LeftTrackSagComment, RightTrackSagComment = equipmentInspection.RightTrackSagComment, LeftCannonExtensionComment = equipmentInspection.LeftCannonExtensionComment, RightCannonExtensionComment = equipmentInspection.RightCannonExtensionComment, LeftTrackSagImage = equipmentInspection.LeftTrackSagImage, RightTrackSagImage = equipmentInspection.RightTrackSagImage, LeftCannonExtensionImage = equipmentInspection.LeftCannonExtensionImage, RightCannonExtensionImage = equipmentInspection.RightCannonExtensionImage, TravelledKms = equipmentInspection.TravelledKms, ForwardTravelHours = equipmentInspection.ForwardTravelHours, ReverseTravelHours = equipmentInspection.ReverseTravelHours, LeftScallopMeasurement = equipmentInspection.LeftScallopMeasurement, RightScallopMeasurement = equipmentInspection.RightScallopMeasurement }; var matchedComponents = getMatchingForInspectionSync(EquipmentId.LongNullableToInt(), MblEquipmentId.LongNullableToInt()); List <BLL.Core.Domain.InspectionDetailWithSide> tidWithSIdeList = new List <BLL.Core.Domain.InspectionDetailWithSide>(); foreach (var mtid in mobileInspectionDetails) { var matched = matchedComponents.Where(m => m.ComponentIndex == mtid.track_unit_auto).FirstOrDefault(); if (matched == null || matched.MatchedComponentId == 0) { continue; } BLL.Core.Domain.Component LogicalComponent = new Component(_context, matched.MatchedComponentId); if (LogicalComponent != null && LogicalComponent.Id != 0) { decimal worn = LogicalComponent.CalcWornPercentage(ConvertFrom(BLL.Core.Domain.MeasurementType.Milimeter, mtid.reading), mtid.tool_auto ?? 0, impact); char eval = ' '; LogicalComponent.GetEvalCodeByWorn(worn, out eval); List <TRACK_INSPECTION_IMAGES> imageList = new List <TRACK_INSPECTION_IMAGES>(); List <COMPART_ATTACH_FILESTREAM> imageStreamList = new List <COMPART_ATTACH_FILESTREAM>(); var mobileFileStream = _context.Mbl_CompartAttach_filestream.Where(m => m.inspection_auto == mobileEqInspection.inspection_auto && m.compartid_auto == matched.ComponentIndex).ToList(); foreach (var streamImage in mobileFileStream) { TRACK_INSPECTION_IMAGES inspectionImage = new TRACK_INSPECTION_IMAGES { GUID = streamImage.guid, image_comment = streamImage.comment, image_data = streamImage.attachment }; imageList.Add(inspectionImage); COMPART_ATTACH_FILESTREAM inspectionStreamImage = new COMPART_ATTACH_FILESTREAM { attachment = streamImage.attachment, attachment_name = streamImage.attachment_name, comment = streamImage.comment, compartid_auto = LogicalComponent.DALComponent.compartid_auto, comparttype_auto = LogicalComponent.DALComponent.LU_COMPART.comparttype_auto, compart_attach_type_auto = streamImage.compart_attach_type_auto, entry_date = streamImage.entry_date, guid = streamImage.guid, inspection_auto = InspectionId, position = LogicalComponent.DALComponent.pos, tool_auto = mtid.tool_auto, user_auto = user.Id }; imageStreamList.Add(inspectionStreamImage); } TRACK_INSPECTION_DETAIL tid = new TRACK_INSPECTION_DETAIL { comments = mtid.comments, worn_percentage = worn, eval_code = eval.ToString(), ext_projected_hours = mtid.ext_projected_hours, ext_remaining_hours = mtid.ext_remaining_hours, hours_on_surface = mtid.hours_on_surface, projected_hours = mtid.projected_hours, reading = mtid.reading, remaining_hours = mtid.remaining_hours, tool_auto = mtid.tool_auto, track_unit_auto = LogicalComponent.Id, Images = imageList }; BLL.Core.Domain.InspectionDetailWithSide tidWithSide = new BLL.Core.Domain.InspectionDetailWithSide { CompartAttachFileStreamImage = imageStreamList, ComponentInspectionDetail = tid, side = (LogicalComponent.DALComponent.side == null || LogicalComponent.DALComponent.side > 2 || LogicalComponent.DALComponent.side < 0) ? 0 : (int)LogicalComponent.DALComponent.side }; tidWithSIdeList.Add(tidWithSide); } } BLL.Core.Domain.InsertInspectionParams Params = new BLL.Core.Domain.InsertInspectionParams { EquipmentInspection = EquipmentInspectionParam, ComponentsInspection = tidWithSIdeList, EvaluationOverall = ' ' }; BLL.Interfaces.IEquipmentActionRecord EquipmentAction = new BLL.Core.Domain.EquipmentActionRecord { ActionDate = Params.EquipmentInspection.inspection_date, ActionUser = user, EquipmentId = Params.EquipmentInspection.equipmentid_auto > int.MaxValue ? int.MaxValue : (int)Params.EquipmentInspection.equipmentid_auto, Comment = Params.EquipmentInspection.inspection_comments, ReadSmuNumber = Params.EquipmentInspection.smu == null ? 0 : (int)Params.EquipmentInspection.smu, TypeOfAction = BLL.Core.Domain.ActionType.InsertInspection, Cost = 0 }; using (BLL.Core.Domain.Action UCAction = new BLL.Core.Domain.Action(new DAL.UndercarriageContext(), EquipmentAction, Params)) { System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer(); UCAction.Operation.Start(); if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Close) { rm.OperationSucceed = false; rm.ActionLog = UCAction.Operation.ActionLog; rm.LastMessage = UCAction.Operation.Message; } if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Started) { UCAction.Operation.Validate(); } if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Invalid) { rm.OperationSucceed = false; rm.ActionLog = UCAction.Operation.ActionLog; rm.LastMessage = UCAction.Operation.Message; } if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Valid) { UCAction.Operation.Commit(); } if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Failed) { rm.OperationSucceed = false; rm.ActionLog = UCAction.Operation.ActionLog; rm.LastMessage = UCAction.Operation.Message; } if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Succeed) { rm.OperationSucceed = true; rm.ActionLog = UCAction.Operation.ActionLog; rm.LastMessage = UCAction.Operation.Message; } rm.Id = UCAction.Operation.UniqueId; if (rm.OperationSucceed) { // TT-49 if (mobileEquipment.EquipmentPhoto != null) { _context.EQUIPMENTs.Find(equipment.equipmentid_auto).EquipmentPhoto = mobileEquipment.EquipmentPhoto; } _context.Mbl_Track_Inspection_Detail.RemoveRange(mobileInspectionDetails); _context.Mbl_Track_Inspection.Remove(mobileEqInspection); _context.Mbl_NewGENERAL_EQ_UNIT.RemoveRange(mobileComponents); _context.Mbl_NewEquipment.Remove(mobileEquipment); var imagesTobeDelete = _context.Mbl_CompartAttach_filestream.Where(m => m.inspection_auto == mobileEqInspection.inspection_auto); _context.Mbl_CompartAttach_filestream.RemoveRange(imagesTobeDelete); try { _context.SaveChanges(); rm.OperationSucceed = true; rm.LastMessage = "Operation was successfull!"; } catch (Exception m) { string Message = m.Message; rm.OperationSucceed = false; rm.LastMessage = "Operation failed! please check log for more details!"; rm.ActionLog = Message + ((m.InnerException != null) ? m.InnerException.Message : ""); } } } try { BLL.Core.Domain.Equipment LogicalEquipment = new BLL.Core.Domain.Equipment(new UndercarriageContext(), (int)EquipmentId); if (LogicalEquipment.Id == 0 || LogicalEquipment.GetEquipmentFamily() != BLL.Core.Domain.EquipmentFamily.MEX_Mining_Shovel) { return(rm); } LogicalEquipment.UpdateMiningShovelInspectionParentsFromChildren(rm.Id); return(rm); } catch (Exception ex) { string message = ex.Message; return(rm); } }// End of transit from mobile
/// <summary> /// Rope shovel /// </summary> /// <param name="inspection"></param> /// <returns></returns> public BLL.Core.Domain.ResultMessageExtended SaveUcRopeShovelInspection(UndercarriageInspectionEntity inspection) { var rm = new BLL.Core.Domain.ResultMessageExtended { OperationSucceed = false, ActionLog = " ", LastMessage = " ", Id = 0, }; BLL.Interfaces.IUser user = GetUserIdByExaminer(inspection.Examiner); if (user == null) { rm.LastMessage = "User Not Found!"; return(rm); } inspection.Examiner = user.userName; BLL.Core.Domain.InsertInspectionParams Params = getInsertInspectionParams(inspection); if (Params.EquipmentInspection.docket_no == null || Params.EquipmentInspection.docket_no.Length < 2) { Params.EquipmentInspection.docket_no = GetUniqueDocketNo(); } BLL.Interfaces.IEquipmentActionRecord EquipmentAction = new BLL.Core.Domain.EquipmentActionRecord { ActionDate = Params.EquipmentInspection.inspection_date, ActionUser = user, EquipmentId = Params.EquipmentInspection.equipmentid_auto > int.MaxValue ? int.MaxValue : (int)Params.EquipmentInspection.equipmentid_auto, Comment = Params.EquipmentInspection.inspection_comments, ReadSmuNumber = Params.EquipmentInspection.smu == null ? 0 : (int)Params.EquipmentInspection.smu, TypeOfAction = BLL.Core.Domain.ActionType.InsertInspection, Cost = 0 }; ///////////////// // Rope Shovel BLL.Interfaces.IGeneralInspectionModel GeneralInspection = new BLL.Core.ViewModel.GeneralInspectionViewModel { Date = Params.EquipmentInspection.inspection_date, SMU = (int)Params.EquipmentInspection.smu, TrammingHours = inspection.TrammingHours, CustomerContact = inspection.CustomerContact, InspectionNotes = inspection.InspectorComments, DocketNo = Params.EquipmentInspection.docket_no, Impact = inspection.Impact, Abrasive = inspection.Abrasive, Moisture = inspection.Moisture, Packing = inspection.Packing, JobSiteNotes = inspection.JobsiteComments }; ///////////////// // Rope Shovel //using (BLL.Core.Domain.Action UCAction = new BLL.Core.Domain.Action(new DAL.UndercarriageContext(), EquipmentAction, Params)) using (BLL.Core.Domain.Action UCAction = new BLL.Core.Domain.Action(new DAL.UndercarriageContext(), EquipmentAction, GeneralInspection)) { rm.PreValidation = UCAction.PreValidate(EquipmentAction); if (!rm.PreValidation.IsValid) { rm.LastMessage = "Validation Failed!"; rm.ActionLog = "PreValidation Failed"; rm.OperationSucceed = false; return(rm); } UCAction.Operation.Start(); if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Close) { rm.OperationSucceed = false; //rm.ActionLog = UCAction.Operation.ActionLog; rm.LastMessage = UCAction.Operation.Message; } if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Started) { UCAction.Operation.Validate(); } if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Invalid) { rm.OperationSucceed = false; //rm.ActionLog = UCAction.Operation.ActionLog; rm.LastMessage = UCAction.Operation.Message; } if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Valid) { UCAction.Operation.Commit(); } if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Failed) { rm.OperationSucceed = false; //rm.ActionLog = UCAction.Operation.ActionLog; rm.LastMessage = UCAction.Operation.Message; } if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Succeed) { rm.OperationSucceed = true; //rm.ActionLog = UCAction.Operation.ActionLog; rm.LastMessage = UCAction.Operation.Message; } rm.Id = UCAction.Operation.UniqueId; } try { BLL.Core.Domain.Equipment LogicalEquipment = new BLL.Core.Domain.Equipment(new DAL.UndercarriageContext(), EquipmentAction.EquipmentId); //if (LogicalEquipment.Id == 0 || LogicalEquipment.GetEquipmentFamily() != BLL.Core.Domain.EquipmentFamily.MEX_Mining_Shovel) // return rm; //LogicalEquipment.UpdateMiningShovelInspectionParentsFromChildren(rm.Id); return(rm); } catch (Exception ex) { string message = ex.Message; return(rm); } }
public void storeSetupLogic(BLL.Core.Domain.UndercarriageSetupSystemViewModel systemModel, BLL.Core.Domain.EquipmentSystemsExistence eqStat, BLL.Core.Domain.SetupSystemParams param, int LogicalEquipmentId, BLL.Interfaces.IUser user, BLL.Core.Domain.Side selectedSide ) { if (systemModel.Id == 0 && !eqStat.LeftChain) //NEW SYSTEM { BLL.Core.Domain.UCSystem leftChain = new BLL.Core.Domain.UCSystem(new DAL.UndercarriageContext()); param.SerialNo = systemModel.SerialNo; param.Side = selectedSide; param.Life = systemModel.systemLife; param.SetupDate = systemModel.InstallationDate; if (leftChain.CreateNewSystem(param, LogicalEquipmentId)) { param.Id = leftChain.Id; BLL.Interfaces.IEquipmentActionRecord EquipmentAction = new BLL.Core.Domain.EquipmentActionRecord { EquipmentId = LogicalEquipmentId, ReadSmuNumber = systemModel.EquipmentSMU, TypeOfAction = BLL.Core.Domain.ActionType.InstallSystemOnEquipment, ActionDate = systemModel.InstallationDate, ActionUser = user, Cost = 0, Comment = "System Setup" }; using (BLL.Core.Domain.Action action = new BLL.Core.Domain.Action(new DAL.UndercarriageContext(), EquipmentAction, new BLL.Core.Domain.InstallSystemParams { Id = leftChain.Id, EquipmentId = LogicalEquipmentId, side = selectedSide })) { if (action.Operation.Start() == BLL.Core.Domain.ActionStatus.Started && action.Operation.Validate() == BLL.Core.Domain.ActionStatus.Valid && action.Operation.Commit() == BLL.Core.Domain.ActionStatus.Succeed) { foreach (var comp in systemModel.Components) { var componentParam = new BLL.Core.Domain.SetupComponentParams { BudgetLife = comp.BudgetLife, CMU = comp.ComponentCurrentLife, CompartId = comp.CompartId, Cost = comp.Cost, Id = comp.Id, Life = comp.ComponentCurrentLife, UserId = user.Id, UserName = user.userName }; var LogicalComponent = new BLL.Core.Domain.Component(new DAL.UndercarriageContext()); if (LogicalComponent.CreateNewComponent(componentParam)) { BLL.Interfaces.IEquipmentActionRecord EquipmentActionForComp = new BLL.Core.Domain.EquipmentActionRecord { EquipmentId = LogicalEquipmentId, ReadSmuNumber = comp.EquipmetSMU, TypeOfAction = BLL.Core.Domain.ActionType.InstallComponentOnSystemOnEquipment, ActionDate = comp.InstallationDate, ActionUser = user, Cost = 0, Comment = "Component Setup" }; using (BLL.Core.Domain.Action compAction = new BLL.Core.Domain.Action(new DAL.UndercarriageContext(), EquipmentActionForComp, new BLL.Core.Domain.InstallComponentOnSystemParams { Id = LogicalComponent.Id, Position = comp.Position, SystemId = leftChain.Id, side = selectedSide })) { compAction.Operation.Start(); compAction.Operation.Validate(); compAction.Operation.Commit(); } } } } } } } else //UPDATE SYSTEM { var LogicalSystem = new BLL.Core.Domain.UCSystem(new DAL.UndercarriageContext(), systemModel.Id); if (LogicalSystem.Id != 0 && LogicalSystem.Components != null) { var removiongComponents = LogicalSystem.Components.Where(m => !systemModel.Components.Any(n => m.equnit_auto == n.Id)); if (LogicalSystem.removeComponents(removiongComponents.ToList())) { //Components which are not in the list of current components should be removed from installed components! //Just for monitoring purposes string message = ""; message += "Components removed successfully"; } foreach (var comp in systemModel.Components) { var componentParam = new BLL.Core.Domain.SetupComponentParams { BudgetLife = comp.BudgetLife, CMU = comp.ComponentCurrentLife, CompartId = comp.CompartId, Cost = comp.Cost, Id = comp.Id, Life = comp.ComponentCurrentLife, UserId = user.Id, UserName = user.userName }; if (comp.Id == 0) //New Component Added { var LogicalComponent = new BLL.Core.Domain.Component(new DAL.UndercarriageContext()); if (LogicalComponent.CreateNewComponent(componentParam)) { BLL.Interfaces.IEquipmentActionRecord EquipmentActionForComp = new BLL.Core.Domain.EquipmentActionRecord { EquipmentId = LogicalEquipmentId, ReadSmuNumber = comp.EquipmetSMU, TypeOfAction = BLL.Core.Domain.ActionType.InstallComponentOnSystemOnEquipment, ActionDate = comp.InstallationDate, ActionUser = user, Cost = 0, Comment = "Component Setup" }; using (BLL.Core.Domain.Action compAction = new BLL.Core.Domain.Action(new DAL.UndercarriageContext(), EquipmentActionForComp, new BLL.Core.Domain.InstallComponentOnSystemParams { Id = LogicalComponent.Id, Position = comp.Position, SystemId = systemModel.Id, side = selectedSide })) { compAction.Operation.Start(); compAction.Operation.Validate(); compAction.Operation.Commit(); } } } else { var LogicalComponent = new BLL.Core.Domain.Component(new DAL.UndercarriageContext(), comp.Id); LogicalComponent.removeInstallationRecord(); LogicalComponent.UpdateComponentOnSetup(componentParam); BLL.Interfaces.IEquipmentActionRecord EquipmentActionForComp = new BLL.Core.Domain.EquipmentActionRecord { EquipmentId = LogicalEquipmentId, ReadSmuNumber = comp.EquipmetSMU, TypeOfAction = BLL.Core.Domain.ActionType.InstallComponentOnSystemOnEquipment, ActionDate = comp.InstallationDate, ActionUser = user, Cost = 0, Comment = "Component Setup" }; using (BLL.Core.Domain.Action compAction = new BLL.Core.Domain.Action(new DAL.UndercarriageContext(), EquipmentActionForComp, new BLL.Core.Domain.InstallComponentOnSystemParams { Id = LogicalComponent.Id, Position = comp.Position, SystemId = systemModel.Id, side = selectedSide })) { compAction.Operation.Start(); compAction.Operation.Validate(); compAction.Operation.Commit(); } } } } } }
public BLL.Core.Domain.ResultMessageExtended SaveUcInspection(UndercarriageInspectionEntity inspection) { var rm = new BLL.Core.Domain.ResultMessageExtended { OperationSucceed = false, ActionLog = " ", LastMessage = " ", Id = 0, }; BLL.Interfaces.IUser user = GetUserIdByExaminer(inspection.Examiner); if (user == null) { rm.LastMessage = "User Not Found!"; return(rm); } inspection.Examiner = user.userName; BLL.Core.Domain.InsertInspectionParams Params = getInsertInspectionParams(inspection); if (Params.EquipmentInspection.docket_no == null || Params.EquipmentInspection.docket_no.Length < 2) { Params.EquipmentInspection.docket_no = GetUniqueDocketNo(); } BLL.Interfaces.IEquipmentActionRecord EquipmentAction = new BLL.Core.Domain.EquipmentActionRecord { ActionDate = Params.EquipmentInspection.inspection_date, ActionUser = user, EquipmentId = Params.EquipmentInspection.equipmentid_auto > int.MaxValue ? int.MaxValue : (int)Params.EquipmentInspection.equipmentid_auto, Comment = Params.EquipmentInspection.inspection_comments, ReadSmuNumber = Params.EquipmentInspection.smu == null ? 0 : (int)Params.EquipmentInspection.smu, TypeOfAction = BLL.Core.Domain.ActionType.InsertInspection, Cost = 0 }; using (BLL.Core.Domain.Action UCAction = new BLL.Core.Domain.Action(new DAL.UndercarriageContext(), EquipmentAction, Params)) { rm.PreValidation = UCAction.PreValidate(EquipmentAction); if (!rm.PreValidation.IsValid) { rm.LastMessage = "Validation Failed!"; rm.ActionLog = "PreValidation Failed"; rm.OperationSucceed = false; return(rm); } UCAction.Operation.Start(); if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Close) { rm.OperationSucceed = false; //rm.ActionLog = UCAction.Operation.ActionLog; rm.LastMessage = UCAction.Operation.Message; } if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Started) { UCAction.Operation.Validate(); } if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Invalid) { rm.OperationSucceed = false; //rm.ActionLog = UCAction.Operation.ActionLog; rm.LastMessage = UCAction.Operation.Message; } if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Valid) { UCAction.Operation.Commit(); } if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Failed) { rm.OperationSucceed = false; //rm.ActionLog = UCAction.Operation.ActionLog; rm.LastMessage = UCAction.Operation.Message; } if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Succeed) { rm.OperationSucceed = true; //rm.ActionLog = UCAction.Operation.ActionLog; rm.LastMessage = UCAction.Operation.Message; // TT-49 if (inspection.EquipmentImage != null) { UpdateEquipmentImageFromInspection(inspection.EquipmentIdAuto, inspection.EquipmentImage); } } rm.Id = UCAction.Operation.UniqueId; } try { BLL.Core.Domain.Equipment LogicalEquipment = new BLL.Core.Domain.Equipment(new DAL.UndercarriageContext(), EquipmentAction.EquipmentId); if (LogicalEquipment.Id == 0 || LogicalEquipment.GetEquipmentFamily() != BLL.Core.Domain.EquipmentFamily.MEX_Mining_Shovel) { return(rm); } LogicalEquipment.UpdateMiningShovelInspectionParentsFromChildren(rm.Id); return(rm); } catch (Exception ex) { string message = ex.Message; return(rm); } }
public async Task <Tuple <long, string> > UpdateEquipment(SetupEquipmentViewModel e) { var ActionParam = new BLL.Core.Domain.EquipmentActionRecord { ActionUser = new BLL.Core.Domain.User { Id = (int)(e.CreatedByUserId ?? 0) }, EquipmentId = (int)e.Id, ReadSmuNumber = e.Smu, EquipmentActualLife = e.Ltd, TypeOfAction = BLL.Core.Domain.ActionType.UpdateSetupEquipment, Cost = 0.0M, Comment = "Update Equipment Setup", ActionDate = e.Date.ToLocalTime().Date }; var EquipmentSetupParams = new BLL.Core.Domain.GETEquipmentSetupParams { UserAuto = (int)(e.CreatedByUserId ?? 0), ActionType = BLL.Core.Domain.GETActionType.UpdateSetupEquipment, RecordedDate = DateTime.Now, EventDate = e.Date.ToLocalTime().Date, Comment = "Update Equipment Setup", Cost = 0.0M, MeterReading = e.Smu, EquipmentLTD = e.Ltd, EquipmentId = e.Id, IsUpdating = true, }; var rm = new BLL.Core.Domain.ResultMessage { OperationSucceed = false, ActionLog = " ", LastMessage = " ", Id = 0 }; using (var action = new BLL.Core.Domain.Action(new DAL.UndercarriageContext(), new DAL.GETContext(), ActionParam, EquipmentSetupParams)) { if (action.Operation.Start() == ActionStatus.Started && action.Operation.Validate() == ActionStatus.Valid && action.Operation.Commit() == ActionStatus.Succeed) { rm.OperationSucceed = true; } else { rm.OperationSucceed = false; } rm.LastMessage = action.Operation.Message; rm.ActionLog = action.Operation.ActionLog; rm.Id = action.Operation.UniqueId; } if (!rm.OperationSucceed && rm.Id != -2) { return(Tuple.Create((long)-1, "Failed to complete the action: " + rm.LastMessage)); } var mmta = await _context.LU_MMTA.Where(m => m.model_auto == e.ModelId && m.make_auto == e.MakeId).FirstOrDefaultAsync(); var updater = await _context.USER_TABLE.FindAsync(e.CreatedByUserId); string[] LogoArr = e.Photo.Split(','); string equipmentPhoto = ""; if (LogoArr.Length > 1) { equipmentPhoto = LogoArr[1]; } var eq = await _context.EQUIPMENTs.FindAsync(e.Id); // Need to check if inspections exist eq.smu_at_start = e.Smu; eq.currentsmu = e.Smu; eq.last_reading_date = e.Date.ToLocalTime().Date; eq.LTD_at_start = e.Ltd; eq.purchase_op_hrs = e.Smu; eq.purchase_date = e.Date.ToLocalTime().Date; eq.modified_date = DateTime.Now; eq.modified_user = updater.username; eq.equip_status = e.StatusId; eq.crsf_auto = e.JobsiteId; eq.serialno = e.SerialNumber; eq.unitno = e.UnitNumber; eq.mmtaid_auto = mmta.mmtaid_auto; eq.op_hrs_per_day = e.HoursOfUsePerDay; eq.ranking_auto = Convert.ToByte((e.RankingId == null || e.RankingId < 0) ? 0 : e.RankingId); eq.UsedMonday = e.UsedMonday; eq.UsedTuesday = e.UsedTuesday; eq.UsedWednesday = e.UsedWednesday; eq.UsedThursday = e.UsedThursday; eq.UsedFriday = e.UsedFriday; eq.UsedSaturday = e.UsedSaturday; eq.UsedSunday = e.UsedSunday; if (e.Photo.Length > 0) { eq.EquipmentPhoto = Convert.FromBase64String(equipmentPhoto); } eq.InspectEvery = e.InspectEvery; eq.InspectEveryUnitTypeId = e.InspectEveryUnitTypeId; var mmtaEntity = await _context.LU_MMTA.FindAsync(eq.mmtaid_auto); mmtaEntity.make_auto = e.MakeId; mmtaEntity.model_auto = e.ModelId; mmtaEntity.type_auto = mmta.type_auto; mmtaEntity.app_auto = e.ApplicationId; try { await _context.SaveChangesAsync(); } catch (Exception ex) { return(Tuple.Create((long)-1, "Failed to update the equipment. " + ex.Message + ". " + ex.InnerException != null ? ex.InnerException.Message : "")); } //var getSetupEvent = new GETCore.Classes.GETEquipment(); //getSetupEvent.equipmentSetupEvent(eq.equipmentid_auto, e.Smu, e.Ltd, e.CreatedByUserId != null ? (long)e.CreatedByUserId : -1); if (e.UnsyncedId > 0) { new BLL.Core.Domain.Inspection(new DAL.UndercarriageContext()).MatchMobileInspection((int)e.Id, e.UnsyncedId); } if (!rm.OperationSucceed) { return(Tuple.Create(eq.equipmentid_auto, "Your equipment has been updated with warnings. This equipment was setup in the old application and some manual midifications may be required!")); } return(Tuple.Create(eq.equipmentid_auto, "Your equipment has been updated successfully. ")); }