public ServiceResponseModel <string> InserteFleetFueling(eFleetFuelingModelForService objModel) { var objReturnModel = new ServiceResponseModel <string>(); try { var objFuelingRepository = new FuelingRepository(); var objDARRepository = new DARRepository(); var objDARDetail = new DARDetail(); var objDAR = new DARModel(); var Obj = new eFleetFueling(); AutoMapper.Mapper.CreateMap <eFleetFuelingModelForService, eFleetFueling>(); Obj = AutoMapper.Mapper.Map(objModel, Obj); Obj.CreatedBy = objModel.UserId; Obj.CreatedDate = DateTime.UtcNow; objFuelingRepository.Add(Obj); if (Obj.FuelID > 0) { objDARDetail.ActivityDetails = DarMessage.RegisterNeweFleetFueling(objModel.LocationName); //objDAR.ActivityDetails = objModel.ActivityDetails; objDARDetail.LocationId = objModel.LocationID; objDARDetail.TaskType = (long)TaskTypeCategory.EfleetFuelingSubmission; objDARDetail.CreatedBy = objModel.UserId; objDARDetail.CreatedOn = DateTime.UtcNow; objDARDetail.DeletedBy = null; objDARDetail.DeletedOn = null; objDARDetail.IsDeleted = false; objDARDetail.IsManual = false; objDARDetail.ModifiedBy = null; objDARDetail.ModifiedOn = null; objDARDetail.UserId = objModel.UserId; objDARDetail.StartTime = objModel.FuelingDate; objDARDetail.EndTime = DateTime.UtcNow; objDARRepository.Add(objDARDetail); //Result result = _ICommonMethod.SaveDAR(objDARDetail); #region Email var objEmailLogRepository = new EmailLogRepository(); var objEmailReturn = new List <EmailToManagerModel>(); var objListEmailog = new List <EmailLog>(); var objTemplateModel = new TemplateModel(); Result result; workorderEMSEntities db = new workorderEMSEntities(); if (objDARDetail.DARId > 0) { objEmailReturn = objEmailLogRepository.SendEmailToManagerForeFleetInspection(objModel.LocationID, objModel.UserId).Result; } if (objEmailReturn.Count > 0 && objDARDetail.DARId > 0) { 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.GasStatioName = objModel.GasStatioName; objEmailHelper.Mileage = objModel.Mileage; objEmailHelper.CurrentFuel = objModel.CurrentFuel; objEmailHelper.Total = objModel.Total.ToString(); objEmailHelper.VehicleNumber = objModel.VehicleNumber; objEmailHelper.LocationName = objModel.LocationName; objEmailHelper.UserName = item.UserName; objEmailHelper.QrCodeId = objModel.QRCodeID; objEmailHelper.FuelingDate = objModel.FuelingDate.ToString(); //objEmailHelper.InfractionStatus = obj.Status; objEmailHelper.MailType = "EfleetFueling"; 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.eFleetFuelingReported(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 (objDARDetail.DARId > 0) { objReturnModel.Response = Convert.ToInt32(ServiceResponse.SuccessResponse, CultureInfo.InvariantCulture); objReturnModel.Message = CommonMessage.Successful(); } else { objReturnModel.Response = Convert.ToInt32(ServiceResponse.FailedResponse, CultureInfo.CurrentCulture); objReturnModel.Message = CommonMessage.FailureMessage(); } } } } 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); }