Esempio n. 1
0
        public async Task <bool> SubscribeAsync(string message)
        {
            //validate message
            Message msg = JsonConvert.DeserializeObject <Message>(message);

            if (!msg.IsValidate || msg.SubscriberId.IsNullOrEmpty() || msg.TargetId.IsNullOrEmpty())
            {
                _logger.Error(AlterKeys.Error.MESSAGE_INVALID, new string[] { msg.Id });
                return(false);
            }

            var topicObj = await _topicService.GetTopicAsync(msg.Topic, msg.ServiceId);

            if (topicObj.IsNull())
            {
                return(false);
            }

            msg.Id          = Guid.NewGuid().ToString();
            msg.TopicId     = topicObj.Id;
            msg.TypeId      = StaticKeys.MessageTypeId_Subscribe;
            msg.ReceiveTime = DateTime.UtcNow;
            if (!MessageDb.Insert(msg))
            {
                return(false);
            }

            // handle message logic
            var subscribe = new Subscribe(Guid.NewGuid().ToString(), msg.ServiceId, msg.TopicId, msg.SubscriberId, msg.TargetId);

            return(await _subscribeService.SubscribeAsync(subscribe));
        }
Esempio n. 2
0
        public static bool Read(SqliteDataReader row, out MessageDb result)
        {
            bool message = false, channel = false, author = false, content = false;

            result = default;
            for (var i = 0; i < row.FieldCount; i++)
            {
                switch (row.GetName(i))
                {
                case "message_id":
                    result.MessageId = Convert.ToUInt64(row.GetValue(i));
                    message          = true;
                    break;

                case "channel_id":
                    result.ChannelId = Convert.ToUInt64(row.GetValue(i));
                    channel          = true;
                    break;

                case "author_id":
                    result.AuthorId = Convert.ToUInt64(row.GetValue(i));
                    author          = true;
                    break;

                case "message":
                    result.Message = (string)row.GetValue(i);
                    content        = true;
                    break;
                }
            }
            return(message && channel && author && content);
        }
Esempio n. 3
0
 // GET: Account
 public ActionResult Messages()
 {
     using (MessageDb db = new MessageDb())
     {
         return(View(db.message.ToList()));
     }
 }
Esempio n. 4
0
        public async Task <IActionResult> Message(MessageModel message, [FromQuery(Name = "shopID")] string shopID, [FromQuery(Name = "vehReqID")] string vehReqID)
        {
            if (ModelState.IsValid)
            {
                MessageDb messageDb = new MessageDb
                {
                    VehReqId    = int.Parse(vehReqID),
                    UserId      = int.Parse(shopID),
                    Message     = message.TextMessage,
                    MessageDate = message.DateMessage
                };

                bool result = await _repo.CreateMessage(messageDb);

                if (result)
                {
                    ViewBag.MessageSent = "Message Have been Sent";
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Couldn't Add Shop Services. Try Again With Cookies Enabled");
                }
            }

            return(RedirectToAction("ShopPortfolio", "AutoPort"));
            //return RedirectToAction("ShopPortfolio", "AutoPort", new { id = shopID, status = true });
        }
Esempio n. 5
0
        public async Task <ActionResult> UserCreate(CreateView ViewMessage)
        {
            UserDb UserSession = (UserDb)Session["User"];

            if (ViewMessage.UserDbId == UserSession.Id)
            {
                var user = await db.Users.FirstOrDefaultAsync(f => f.Id == UserSession.Id);

                MessageDb Message = new MessageDb();

                Message.UserDbId   = ViewMessage.UserDbId;
                Message.Company    = ViewMessage.Company;
                Message.Subject    = ViewMessage.Subject;
                Message.Message    = ViewMessage.Message;
                Message.FullName   = user.FirstName + " " + user.LastName;
                Message.Phone      = user.PhoneNumber;
                Message.CreateDate = DateTime.Now;
                Message.FromMail   = user.Mail;
                Message.ToMail     = "kenanbagirov14gmail.com";
                Message.Read       = true;
                db.Messages.Add(Message);
                await db.SaveChangesAsync();

                return(RedirectToAction("UserIndexMsg", new { id = UserSession.Id }));
            }
            else
            {
                return(RedirectToAction("Index", "MyAccount"));
            }
        }
Esempio n. 6
0
        public Message Map(MessageDb message)
        {
            Message message_newType = new Message();

            #region Transfer main attributes

            message_newType.Id         = message.Id;
            message_newType.Content    = message.Content;
            message_newType.CreateDate = message.CreateDate;
            message_newType.IsRead     = message.IsRead;

            #endregion

            #region Transfering interop attributes

            message_newType.IdChat = new Chat()
            {
                Id = message.IdChat
            };
            message_newType.IdSender = new User()
            {
                Id = message.IdSender
            };

            #endregion

            return(message_newType);
        }
        /// <summary>
        /// Return the MessageDb object with interop properties
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public MessageDb GetExtended(long id)
        {
            MessageDb message = Get(id);

            //message.PlayersList = GetPlayersList(id);

            return(message);
        }
