Пример #1
0
        /// <summary>
        /// Created By Ashwajit Bansod Dated : Sept-22-2017
        /// For Saving and editing Maintenance Report
        /// </summary>
        /// <param name="objeFleetMaintenanceModel"></param>
        /// <returns></returns>
        public eFleetMaintenanceModel SaveEfleetMaintenance(eFleetMaintenanceModel objeFleetMaintenanceModel)
        {
            try
            {
                LocationMaster objLocationMaster              = new LocationMaster();
                var            objeFleetMaintenance           = new eFleetMaintenance();
                var            objeFleetMaintenanceRepository = new eFleetMaintenanceRepository();
                var            objeTracLoginModel             = new eTracLoginModel();
                if (objeFleetMaintenanceModel.MaintenanceID == 0)
                {
                    AutoMapper.Mapper.CreateMap <eFleetMaintenanceModel, eFleetMaintenance>();
                    var objfleetMaintenanceMapper = AutoMapper.Mapper.Map(objeFleetMaintenanceModel, objeFleetMaintenance);
                    objeFleetMaintenanceRepository.Add(objfleetMaintenanceMapper);
                    //objeFleetDriver.QRCCodeID = objeFleetMaintenanceModel.QRCCodeID + "EFD" + (objeFleetDriver.DriverID + 100).ToString();
                    objeFleetMaintenanceRepository.SaveChanges();
                    if (objeFleetMaintenance.MaintenanceID > 0)
                    {
                        if (objeFleetMaintenance.MaintenanceType == 445 && objeFleetMaintenanceModel.PmID != null && objeFleetMaintenanceModel.PmID > 0)
                        {
                            var objeFleetPreventativeMaintenanceRepository = new eFleetPreventativeMaintenanceRepository();
                            var pmData = objeFleetPreventativeMaintenanceRepository.GetAll(pm => pm.ID == objeFleetMaintenanceModel.PmID && pm.LocationID == objeFleetMaintenanceModel.LocationID && pm.IsDeleted == false).FirstOrDefault();
                            if (pmData != null && pmData.ID > 0)
                            {
                                pmData.IsCompleted = true;
                                pmData.CompletedBy = objeFleetMaintenanceModel.UserID;
                                pmData.CompletedOn = DateTime.UtcNow;
                                objeFleetPreventativeMaintenanceRepository.Update(pmData);
                            }
                        }
                        //    objeFleetMaintenanceModel.Result = Result.Completed;
                        if (objeFleetMaintenanceModel.Result == Result.Completed)
                        {
                            #region Save DAR
                            DARModel objDAR = new DARModel();
                            objDAR.ActivityDetails = DarMessage.RegisterNeweFleetMaintenance(objeTracLoginModel.LocationNames);
                            objDAR.LocationId      = objeFleetMaintenanceModel.LocationID;
                            objDAR.UserId          = objeFleetMaintenanceModel.UserID;
                            objDAR.CreatedBy       = objeFleetMaintenanceModel.UserID;
                            objDAR.CreatedOn       = DateTime.UtcNow;
                            objDAR.TaskType        = (long)TaskTypeCategory.eFleetDriverSubmission;
                            Result result = _ICommonMethod.SaveDAR(objDAR);
                            #endregion Save DAR
                        }
                    }
                }
                //edit Data
                else
                {
                    var MaintenanceData = objeFleetMaintenanceRepository.GetAll(v => v.IsDeleted == false && v.MaintenanceID == objeFleetMaintenanceModel.MaintenanceID && v.LocationID == objeFleetMaintenanceModel.LocationID).SingleOrDefault();
                    //objeFleetDriverModel.QRCCodeID = MaintenanceData.QRCCodeID;
                    //objeFleetDriverModel.DriverImage = MaintenanceData.DriverImage;//== null ? "" : HostingPrefix + ProfilePicPath.Replace("~", "") + DriverData.DriverImage;
                    AutoMapper.Mapper.CreateMap <eFleetMaintenanceModel, eFleetMaintenance>();
                    var objfleetDriverMapper = AutoMapper.Mapper.Map(objeFleetMaintenanceModel, MaintenanceData);
                    //objeFleetDriverModel.Passwordforedit = DriverData.Password;
                    objeFleetMaintenanceRepository.SaveChanges();
                    objeFleetMaintenanceModel.Result = Result.UpdatedSuccessfully;

                    if (objeFleetMaintenanceModel.Result == Result.UpdatedSuccessfully)
                    {
                        #region Save DAR
                        DARModel objDAR = new DARModel();
                        objDAR.ActivityDetails = DarMessage.RegisterNeweFleetMaintenance(objeFleetMaintenanceModel.LocationName);
                        objDAR.LocationId      = objeFleetMaintenanceModel.LocationID;
                        objDAR.UserId          = objeFleetMaintenanceModel.UserID;
                        objDAR.ModifiedBy      = objeFleetMaintenanceModel.UserID;
                        objDAR.ModifiedOn      = DateTime.UtcNow;
                        objDAR.TaskType        = (long)TaskTypeCategory.UpdateeFleetMaintenance;
                        Result result = _ICommonMethod.SaveDAR(objDAR);
                        #endregion Save DAR
                    }
                }
                return(objeFleetMaintenanceModel);
            }
            catch (Exception ex)
            {
                Exception_B.Exception_B.exceptionHandel_Runtime(ex, "public eFleetMaintenanceModel SaveEfleetMaintenance(eFleetMaintenanceModel objeFleetMaintenanceModel)", "Exception While saving Maintenance request.", objeFleetMaintenanceModel);
                throw;
            }
        }