Example #1
0
        public IHttpActionResult SaveeFleetIncident(eFleetIncidentModel objeeFleetIncidentModel)
        {
            var ObjServiceResponseModel = new ServiceResponseModel <string>();

            try
            {
                // var objVehicleIncidentManager = new VehicleIncidentManager();
                if (objeeFleetIncidentModel != null && objeeFleetIncidentModel.ServiceAuthKey != null && objeeFleetIncidentModel.UserId > 0)
                {
                    var ObjRespnse = _IEfleetVehicleIncidentReport.InsertVehicleIncident(objeeFleetIncidentModel);
                    return(Ok(ObjRespnse));
                }
                else
                {
                    ObjServiceResponseModel.Response = Convert.ToInt32(ServiceResponse.FailedResponse, CultureInfo.CurrentCulture);
                    ObjServiceResponseModel.Message  = CommonMessage.InvalidUser();
                    return(Ok(ObjServiceResponseModel));
                }
            }
            catch (Exception ex)
            {
                ObjServiceResponseModel.Message  = ex.Message;
                ObjServiceResponseModel.Response = Convert.ToInt32(ServiceResponse.ExeptionResponse, CultureInfo.CurrentCulture);
                ObjServiceResponseModel.Data     = null;

                return(Ok(ObjServiceResponseModel));
            }
        }
Example #2
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);
        }