Exemplo n.º 1
0
        /// <summary>Save eFleet Preventative Maintenance
        /// <CreatedBy>Bhushan Dod</CreatedBy>
        /// <CreatedFor>SaveeFleetPreventativeMaintenance</CreatedFor>
        /// <CreatedOn>August-29-2017</CreatedOn>
        /// </summary>
        /// <param name="eFleetDamageTireModel"></param>
        /// <returns></returns>
        public ServiceResponseModel <string> InsertPreventativeMaintenance(eFleetPreventaticeMaintenanceModel objModel)
        {
            var objReturnModel = new ServiceResponseModel <string>();

            try
            {
                var objeFleetPreventativeMaintenanceRepository = new eFleetPreventativeMaintenanceRepository();
                eFleetPreventativeMaintenance Obj = new eFleetPreventativeMaintenance();
                AutoMapper.Mapper.CreateMap <eFleetPreventaticeMaintenanceModel, eFleetPreventativeMaintenance>();
                Obj             = AutoMapper.Mapper.Map(objModel, Obj);
                Obj.CreatedBy   = objModel.UserId;
                Obj.CreatedDate = DateTime.UtcNow;
                objeFleetPreventativeMaintenanceRepository.Add(Obj);
                if (Obj.ID > 0)
                {
                    #region Save DAR
                    DARModel objDAR = new DARModel();
                    objDAR.ActivityDetails = DarMessage.NeweFleetPMCreated(objModel.LocationName);
                    objDAR.LocationId      = objModel.LocationID;
                    objDAR.UserId          = objModel.UserId;
                    objDAR.CreatedBy       = objModel.UserId;
                    objDAR.CreatedOn       = DateTime.UtcNow;
                    objDAR.TaskType        = (long)TaskTypeCategory.PreventativeMaintenanceSubmission;
                    Result result = _ICommonMethod.SaveDAR(objDAR);
                    #endregion Save DAR

                    #region Email
                    var objEmailLogRepository = new EmailLogRepository();
                    var objEmailReturn        = new List <EmailToManagerModel>();
                    var objListEmailog        = new List <EmailLog>();
                    var objTemplateModel      = new TemplateModel();
                    if (result == Result.Completed)
                    {
                        objEmailReturn = objEmailLogRepository.SendEmailToManagerForeFleetInspection(objModel.LocationID, objModel.UserId).Result;
                    }

                    if (objEmailReturn.Count > 0 && result == Result.Completed)
                    {
                        foreach (var item in objEmailReturn)
                        {
                            bool IsSent         = false;
                            var  objEmailHelper = new EmailHelper();
                            objEmailHelper.emailid        = item.ManagerEmail;
                            objEmailHelper.ManagerName    = item.ManagerName;
                            objEmailHelper.RemiderMetric  = Convert.ToString(objModel.ReminderMetric);
                            objEmailHelper.Meter          = Convert.ToString(objModel.Meter);
                            objEmailHelper.VehicleNumber  = objModel.VehicleNumber;
                            objEmailHelper.LocationName   = objModel.LocationName;
                            objEmailHelper.UserName       = item.UserName;
                            objEmailHelper.QrCodeId       = objModel.QrCodeId;
                            objEmailHelper.ServiceDueDate = objModel.ServiceDueDate.ToString();
                            //objEmailHelper.InfractionStatus = obj.Status;
                            objEmailHelper.MailType      = "PreventativeMaintenance";
                            objEmailHelper.SentBy        = item.RequestBy;
                            objEmailHelper.LocationID    = item.LocationID;
                            objEmailHelper.TimeAttempted = DateTime.UtcNow.ToMobileClientTimeZone(objTemplateModel.TimeZoneName, objTemplateModel.TimeZoneOffset, objTemplateModel.IsTimeZoneinDaylight, false).ToString();

                            IsSent = objEmailHelper.SendEmailWithTemplate();

                            //Push Notification
                            string message = PushNotificationMessages.eFleetPreventativeMaintenanceReported(objModel.LocationName, objModel.QrCodeId, objModel.VehicleNumber);
                            PushNotification.GCMAndroid(message, item.DeviceId, objEmailHelper);
                            if (IsSent == true)
                            {
                                var objEmailog = new EmailLog();
                                try
                                {
                                    objEmailog.CreatedBy   = item.RequestBy;
                                    objEmailog.CreatedDate = DateTime.UtcNow;
                                    objEmailog.DeletedBy   = null;
                                    objEmailog.DeletedOn   = null;
                                    objEmailog.LocationId  = item.LocationID;
                                    objEmailog.ModifiedBy  = null;
                                    objEmailog.ModifiedOn  = null;
                                    objEmailog.SentBy      = item.RequestBy;
                                    objEmailog.SentEmail   = item.ManagerEmail;
                                    objEmailog.Subject     = objEmailHelper.Subject;
                                    objEmailog.SentTo      = item.ManagerUserId;
                                    objListEmailog.Add(objEmailog);
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                            }
                        }
                        using (var context = new workorderEMSEntities())
                        {
                            context.EmailLogs.AddRange(objListEmailog);
                            context.SaveChanges();;
                        }
                        //    //var x = EmailLogRepository.InsertEntitiesNew("EmailLog", objListEmailog);
                        //    //Task<bool> x = null;
                        //    //foreach (var i in objListEmailog)
                        //    //{
                        //    //    x = objEmailLogRepository.SaveEmailLogAsync(i);
                        //    //}
                        //}


                        #endregion Email
                        objReturnModel.Response = Convert.ToInt32(ServiceResponse.SuccessResponse, CultureInfo.InvariantCulture);
                        objReturnModel.Message  = CommonMessage.Successful();
                    }
                }
            }


            catch (Exception ex)
            {
                WorkOrderEMS.BusinessLogic.Exception_B.Exception_B.exceptionHandel_Runtime(ex, "ServiceResponseModel<string> InsertPreventativeMaintenance(eFleetPreventaticeMaintenanceModel objModel)", "while insert preventative maintenance", objModel);
                objReturnModel.Message  = ex.Message;
                objReturnModel.Response = Convert.ToInt32(ServiceResponse.ExeptionResponse, CultureInfo.CurrentCulture);
                objReturnModel.Data     = null;
            }
            return(objReturnModel);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Created By Ashwajit Bansod Dated 08/29/2017
        /// Save and edit Preventative maintenance Data
        /// </summary>
        /// <param name="objeFleetPMModel"></param>
        /// <returns></returns>
        public eFleetPMModel SaveEfleetPreventativeMaintenance(eFleetPMModel objeFleetPMModel)
        {
            try
            {
                workorderEMSEntities db = new workorderEMSEntities();
                var objLocationMaster   = new LocationMaster();
                var objeFleetPreventativeMaintenance = new eFleetPreventativeMaintenance();
                var objeFleetVehicleModel            = new eFleetVehicleModel();
                var meterval = Convert.ToInt64(eFleetEnum.Hours);
                var objeFleetPreventativeMaintenanceRepository = new eFleetPreventativeMaintenanceRepository();
                var objeTracLoginModel = new eTracLoginModel();
                if (objeFleetPMModel.ID == 0)
                {
                    AutoMapper.Mapper.CreateMap <eFleetPMModel, eFleetPreventativeMaintenance>();
                    if (objeFleetPMModel.Meter == meterval)
                    {
                        objeFleetPMModel.ReminderMetric = objeFleetPMModel.HoursValue;
                    }
                    var objfleetPMMapper = AutoMapper.Mapper.Map(objeFleetPMModel, objeFleetPreventativeMaintenance);
                    objeFleetPreventativeMaintenanceRepository.Add(objfleetPMMapper);
                    objeFleetPreventativeMaintenanceRepository.SaveChanges();
                    objeFleetPMModel.Result = Result.Completed;
                    if (objeFleetPMModel.Result == Result.Completed)
                    {
                        #region Save DAR
                        DARModel objDAR = new DARModel();
                        objDAR.ActivityDetails = DarMessage.NeweFleetPMCreated(objeFleetPMModel.LocationName);
                        objDAR.LocationId      = objeFleetPMModel.LocationID;
                        objDAR.UserId          = objeFleetPMModel.UserId;
                        objDAR.CreatedBy       = objeFleetPMModel.UserId;
                        objDAR.CreatedOn       = DateTime.UtcNow;
                        objDAR.TaskType        = (long)TaskTypeCategory.PreventativeMaintenanceSubmission;
                        Result result = _ICommonMethod.SaveDAR(objDAR);
                        #endregion Save DAR

                        //Created By Ashwajit Bansod Date: Oct-04-2017 for sending a mail regarding Prevenatative maintenance to the manager
                        #region Email
                        var objEmailLogRepository = new EmailLogRepository();
                        var objEmailReturn        = new List <EmailToManagerModel>();
                        var objListEmailog        = new List <EmailLog>();
                        var objTemplateModel      = new TemplateModel();
                        if (result == Result.Completed)
                        {
                            objEmailReturn = objEmailLogRepository.SendEmailToManagerForeFleetInspection(objeFleetPMModel.LocationID, objeFleetPMModel.UserId).Result;
                        }

                        if (objEmailReturn.Count > 0 && result == Result.Completed)
                        {
                            foreach (var item in objEmailReturn)
                            {
                                bool IsSent         = false;
                                var  objEmailHelper = new EmailHelper();
                                objEmailHelper.emailid     = item.ManagerEmail;
                                objEmailHelper.ManagerName = item.ManagerName;
                                if (objeFleetPMModel.ReminderMetric == null)
                                {
                                    objEmailHelper.RemiderMetric = "N/A";
                                }
                                else
                                {
                                    objEmailHelper.RemiderMetric = (from em in db.eFleetMeters where em.ID == objeFleetPMModel.ReminderMetric select em.MeterValue).FirstOrDefault();
                                }
                                objEmailHelper.Meter          = (from gc in db.GlobalCodes where gc.GlobalCodeId == objeFleetPMModel.Meter select gc.CodeName).FirstOrDefault();
                                objEmailHelper.Category       = (from gc in db.GlobalCodes where gc.GlobalCodeId == objeFleetPMModel.Category select gc.CodeName).FirstOrDefault();;
                                objEmailHelper.VehicleNumber  = objeFleetPMModel.VehicleNumber;
                                objEmailHelper.LocationName   = objeFleetPMModel.LocationName;
                                objEmailHelper.UserName       = item.UserName;
                                objEmailHelper.QrCodeId       = objeFleetPMModel.QRCodeID;
                                objEmailHelper.ServiceDueDate = objeFleetPMModel.ServiceDueDate.ToString();
                                objEmailHelper.PMMetric       = objeFleetPMModel.ReminderMetricDesc;
                                //objEmailHelper.InfractionStatus = obj.Status;
                                objEmailHelper.MailType      = "PreventativeMaintenance";
                                objEmailHelper.SentBy        = item.RequestBy;
                                objEmailHelper.LocationID    = item.LocationID;
                                objEmailHelper.TimeAttempted = DateTime.UtcNow.ToMobileClientTimeZone(objTemplateModel.TimeZoneName, objTemplateModel.TimeZoneOffset, objTemplateModel.IsTimeZoneinDaylight, false).ToString();
                                IsSent = objEmailHelper.SendEmailWithTemplate();
                                //Push Notification
                                string message = PushNotificationMessages.eFleetPreventativeMaintenanceReported(objeFleetPMModel.LocationName, objeFleetPMModel.QRCodeID, objeFleetPMModel.VehicleNumber);
                                PushNotification.GCMAndroid(message, item.DeviceId, objEmailHelper);
                                if (IsSent == true)
                                {
                                    var objEmailog = new EmailLog();
                                    try
                                    {
                                        objEmailog.CreatedBy   = item.RequestBy;
                                        objEmailog.CreatedDate = DateTime.UtcNow;
                                        objEmailog.DeletedBy   = null;
                                        objEmailog.DeletedOn   = null;
                                        objEmailog.LocationId  = item.LocationID;
                                        objEmailog.ModifiedBy  = null;
                                        objEmailog.ModifiedOn  = null;
                                        objEmailog.SentBy      = item.RequestBy;
                                        objEmailog.SentEmail   = item.ManagerEmail;
                                        objEmailog.Subject     = objEmailHelper.Subject;
                                        objEmailog.SentTo      = item.ManagerUserId;
                                        objListEmailog.Add(objEmailog);
                                    }
                                    catch (Exception)
                                    {
                                        throw;
                                    }
                                }
                            }
                            using (var context = new workorderEMSEntities())
                            {
                                context.EmailLogs.AddRange(objListEmailog);
                                context.SaveChanges();;
                            }
                            //    //var x = EmailLogRepository.InsertEntitiesNew("EmailLog", objListEmailog);
                            //    //Task<bool> x = null;
                            //    //foreach (var i in objListEmailog)
                            //    //{
                            //    //    x = objEmailLogRepository.SaveEmailLogAsync(i);
                            //    //}
                            //}
                            #endregion Email
                        }
                    }
                }
                //edit Data
                else
                {
                    var PreventativeData = objeFleetPreventativeMaintenanceRepository.GetAll(v => v.IsDeleted == false && v.ID == objeFleetPMModel.PmID).SingleOrDefault(); //PmID = ID PmID in Ashwajit Table
                                                                                                                                                                            //objeFleetPMModel.DriverImage = DriverData.DriverImage;//== null ? "" : HostingPrefix + ProfilePicPath.Replace("~", "") + DriverData.DriverImage;
                    AutoMapper.Mapper.CreateMap <eFleetPMModel, eFleetPreventativeMaintenance>();
                    if (objeFleetPMModel.Meter == meterval)
                    {
                        objeFleetPMModel.ReminderMetric = objeFleetPMModel.HoursValue;
                    }
                    var objfleetDriverMapper = AutoMapper.Mapper.Map(objeFleetPMModel, PreventativeData);
                    objeFleetPreventativeMaintenanceRepository.SaveChanges();
                    objeFleetPMModel.Result = Result.UpdatedSuccessfully;
                    if (objeFleetPMModel.Result == Result.UpdatedSuccessfully)
                    {
                        #region Save DAR
                        DARModel objDAR = new DARModel();
                        objDAR.ActivityDetails = DarMessage.NeweFleetPMUpdated(objeFleetPMModel.LocationName);
                        objDAR.LocationId      = objeFleetPMModel.LocationID;
                        objDAR.UserId          = objeFleetPMModel.UserId;
                        objDAR.ModifiedBy      = objeFleetPMModel.UserId;
                        objDAR.ModifiedOn      = DateTime.UtcNow;
                        objDAR.TaskType        = (long)TaskTypeCategory.UpdatePreventativeMaintenance;
                        Result result = _ICommonMethod.SaveDAR(objDAR);
                        #endregion Save DAR
                    }
                }

                return(objeFleetPMModel);
            }
            catch (Exception ex)
            {
                Exception_B.Exception_B.exceptionHandel_Runtime(ex, "public eFleetPMModel SaveEfleetPreventativeMaintenance(eFleetPMModel objeFleetPMModel)", "Exception While saving Preventative Maintenence request.", objeFleetPMModel);
                throw;
            }
        }