Пример #1
0
        /// <summary>Save eFleet Incident
        /// <CreatedBy>Bhushan Dod</CreatedBy>
        /// <CreatedFor>InsertVehicleIncident</CreatedFor>
        /// <CreatedOn>September-15-2017</CreatedOn>
        /// </summary>
        /// <param name="eFleetIncidentModel"></param>
        /// <returns></returns>
        public ServiceResponseModel <string> InsertVehicleIncident(eFleetIncidentModel objModel)
        {
            var objReturnModel = new ServiceResponseModel <string>();

            try
            {
                var objeFleetVehicleIncidentRepository = new eFleetVehicleIncidentRepository();
                var Obj    = new eFleetVehicleIncident();
                var objDAR = new DARModel();
                AutoMapper.Mapper.CreateMap <eFleetIncidentModel, eFleetVehicleIncident>();
                Obj             = AutoMapper.Mapper.Map(objModel, Obj);
                Obj.CreatedBy   = objModel.UserId;
                Obj.CreatedDate = DateTime.UtcNow;
                Obj.IsDeleted   = false;
                objeFleetVehicleIncidentRepository.Add(Obj);
                if (Obj.IncidentID > 0)
                {
                    // objDAR.ActivityDetails = objModel.ActivityDetails;
                    objDAR.ActivityDetails = DarMessage.RegisterNeweFleetIncidentVehicle(objModel.LocationName);
                    objDAR.LocationId      = objModel.LocationID;
                    // objDAR.TaskType = objModel.TaskType;
                    objDAR.TaskType   = (long)TaskTypeCategory.EfleetIncidentSubmission;
                    objDAR.CreatedBy  = objModel.UserId;
                    objDAR.CreatedOn  = DateTime.UtcNow;
                    objDAR.DeletedBy  = null;
                    objDAR.DeletedOn  = null;
                    objDAR.IsDeleted  = false;
                    objDAR.IsManual   = false;
                    objDAR.ModifiedBy = null;
                    objDAR.ModifiedOn = null;
                    objDAR.UserId     = objModel.UserId;
                    objDAR.StartTime  = objModel.AccidentDate.ToString();
                    objDAR.EndTime    = DateTime.UtcNow.ToString();
                    // objDARRepository.Add(objDAR);
                    Result result = _ICommonMethod.SaveDAR(objDAR);

                    #region Email
                    var objEmailLogRepository = new EmailLogRepository();
                    var objEmailReturn        = new List <EmailToManagerModel>();
                    var objListEmailog        = new List <EmailLog>();
                    var objTemplateModel      = new TemplateModel();
                    workorderEMSEntities db   = new workorderEMSEntities();
                    if (result == Result.Completed)
                    {
                        objEmailReturn = objEmailLogRepository.SendEmailToManagerForeFleetInspection(objModel.LocationID, objModel.UserId).Result;
                        //Code added by Bhu on 14 Dec 2017 for sending email to [email protected]. This is common MRA for risk manager.
                        var objEmailToManagerModel = new EmailToManagerModel();
                        objEmailToManagerModel.LocationID    = objModel.LocationID;
                        objEmailToManagerModel.LocationName  = objModel.LocationName;
                        objEmailToManagerModel.ManagerEmail  = "*****@*****.**";
                        objEmailToManagerModel.ManagerName   = "Team";
                        objEmailToManagerModel.ManagerUserId = 3; //admin user id for need to track email log
                        objEmailToManagerModel.RequestBy     = 3; //admin user id for need to track email log
                        objEmailToManagerModel.UserName      = "******";
                        objEmailReturn.Add(objEmailToManagerModel);
                    }

                    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.DriverNameforFueling = objModel.DriverName;
                            /// objEmailHelper.FuelType = (from gc in db.GlobalCodes where gc.GlobalCodeId == objModel.FuelType select gc.CodeName).FirstOrDefault();
                            objEmailHelper.IncidentDescription = objModel.Description;
                            if (objModel.Preventability == true)
                            {
                                objEmailHelper.Prevenatability = "Yes";
                            }
                            else
                            {
                                objEmailHelper.Prevenatability = "No";
                            }
                            objEmailHelper.NumberOfInjuries = objModel.NumberOfInjuries;
                            objEmailHelper.City             = objModel.City;
                            objEmailHelper.VehicleNumber    = objModel.VehicleNumber;
                            objEmailHelper.LocationName     = objModel.LocationName;
                            objEmailHelper.UserName         = item.UserName;
                            objEmailHelper.QrCodeId         = objModel.QRCodeID;
                            objEmailHelper.AccidentDate     = objModel.AccidentDate.ToString();
                            //objEmailHelper.InfractionStatus = obj.Status;
                            objEmailHelper.MailType      = "EfleetIncidentForService";
                            objEmailHelper.SentBy        = item.RequestBy;
                            objEmailHelper.LocationID    = item.LocationID;
                            objEmailHelper.TimeAttempted = DateTime.UtcNow.ToMobileClientTimeZone(objTemplateModel.TimeZoneName, objTemplateModel.TimeZoneOffset, objTemplateModel.IsTimeZoneinDaylight, false).ToString();

                            IsSent = objEmailHelper.SendEmailWithTemplate();

                            if (item.DeviceId != null && item.DeviceId != "")
                            {
                                //Push Notification
                                string message = PushNotificationMessages.eFleetIncidentForServiceReported(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
                    if (Obj.IncidentID > 0)
                    {
                        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> InsertVehicleIncident(eFleetIncidentModel objModel)", "while insert eFleet vehicle incident", objModel);
                objReturnModel.Message  = ex.Message;
                objReturnModel.Response = Convert.ToInt32(ServiceResponse.ExeptionResponse, CultureInfo.CurrentCulture);
                objReturnModel.Data     = null;
            }
            return(objReturnModel);
        }
Пример #2
0
        public eFleetVehicleIncidentModel SaveEfleetVehicleIncident(eFleetVehicleIncidentModel objeFleetVehicleIncidentModel)
        {
            try
            {
                LocationMaster objLocationMaster                  = new LocationMaster();
                var            objeFleetVehicleIncident           = new eFleetVehicleIncident();
                var            objeFleetVehicleIncidentRepository = new eFleetVehicleIncidentRepository();
                var            objeTracLoginModel                 = new eTracLoginModel();

                if (objeFleetVehicleIncidentModel.IncidentID == 0)
                {
                    objeFleetVehicleIncidentModel.IsDeleted = false;
                    AutoMapper.Mapper.CreateMap <eFleetVehicleIncidentModel, eFleetVehicleIncident>();
                    var objfleetVehicleIncidentMapper = AutoMapper.Mapper.Map(objeFleetVehicleIncidentModel, objeFleetVehicleIncident);
                    objeFleetVehicleIncidentRepository.Add(objfleetVehicleIncidentMapper);
                    // objeFleetVehicle.QRCodeID = objeFleetVehicleModel.QRCodeID + "EFV" + (objeFleetVehicle.VehicleID + 100).ToString();
                    objeFleetVehicleIncidentRepository.SaveChanges();
                    objeFleetVehicleIncidentModel.Result = Result.Completed;
                    if (objeFleetVehicleIncidentModel.Result == Result.Completed)
                    {
                        #region Save DAR
                        DARModel objDAR = new DARModel();
                        objDAR.ActivityDetails = DarMessage.RegisterNeweFleetIncidentVehicle(objeFleetVehicleIncidentModel.LocationName);
                        objDAR.LocationId      = objeFleetVehicleIncidentModel.LocationID;
                        objDAR.UserId          = objeFleetVehicleIncidentModel.UserID;
                        objDAR.CreatedBy       = objeFleetVehicleIncidentModel.UserID;
                        objDAR.CreatedOn       = DateTime.UtcNow;
                        objDAR.TaskType        = (long)TaskTypeCategory.eFleetVehicleIncidentSubmission;
                        Result result = _ICommonMethod.SaveDAR(objDAR);
                        #endregion Save DAR

                        //Created By Ashwajit Bansod for Sending the Mail of Vehicle Incident 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(objeFleetVehicleIncidentModel.LocationID, objeFleetVehicleIncidentModel.UserID).Result;
                            //Code added by Bhu on 14 Dec 2017 for sending email to [email protected]. This is common MRA for risk manager.
                            var objEmailToManagerModel = new EmailToManagerModel();
                            objEmailToManagerModel.LocationID    = objeFleetVehicleIncidentModel.LocationID;
                            objEmailToManagerModel.LocationName  = objeFleetVehicleIncidentModel.LocationName;
                            objEmailToManagerModel.ManagerEmail  = "*****@*****.**";
                            objEmailToManagerModel.ManagerName   = "Team";
                            objEmailToManagerModel.ManagerUserId = 3; //admin user id for need to track email log
                            objEmailToManagerModel.RequestBy     = 3; //admin user id for need to track email log
                            objEmailToManagerModel.UserName      = "******";
                            objEmailReturn.Add(objEmailToManagerModel);
                        }

                        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.VehicleNumber                = objeFleetVehicleIncidentModel.VehicleNumber;
                                objEmailHelper.LocationName                 = objeFleetVehicleIncidentModel.LocationName;
                                objEmailHelper.UserName                     = item.UserName;
                                objEmailHelper.QrCodeId                     = objeFleetVehicleIncidentModel.QRCodeID;
                                objEmailHelper.AccidentDate                 = objeFleetVehicleIncidentModel.AccidentDate.ToString();
                                objEmailHelper.City                         = objeFleetVehicleIncidentModel.City;
                                objEmailHelper.NumberOfInjuries             = objeFleetVehicleIncidentModel.NumberOfInjuries;
                                objEmailHelper.DriverNameForVehicleIncident = objeFleetVehicleIncidentModel.DriverName;
                                objEmailHelper.IncidentDescription          = objeFleetVehicleIncidentModel.Description;
                                if (objeFleetVehicleIncidentModel.Preventability == true)
                                {
                                    objEmailHelper.Prevenatability = "Yes";
                                }
                                else
                                {
                                    objEmailHelper.Prevenatability = "No";
                                }
                                //objEmailHelper.InfractionStatus = obj.Status;
                                objEmailHelper.MailType      = "VehicleIncident";
                                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.eFleetIncidentForServiceReported(objeFleetVehicleIncidentModel.LocationName, objeFleetVehicleIncidentModel.QRCodeID, objeFleetVehicleIncidentModel.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
                        }
                    }
                }
                else
                {
                    var vehicleIncidentData = objeFleetVehicleIncidentRepository.GetAll(v => v.IsDeleted == false && v.LocationID == objeFleetVehicleIncidentModel.LocationID && v.IncidentID == objeFleetVehicleIncidentModel.IncidentID).SingleOrDefault();
                    objeFleetVehicleIncidentModel.IncidentImage = vehicleIncidentData.IncidentImage;
                    AutoMapper.Mapper.CreateMap <eFleetVehicleIncidentModel, eFleetVehicleIncident>();
                    // objeFleetVehicleIncident.FuelType = Convert.ToInt32(objeFleetVehicleIncidentModel.FuelType);
                    var objfleetVehicleMapper = AutoMapper.Mapper.Map(objeFleetVehicleIncidentModel, vehicleIncidentData);
                    objeFleetVehicleIncidentRepository.SaveChanges();
                    objeFleetVehicleIncidentModel.Result = Result.UpdatedSuccessfully;
                    if (objeFleetVehicleIncidentModel.Result == Result.UpdatedSuccessfully)
                    {
                        #region Save DAR
                        DARModel objDAR = new DARModel();
                        objDAR.ActivityDetails = DarMessage.UpdateeFleetVehicleIncident(objeFleetVehicleIncidentModel.LocationName);
                        objDAR.LocationId      = objeFleetVehicleIncidentModel.LocationID;
                        objDAR.UserId          = objeFleetVehicleIncidentModel.UserID;
                        objDAR.ModifiedBy      = objeFleetVehicleIncidentModel.UserID;
                        objDAR.ModifiedOn      = DateTime.UtcNow;
                        objDAR.TaskType        = (long)TaskTypeCategory.UpdateeFleetIncidentVehicle;
                        Result result = _ICommonMethod.SaveDAR(objDAR);
                        #endregion Save DAR
                    }
                }
                return(objeFleetVehicleIncidentModel);
            }
            catch (Exception ex)
            {
                Exception_B.Exception_B.exceptionHandel_Runtime(ex, "public eFleetVehicleIncidentModel SaveEfleetVehicleIncident(eFleetVehicleIncidentModel objeFleetVehicleIncidentModel)", "Exception While saving vehicle Incident request.", objeFleetVehicleIncidentModel);
                throw;
            }
        }