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; } }