Example #1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "rooms/{id}")] HttpRequest req, string id,
            ILogger log)
        {
            var guid = new Guid(id);
            var room = _context.Rooms
                       .Where(r => r.Id.Equals(guid))
                       .Include(r => r.Messages)
                       .Single();

            string json = await req.ReadAsStringAsync();

            var body    = JsonConvert.DeserializeObject <Message>(json);
            var message = new Message
            {
                Id          = Guid.NewGuid(),
                MessageText = body.MessageText,
                UserNick    = body.UserNick
            };

            room.Messages.Add(message);
            await _context.SaveChangesAsync();

            return(new OkObjectResult(message.Id));
        }
Example #2
0
        public async Task <IActionResult> Get(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            string name = req.Query["name"];

            var room = new BrainstormingRoom {
                Id = Guid.NewGuid(), Name = name
            };

            await _context.AddAsync(room);

            await _context.SaveChangesAsync();

            return(new OkObjectResult(room.Id));
        }
Example #3
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "delete", Route = "rooms/{msgId}")] HttpRequest req,
            string msgId,
            ILogger log)
        {
            //var guid = new Guid(msgId);

            var message = _context.Messages.Where(m => m.Id.ToString() == msgId).SingleOrDefault();

            if (null == message)
            {
                return(new NotFoundResult());
            }

            message.MessageArchived = DateTime.UtcNow;

            await _context.SaveChangesAsync();

            return(new OkResult());
        }