Example #1
0
        // POST api/Announcement

        public async Task <HttpResponseMessage> Post(string password, [FromBody] string message)
        {
            if (string.IsNullOrWhiteSpace(message) || password != ConfigurationManager.AppSettings["NotificationsPassword"])
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden));
            }

            try
            {
                var accounenement = new Notification
                {
                    Date = DateTime.UtcNow,
                    Text = message,
                    Id   = Guid.NewGuid().ToString()
                };

                var context = new Techdays2016Repository();

                context.Notifications.Add(accounenement);

                await context.SaveChangesAsync();
            }
            catch
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }