Ejemplo n.º 1
0
        public async Task <ActionResult> PublishTime(
            PublishTimeJson payload)
        {
            var getHost = new GetHandle(
                sub: GetUserId(),
                handle: payload.Handle
                );
            var foundHost = (await _db.Submit(_creds, getHost))
                            .SingleOrDefault();

            if (foundHost == null)
            {
                return(NotFound());
            }

            var getConflict = new PublishedTimeConflict(
                sub: GetUserId(),
                start: payload.Start,
                end: payload.End
                );
            var conflict = (await _db.Submit(_creds, getConflict))
                           .SingleOrDefault();

            if (conflict != null)
            {
                return(Conflict());
            }

            var addTime = new AddTime(
                sub: GetUserId(),
                t: new PublishedTime(
                    start: payload.Start,
                    end: payload.End,
                    hostHandle: payload.Handle,
                    record: payload.Name
                    )
                );
            var r = await _db.SubmitCommand(_creds, addTime);

            if (r == 1)
            {
                return(Created($"times/{payload.Start}", payload));
            }
            else
            {
                _log.LogWarning($"Failed to insert time for {payload.Handle}/{payload.Start}");
                return(BadRequest());
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> GetHost(
            string handle)
        {
            var found = new GetHandle(
                sub: GetUserId(),
                handle: handle
                );
            var r = (await _db.Submit(_creds, found))
                    .SingleOrDefault();

            if (r != null)
            {
                return(Ok());
            }
            else
            {
                return(NotFound());
            }
        }