Esempio n. 8
0
        public async Task <bool> DelMessageObject(MessageDb messageDb)
        {
            context.Remove(messageDb);

            await context.SaveChangesAsync();

            return(await Task.FromResult(true));
        }
Esempio n. 9
0
        public async Task <bool> CreateMessage(MessageDb message)
        {
            await context.AddAsync(message);

            await context.SaveChangesAsync();

            return(await Task.FromResult(true));
        }
Esempio n. 10
0
        private static async void CheckMessagesToDeleteAsync()
        {
            while (true)
            {
                await MessageDb.CheckMessageToDelete();

                Thread.Sleep(20 * 1000); //20 sec
            }
        }
Esempio n. 11
0
        // Here they will be

        #endregion

        #endregion

        public long Save(MessageDb message)
        {
            EntityORM entity = EntityMapping.Map(message, attributes);

            // Making sure that ID value is not touched.
            entity.attributeValue.Remove("ID");

            long idMessage = crud.Create(table, idColumn, entity);

            return(idMessage);
        }
Esempio n. 12
0
        private static async void CheckMessagesToSend()
        {
            while (true)
            {
                await MessageDb.CheckMessagesToSend(false, null);

                Thread.Sleep(20 * 1000); //20 sec
            }

            // ReSharper disable once FunctionNeverReturns
        }
Esempio n. 13
0
        public Message Get(long id)
        {
            MessageDb message          = messageDAO.GetExtended(id);
            Message   message_newTyped = null;

            if (message != null)
            {
                message_newTyped = mapper.Map(message);
            }

            return(message_newTyped);
        }
Esempio n. 14
0
        public MessageDb Get(long id)
        {
            MessageDb message = null;

            EntityORM entity = crud.Read(id, idColumn, attributes, table);

            if (entity != null)
            {
                EntityMapping.Map(entity, out message);
            }

            return(message);
        }
Esempio n. 15
0
        public MessageDb Get(long id)
        {
            MessageDb message = null;

            List <EntityORM> entities = (List <EntityORM>)(crud.Read(table, attributes, new DbTools.WhereRequest[] { new DbTools.WhereRequest(idColumn, DbTools.RequestOperator.Equal, id) }));

            if (entities.Any())
            {
                EntityMapping.Map(entities[0], out message);
            }

            return(message);
        }
Esempio n. 16
0
        public Guid SaveMessage(string messageText)
        {
            var message = new MessageDb
            {
                Date   = DateTime.UtcNow,
                Id     = Guid.NewGuid(),
                Number = ++_lastNumber,
                Text   = messageText
            };

            _messages.Add(message);
            return(message.Id);
        }
Esempio n. 17
0
        public int UpdateMessage(MessageDb messageDb)
        {
            string str = "update MessageDb set titleMess =@titleMess,textMess=@textMess where no=1 ";

            SqlParameter[] pars =
            {
                new SqlParameter("@titleMess", SqlDbType.VarChar, 50),
                new SqlParameter("@textMess",  SqlDbType.Text),
            };
            pars[0].Value = messageDb.TitleMes;
            pars[1].Value = messageDb.TextMes;

            return(SqlHelper.GetExecuteNonQuery(str, CommandType.Text, pars));
        }
