Exemplo n.º 1
0
        /// <summary>Save eFleet DAR Details
        /// <CreatedFor>For Insert eFleet DAR details</CreatedFor>
        /// <CreatedBy>Bhushan Dod</CreatedBy>
        /// <CreatedOn>Sept-05-2017s</CreatedOn>
        /// </summary>
        /// <param name="ObjServiceDARModel"></param>
        /// <returns>long DARId</returns>
        public long SaveeFleetDAR(ServiceDARModel ObjServiceDARModel)
        {
            var ObjDARDetail     = new DARDetail();
            var objDARRepository = new DARRepository();

            try
            {
                ObjDARDetail.ActivityDetails = ObjServiceDARModel.ActivityDetails;
                ObjDARDetail.LocationId      = ObjServiceDARModel.LocationId;
                ObjDARDetail.TaskType        = ObjServiceDARModel.TaskType;
                ObjDARDetail.CreatedBy       = ObjServiceDARModel.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          = ObjServiceDARModel.UserId;

                //Added by Bhushan on 09/05/2017 for start time of fueling is going to start now.
                if (ObjServiceDARModel.StartTime != null && ObjServiceDARModel.TaskType == Convert.ToInt64(eFleetEnum.Fueling))
                {
                    ObjDARDetail.StartTime = DateTime.UtcNow;
                }

                objDARRepository.Add(ObjDARDetail);
                long DARId = ObjDARDetail.DARId;

                return(DARId);
            }
            catch (Exception ex)
            {
                Exception_B.Exception_B.exceptionHandel_Runtime(ex, "long SaveeFleetDAR(ServiceDARModel ObjServiceDARModel)", "Exception While saving DAR for eFlee", ObjServiceDARModel.UserId);
                throw;
            }
        }
Exemplo n.º 2
0
        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);
        }