Exemplo n.º 1
0
        public async Task <ActionResult> send_message()
        {
            var json = new StreamReader(Request.Body).ReadToEnd();
            var data = JsonConvert.DeserializeObject <JGN_Messages_Recipents>(json);

            var _message = await MessageBLL.sendMessage(_context, data);

            // receiver message info
            var info = await SiteConfig.userManager.FindByIdAsync(data.to_uid);

            if (info != null)
            {
                // await _emailSender.SendMessage(_context, model.ContactEmail, model);
            }

            // generate and push notification
            var notif = new JGN_Notifications()
            {
                sender_id         = data.message.from_uid,
                notification_type = (byte)NotificationTypes.Message,
                title             = "New Message Received",
                body         = data.message.subject,
                href         = Config.GetUrl(SystemDirectoryPaths.MessageUrl),
                recipient_id = data.to_uid
            };
            await NotificationBLL.postNotification(_context, notif);

            return(Ok(new { status = "success", message = "Message Sent", record = _message }));
        }
Exemplo n.º 2
0
        public static async Task <JGN_Notifications> postNotification(ApplicationDbContext context, JGN_Notifications entity)
        {
            // save message
            var notificationEntity = new JGN_Notifications()
            {
                sender_id         = entity.sender_id,
                notification_type = entity.notification_type,
                title             = entity.title,
                body         = entity.body,
                href         = entity.href,
                is_unread    = 1,
                recipient_id = entity.recipient_id,
                created_time = DateTime.Now
            };

            context.Entry(notificationEntity).State = EntityState.Added;
            await context.SaveChangesAsync();

            entity.id = notificationEntity.id;

            return(entity);
        }