Esempio n. 18
0
        public async Task <ActionResult> Create(AdminCreate ViewMessage)
        {
            MessageDb Message = new MessageDb();

            Message.CreateDate         = DateTime.Now;
            Message.ToMesssageUserDbId = ViewMessage.ToMesssageUserDbId;
            Message.Subject            = ViewMessage.Subject;
            Message.Message            = ViewMessage.Message;
            Message.ToMail             = (await db.Users.FirstOrDefaultAsync(f => f.Id == ViewMessage.ToMesssageUserDbId)).Mail;
            Message.FromMail           = "*****@*****.**";
            db.Messages.Add(Message);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Esempio n. 19
0
        private ChatMessage FromMessageDb(MessageDb message)
        {
            if (message == null)
            {
                return(null);
            }

            return(new ChatMessage
            {
                MessageId = message.Id,
                Text = message.Text,
                CreatedUtcDate = message.CreatedUtc,
                IsMy = message.UserId == UserId,
            });
        }
Esempio n. 20
0
        public MessageDb getMessage()
        {
            string    str     = "select * from MessageDB";
            DataTable da      = SqlHelper.GetTable(str, CommandType.Text);
            MessageDb message = new MessageDb();

            if (da.Rows.Count > 0)
            {
                foreach (DataRow datarow in da.Rows)
                {
                    LoadMessageDb(datarow, message);
                }
            }
            return(message);
        }
Esempio n. 21
0
        public WSR_Result DeleteMessage(string idmessage)
        {
            object     data   = null;
            WSR_Result result = null;

            if (result == null)
            {
                MessageDb db = new MessageDb();
                data = db.DeleteMessage(Convert.ToInt32(idmessage));
                return(new WSR_Result(data, true));
            }
            else
            {
                return(result);
            }
        }
Esempio n. 22
0
        public WSR_Result GetMessagesByUser(string iduser)
        {
            object     data   = null;
            WSR_Result result = null;

            if (result == null)
            {
                MessageDb db = new MessageDb();
                data = db.GetMessageByUser(Convert.ToInt32(iduser));
                return(new WSR_Result(data, true));
            }
            else
            {
                return(result);
            }
        }
Esempio n. 23
0
        public WSR_Result GetMessages()
        {
            object     data   = null;
            WSR_Result result = null;

            if (result == null)
            {
                MessageDb db = new MessageDb();
                data = db.GetAll();
                return(new WSR_Result(data, true));
            }
            else
            {
                return(result);
            }
        }
Esempio n. 24
0
        public ActionResult LoggedIn(Message message)
        {
            if (ModelState.IsValid)
            {
                using (MessageDb db = new MessageDb())
                {
                    db.message.Add(message);
                    db.SaveChanges();
                }

                ModelState.Clear();
                ViewBag.Message = message.Receiver + " " + message.Subject + "successfully stored.";
            }

            return(View());
        }
Esempio n. 25
0
        public async Task <JsonResult> GuestMesage(UserMessage Message)
        {
            MessageDb NewMessage = new MessageDb();

            NewMessage.FullName   = Message.FullName;
            NewMessage.Message    = Message.Message;
            NewMessage.Phone      = Message.Phone;
            NewMessage.Subject    = Message.Subject;
            NewMessage.CreateDate = DateTime.Now;
            NewMessage.ToMail     = "*****@*****.**";
            NewMessage.FromMail   = Message.Email;

            db.Messages.Add(NewMessage);
            await db.SaveChangesAsync();

            return(Json(new { succses = true }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 26
0
        public void Update(MessageDb message)
        {
            EntityORM entity = EntityMapping.Map(message, attributes);

            // Making sure that ID value is not touched
            entity.attributeValue.Remove("ID");

            bool ifUpdated = crud.Update(message.Id, table, idColumn, entity);

            if (ifUpdated)
            {
                logger.Info($"Game with id={message.Id} was successfully updated.");
            }
            else
            {
                logger.Info($"Updating message with id={message.Id} was failed.");
            }
        }
Esempio n. 27
0
        public WSR_Result SaveMessage(WSR_Param param)
        {
            MessageDTO message = null;
            object     data    = null;
            WSR_Result result  = null;

            result = VerifParamType(param, "save", out message);

            if (result == null)
            {
                message = (MessageDTO)param["save"];
                MessageDb db = new MessageDb();
                db.SaveMessage(ref message);
                data = message;
                return(new WSR_Result(data, true));
            }
            else
            {
                return(result);
            }
        }
Esempio n. 28
0
        ///<summary>
        ///Maps properties from MessageDb object to EntityORM object
        ///</summary>
        public static EntityORM Map(MessageDb message, HashSet <string> attributes)
        {
            EntityORM entity = new EntityORM();

            foreach (string attribute in attributes)
            {
                object value = null;        // attribute value

                switch (attribute)
                {
                case "IDSENDER":
                    value = message.IdSender;
                    break;

                case "IDCHAT":
                    value = message.IdChat;
                    break;

                case "CONTENT":
                    value = $"\'{message.Content}\'";
                    break;

                case "CREATEDATE":
                    value = $"\'{message.CreateDate.ToString("dd-MMM-yyyy")}\'";
                    break;

                case "ISREAD":
                    value = (message.IsRead) ? "\'y\'" : "\'n\'";
                    break;

                default:
                    break;
                }

                entity.attributeValue.Add(attribute, value);
            }

            return(entity);
        }
Esempio n. 29
0
        public List <MessageLogic> GetMessageList(string receiver)
        {
            MessageDb connection = new MessageDb();

            DataTable dataTable = connection.GetMessages(receiver);

            List <MessageLogic> list = new List <MessageLogic>();

            foreach (DataRow dr in dataTable.Rows)
            {
                MessageLogic message = new MessageLogic();
                message.id       = Convert.ToInt32(dr["Id"]);
                message.sender   = dr["Sender"].ToString();
                message.receiver = dr["Receiver"].ToString();
                message.text     = dr["Text"].ToString();
                message.date     = Convert.ToDateTime(dr["Date"]);
                message.title    = dr["Title"].ToString();

                list.Add(message);
            }
            return(list);
        }
Esempio n. 30
0
        public async Task <bool> AnnounceAsync(Message message)
        {
            if (!message.IsValidate)
            {
                return(false);
            }

            var topicObj = await _topicService.GetTopicAsync(message.TopicId);

            if (topicObj.IsNull())
            {
                return(false);
            }

            message.Id          = Guid.NewGuid().ToString();
            message.TopicId     = topicObj.Id;
            message.TypeId      = StaticKeys.MessageTypeId_Announce;
            message.SendTime    = DateTime.UtcNow;
            message.ReceiveTime = DateTime.UtcNow;

            return(MessageDb.Insert(message));
        }
Esempio n. 31
0
 public MessageHandler()
 {
     messageDb = new MessageDb();
         currentlyLoggedUserName = HttpContext.Current.User.Identity.Name;
         currentlyLoggedUserID = Membership.GetUser(currentlyLoggedUserName).ProviderUserKey.ToString();
 }