Exemple #1
0
        public ValueDataResponse <PreventiveMaintenance> InsertPreventiveMaintenance(UpsertPreventiveMaintenance PmOrders)
        {
            ValueDataResponse <PreventiveMaintenance> response = new ValueDataResponse <PreventiveMaintenance>();

            try
            {
                PreventiveMaintenance PM = _mapper.Map <PreventiveMaintenance>(PmOrders);
                var result = _appContext.PreventiveMaintenances.Add(PM);
                _appContext.SaveChanges();

                foreach (var sId in PmOrders.pmAssets)
                {
                    _appContext.PMAssetXrefs.Add(new PMAssetXref {
                        AssetId = sId.AssetId, PreventiveMaintenanceId = PM.Id, DaysApplicable = sId.DaysApplicable, AstFixedDate = sId.AstFixedDate
                    });
                }
                _appContext.SaveChanges();

                if (PmOrders != null)
                {
                    response.Result          = PM;
                    response.IsSuccess       = true;
                    response.AffectedRecords = 1;
                    response.EndUserMessage  = "Preventive Maintenance Added Successfully";
                }
                else
                {
                    response.IsSuccess       = true;
                    response.AffectedRecords = 0;
                    response.EndUserMessage  = "Preventive Maintenance Added Failed";
                }
            }
            catch (Exception ex)
            {
                response.IsSuccess       = false;
                response.AffectedRecords = 0;
                response.EndUserMessage  = ex.InnerException == null ? ex.Message : ex.InnerException.Message;
                response.Exception       = ex;
            }
            return(response);
        }
Exemple #2
0
        public ValueDataResponse <PreventiveMaintenance> UpdatePreventiveMaintenance(UpsertPreventiveMaintenance PmOrder)
        {
            ValueDataResponse <PreventiveMaintenance> response = new ValueDataResponse <PreventiveMaintenance>();

            try
            {
                PreventiveMaintenance PM = _mapper.Map <PreventiveMaintenance>(PmOrder);
                var result = _appContext.PreventiveMaintenances.Where(x => x.Id == PmOrder.Id).FirstOrDefault();

                var List = _appContext.PMAssetXrefs.Where(x => x.PreventiveMaintenanceId == result.Id).ToList();
                _appContext.PMAssetXrefs.RemoveRange(List);
                _appContext.SaveChanges();
                foreach (var sId in PmOrder.pmAssets)
                {
                    _appContext.PMAssetXrefs.Add(new PMAssetXref {
                        AssetId = sId.AssetId, PreventiveMaintenanceId = PM.Id, DaysApplicable = sId.DaysApplicable, AstFixedDate = sId.AstFixedDate
                    });
                }
                _appContext.SaveChanges();

                if (result != null)
                {
                    result.PreventiveRefId = PmOrder.PreventiveRefId;
                    result.StartDate       = PmOrder.StartDate;
                    result.JobPlanId       = PmOrder.JobPlanId;
                    result.Priority        = PmOrder.Priority;
                    result.DurationinHours = PmOrder.DurationInHours;

                    result.StatusTypeId      = PmOrder.StatusTypeId;
                    result.WorkTechnicianId  = PmOrder.WorkTechnicianId;
                    result.TypeOfMaintenance = PmOrder.TypeOfMaintenance;
                    result.Details           = PmOrder.Details;
                    result.CreatedBy         = PmOrder.CreatedBy;
                    result.CreatedDate       = PmOrder.CreatedDate;
                    result.UpdatedBy         = PmOrder.UpdatedBy;
                    result.UpdatedDate       = PmOrder.UpdatedDate;
                    result.IsActive          = PmOrder.IsActive;
                }
                _appContext.SaveChanges();

                if (PM != null)
                {
                    response.Result          = PM;
                    response.IsSuccess       = true;
                    response.AffectedRecords = 1;
                    response.EndUserMessage  = "Preventive Maintenance Updated Successfully";
                }
                else
                {
                    response.IsSuccess       = true;
                    response.AffectedRecords = 0;
                    response.EndUserMessage  = "Preventive Maintenance Updation Failed";
                }
            }
            catch (Exception ex)
            {
                response.IsSuccess       = false;
                response.AffectedRecords = 0;
                response.EndUserMessage  = ex.InnerException == null ? ex.Message : ex.InnerException.Message;
                response.Exception       = ex;
            }
            return(response);
        }
 public ValueDataResponse <PreventiveMaintenance> UpdatePreventiveMaintenance(UpsertPreventiveMaintenance PmOrder)
 {
     return(_unitOfWork.PreventiveMaintenances.UpdatePreventiveMaintenance(PmOrder));
 }