Beispiel #1
0
        //Add new message
        public string AddNewMessage(string text, int?timesToShow, DateTime timeToDele, string pass)
        {
            try
            {
                //Hash link
                string hashLink = ExtFunc.Hash.GetLinkHash(
                    ExtFunc.LinkGenerator.Generate(32));

                int id = messageRep.GetMaxID();

                //Encrypt Message
                text = ExtFunc.Cryptograph.EncryptMessage(text, pass);

                //Create new instance of message
                DAL.Message message = new DAL.Message(id, text, timesToShow, hashLink, timeToDele);

                //Write new message in DB
                messageRep.AddNewMessage(message);

                //return result hash link
                return(hashLink);
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <IMessage> Create(IUserSummary user, string messageText, int conversationId)
        {
            if (string.IsNullOrWhiteSpace(messageText))
            {
                throw new ArgumentNullException("messageText");
            }
            if (conversationId <= 0)
            {
                throw new ArgumentOutOfRangeException("conversationId", conversationId, "The conversationId must be a valid value greater than 0.");
            }
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            if (user.Id <= 0 || string.IsNullOrWhiteSpace(user.DisplayName))
            {
                throw new ArgumentException("The IUserSummary could not be read. Please ensure to pass a valid instance with a hydrated id and display name.", "user");
            }

            var entity = new DAL.Message()
            {
                ConversationId  = conversationId,
                CreatedByUserId = user.Id,
                CreatedDateTime = DateTime.UtcNow,
                MessageText     = messageText
            };

            this._commandContext.Messages.Add(entity);
            await this._commandContext.SaveChangesAsync();

            var message = await this.GetById(entity.MessageId);

            message.SetCreatedUser(user);
            return(message);
        }
        public async Task SaveMessage(string message)
        {
            var DAL = new DAL.Message();

            await DAL.SaveMessage(message);

            DAL = null;
        }