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);
            }
        }
        /// <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);
            }
        }
Example #3
0
        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();
                            }
                        }
                    }
                }
            }
        }