public ModelViewNotification Get(ModelViewNotificationUpdate model)
        {
            if (model.TokenApp != GlobalConfiguration.TokenWEB)
            {
                if (model.TokenApp != GlobalConfiguration.TokenMobile)
                {
                    throw new Exception("TokenInvalid");
                }
            }

            var data = new RepositoryNotification().Get(model.MessageID);

            return(new ModelViewNotification()
            {
                MessageID = data.MessageID,
                Message = data.Message,
                MessageRead = data.MessageRead,
                Title = data.Title,
                Url = data.Url,
                UserID = data.UserID,
                UserName = data.UserName,
                Status = data.Status,
                CreateDate = data.CreateDate,
                ModifyDate = data.ModifyDate,
                CreateDateString = data.CreateDate.ToString("dd/MM/yyyy HH:mm:ss"),
                ModifyDateString = data.ModifyDate.ToString("dd/MM/yyyy HH:mm:ss")
            });
        }
Exemple #2
0
        public IHttpActionResult GetUnReadCount()
        {
            var repository = new RepositoryNotification();
            var response   = repository.GetUnReadNotificationCount(CurrentUserId);

            return(Ok <DataResponse <UnReadNotification> >(response));
        }
        public IHttpActionResult UpdateNotifications(NotificationModel entity)
        {
            var repository = new RepositoryNotification();
            var response   = new DataResponse();

            if (ModelState.IsValid)
            {
                var model = new EntityNotificationSettings
                {
                    UserId             = CurrentUserId,
                    Status             = entity.Status,
                    NotificationTypeId = entity.NotificationTypeId
                };

                response = repository.SaveNotification(model);
            }
            else
            {
                var errorList = ModelState.Where(a => a.Value.Errors.Any()).Select(s => new
                {
                    Key     = s.Key.Split('.').Last(),
                    Message = s.Value.Errors[0].ErrorMessage
                });
                return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = errorList }));
            }
            response.Status  = DataResponseStatus.OK;
            response.Message = "Success";
            return(Ok <DataResponse>(response));
        }
Exemple #4
0
        public IHttpActionResult GetAllNotifications(int skip, int take)
        {
            var repository = new RepositoryNotification();

            var response = repository.GetAllNotifications(CurrentUserId, CurrentBusinessId, skip, take);

            return(Ok <DataResponse <Notification> >(response));
        }
        public IHttpActionResult GetAllNotifications()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Ok <dynamic>(new { IsSuccess = 0, Status = HttpStatusCode.BadRequest, Model = new { }, Message = "Authorization failed!" }));
            }
            var repository = new RepositoryNotification();

            var user     = new RepositoryUserProfile().GetUserbyId(CurrentUserId);
            var response = repository.GetAllNotificationSettings(CurrentUserId);

            return(Ok <DataResponse>(response));
        }
        public void Status(ModelViewNotificationUpdate model)
        {
            if (model.TokenApp != GlobalConfiguration.TokenWEB)
            {
                if (model.TokenApp != GlobalConfiguration.TokenMobile)
                {
                    throw new Exception("TokenInvalid");
                }
            }

            var data = new RepositoryNotification().Get(model.MessageID);

            data.MessageRead = model.MessageRead;
            data.Status      = model.Status;
            new RepositoryNotification().Update(data);
        }
        public ModelViewNotification Update(ModelViewNotification model)
        {
            EntityNotification data = new EntityNotification()
            {
                MessageID   = model.MessageID,
                Message     = model.Message,
                MessageRead = model.MessageRead,
                Title       = model.Title,
                Url         = model.Url,
                UserID      = model.UserID,
                Status      = model.Status,
                CreateDate  = model.CreateDate,
                ModifyDate  = DateTime.UtcNow
            };

            data = new RepositoryNotification().Update(data);
            return(model);
        }
Exemple #8
0
        public IHttpActionResult updateNotification(string id)
        {
            var repository = new RepositoryNotification();

            if (!User.Identity.IsAuthenticated)
            {
                return(Ok <dynamic>(new { IsSuccess = 0, Status = HttpStatusCode.BadRequest, Model = new { }, Message = "Authorization failed!" }));
            }
            try
            {
                repository.UpdateNotification(Int32.Parse(id), CurrentUserId);
                return(Ok <dynamic>(new { IsSuccess = 1, Status = 200, Model = new { }, Message = "Success!" }));
            }
            catch (Exception e)
            {
                return(Ok <dynamic>(new { IsSuccess = 0, Status = DataResponseStatus.InternalServerError, Message = e.Message }));
            }
        }
        public ModelViewNotification Insert(ModelViewNotification model)
        {
            EntityNotification data = new EntityNotification()
            {
                MessageID   = model.MessageID,
                Message     = model.Message,
                MessageRead = model.MessageRead,
                Title       = model.Title,
                Url         = model.Url,
                UserID      = model.UserID,
                Status      = true,
                CreateDate  = DateTime.UtcNow,
                ModifyDate  = DateTime.UtcNow
            };

            data            = new RepositoryNotification().Insert(data);
            model.MessageID = data.MessageID;

            return(model);
        }
Exemple #10
0
        private void SendNotification()
        {
            new Exception("Process Started").Log();

            CRMStagingEntities n = new CRMStagingEntities();
            var response         = new List <EntityNotificationUsers>();
            var repository       = new RepositoryNotification();

            // Get All Notifications which have IspushSent Status true
            response = repository.GetAllUserNotifications();

            foreach (var item in response)
            {
                // Get Details of Notification and user for pushing
                var dataNotification = repository.GetNotificationById(item.NotificationId);

                if (dataNotification.Model == null)
                {
                    break;
                }

                long   NotificationId = dataNotification.Model.NotificationId;
                int    ToUserId       = dataNotification.Model.UserId;
                int    TargetId       = dataNotification.Model.TargetId;
                int    TargetType     = dataNotification.Model.TargetTypeId;
                string Message        = dataNotification.Model.Message;
                //string Subject=null;
                //if(TargetType==(int)NoteType.Task)

                //{
                //var TaskModel = repository.GetTaskById(TargetId);
                //Subject = TaskModel.Model.Subject;
                //}
                //get Notification UnReadCount

                var unReadNotify = repository.GetUnReadNotificationCount(item.UserId);

                int unReadCount = unReadNotify.Model != null ? unReadNotify.Model.NotificationCount : 0;
                //Payload Format
                var notifyObj = new ApplePushPayLoad
                {
                    aps = new aps
                    {
                        alert = Message,
                        badge = unReadCount == 0 ? 1 : unReadCount,
                        sound = "default"
                    },
                    NotificationId = NotificationId,
                    TargetId       = TargetId,
                    TargetType     = TargetType
                };


                //  For Getting User DeviceId Details
                var repositoryUsers = new RepositoryUsers();
                var userDetails     = repositoryUsers.GetUserDeviceIdById(item.UserId);
                if (userDetails.Model != null)
                {
                    var toDeviceId = userDetails.Model.DeviceId;

                    if (toDeviceId == null)
                    {
                        continue;
                    }

                    // Push Message
                    string appPath    = Path.GetDirectoryName(Application.ExecutablePath);
                    string stringPath = Path.Combine(appPath, "AppleCertificate", "Certificates.p12");
                    new Exception("certificate path:" + stringPath).Log();
                    //NotificationHelper.pushMessage(toDeviceId, notifyObj, stringPath);

                    bool pushStatus = NotificationHelper.pushMessage(toDeviceId, notifyObj, stringPath);
                    if (pushStatus == true)
                    {
                        // Update Notification IsPushStatus
                        var updatePushStatus = repository.UpdateNotificationPushStatus(NotificationId, ToUserId);
                        new EventsLog().Write("Push success");
                        new Exception("Push success:- \tDeviceId:" + toDeviceId + "\tUser: "******"\tMessage:" + Message).Log();
                    }
                    else
                    {
                        new Exception("Push failed:- \tDeviceId:" + toDeviceId + "\tUser: "******"\tMessage:" + Message).Log();
                    }
                }
                // var updatePushStatus = repository.UpdateNotificationPushStatus(NotificationId, ToUserId);
            }
        }