Ejemplo n.º 1
0
        /// <summary>
        /// Delete user form this app
        /// </summary>
        /// <param name="id"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <IHttpActionResult> Delete(long id, AppUserPut model)
        {
            var user = await DB.AppUsers.FirstOrDefaultAsync(x => x.AppID == id && x.Username == model.Username);

            if (user == null)
            {
                ThrowHttpError(HttpStatusCode.NotFound, "User not found in this app");
            }
            DB.AppUsers.Remove(user);
            await DB.SaveChangesAsync();

            return(Ok());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Grant access for this app
        /// </summary>
        /// <param name="id"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <IHttpActionResult> Put(long id, AppUserPut model)
        {
            var user = await DB.AppUsers.FirstOrDefaultAsync(x => x.AppID == id && x.Username == model.Username);

            if (user == null)
            {
                user = new AppUser {
                    AppID    = id,
                    Username = model.Username
                };
                DB.AppUsers.Add(user);
                await DB.SaveChangesAsync();
            }
            return(Ok());
        }