Ejemplo n.º 1
0
        public HttpResponseMessage DeleteMessage(string messageId,
            [ValueProvider(typeof(HeaderValueProviderFactory<string>))]
            string accessToken)
        {
            var data = new MessagesRepository(
                    ConfigurationManager.AppSettings["MongoConnectionString"],
                    ConfigurationManager.AppSettings["Database"]);

            var user = this.GetUserByAccessToken(accessToken, data.Db);

            if (user == null)
            {
                return this.Request.CreateResponse(HttpStatusCode.Unauthorized);
            }

            var message = data.GetMessage(messageId);
            if (message == null)
            {
                return this.Request.CreateResponse(HttpStatusCode.BadRequest, messageId);
            }

            data.DeleteMessage(messageId);

            var response = this.Request.CreateResponse(HttpStatusCode.OK);
            return response;

        }
Ejemplo n.º 2
0
        public HttpResponseMessage GetMessage(string messageId,
            [ValueProvider(typeof(HeaderValueProviderFactory<string>))]
            string accessToken)
        {
            var data = new MessagesRepository(
                    ConfigurationManager.AppSettings["MongoConnectionString"],
                    ConfigurationManager.AppSettings["Database"]);
            var user = this.GetUserByAccessToken(accessToken, data.Db);

            if (user == null)
            {
                return this.Request.CreateResponse(HttpStatusCode.Unauthorized);
            }

            var message = data.GetMessage(messageId);
            if (message == null)
            {
                return this.Request.CreateResponse(HttpStatusCode.BadRequest, messageId);
            }

            var responceMessage = new MessageResponceModel()
                                 {
                                     BodyHtml = message.BodyHtml,
                                     BodyPlain = message.BodyPlain,
                                     Date = message.Date,
                                     Id = message.Id,
                                     Recipient = message.Recipient,
                                     Sender = message.Sender,
                                     Subject = message.Subject
                                 };

            var response = this.Request.CreateResponse(HttpStatusCode.OK, responceMessage);
            return response;
        }