Exemplo n.º 1
0
        public async Task <IActionResult> DeactivatePost([FromRoute][Required] int lockId, [FromHeader][Required()] string token)
        {
            await Db.Connection.OpenAsync();

            AuthenticationHandler auth = new AuthenticationHandler(Db);
            var authToken = auth.CheckAuth(token);

            if (authToken.Result != null)
            {
                if (await auth.CheckLockOwner(lockId, authToken.Result.Id) == true)
                {
                    // Get lock we want to update
                    LockQuerry lq    = new LockQuerry(Db);
                    var        locka = await lq.FindOneAsync(lockId);

                    // Update the lock
                    locka.OwnerId = null;
                    await locka.UpdateAsync();

                    Db.Dispose();
                    return(new OkObjectResult("Lock updated"));
                }
                Db.Dispose();
                return(StatusCode(403));
            }
            Db.Dispose();
            return(new UnauthorizedResult());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> ShareLockPost([FromRoute][Required] int lockId, [FromHeader][Required()] string token, [FromBody] Share body)
        {
            await Db.Connection.OpenAsync();

            AuthenticationHandler auth = new AuthenticationHandler(Db);
            var authToken = auth.CheckAuth(token);

            if (authToken.Result != null)
            {
                if (await auth.CheckLockOwner(lockId, authToken.Result.Id) == true)
                {
                    UserQuerry helper = new UserQuerry(Db);
                    // helper.
                    // Setup stuf to create the new rented
                    Rented rLock = new Rented(Db);
                    rLock.LockId    = lockId;
                    rLock.StartDate = body.StartDate;
                    rLock.EndDate   = body.EndDate;
                    rLock.UserId    = helper.GetUserByUsername(body.Username).Result.Id;

                    await rLock.InsertAsync();

                    Db.Dispose();
                    return(new OkObjectResult("Access Granted"));
                }

                Db.Dispose();
                return(new UnauthorizedResult());
            }
            Db.Dispose();
            return(new UnauthorizedResult());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> ChangelockdetailsPost([FromRoute][Required] int lockId, [FromHeader][Required()] string token, [FromBody] Lock body)
        {
            await Db.Connection.OpenAsync();

            AuthenticationHandler auth = new AuthenticationHandler(Db);
            var authToken = auth.CheckAuth(token);

            if (authToken.Result != null)
            {
                if (await auth.CheckLockOwner(lockId, authToken.Result.Id) == true)
                {
                    // Get lock we want to update
                    LockQuerry lq    = new LockQuerry(Db);
                    var        locka = await lq.FindOneAsync(lockId);

                    // Update the lock
                    if (body.Description != null)
                    {
                        locka.Description = body.Description;
                    }

                    if (body.DisplayName != null)
                    {
                        locka.DisplayName = body.DisplayName;
                    }
                    await locka.UpdateAsync();

                    Db.Dispose();
                    return(new OkObjectResult("Lock updated"));
                }
                Db.Dispose();
                return(new UnauthorizedResult());
            }
            Db.Dispose();
            return(new UnauthorizedResult());
        }