Пример #1
0
        public async Task <IActionResult> PutDbUser(int id, DbUser dbUser)
        {
            if (id != dbUser.DbUserId)
            {
                return(BadRequest());
            }

            AdapterContext.Entry(dbUser).State = EntityState.Modified;

            try
            {
                await AdapterContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DbUserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <ActionResult <AdapterType> > PostAdapterType(AdapterType adapterType)
        {
            AdapterContext.AdapterTypes.Add(adapterType);
            await AdapterContext.SaveChangesAsync();

            return(CreatedAtAction("GetAdapterType", new { id = adapterType.AdapterTypeId }, adapterType));
        }
Пример #3
0
        public async Task <IActionResult> PutAdapterType(int id, AdapterType adapterType)
        {
            if (id != adapterType.AdapterTypeId)
            {
                return(BadRequest());
            }

            AdapterContext.Entry(adapterType).State = EntityState.Modified;

            try
            {
                await AdapterContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AdapterTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #4
0
        public async Task <ActionResult <DbUser> > DeleteDbUser(int id)
        {
            var dbUser = await AdapterContext.DbUsers.FindAsync(id);

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

            AdapterContext.DbUsers.Remove(dbUser);
            await AdapterContext.SaveChangesAsync();

            return(dbUser);
        }
Пример #5
0
        public async Task <ActionResult <AdapterType> > DeleteAdapterType(int id)
        {
            var adapterType = await AdapterContext.AdapterTypes.FindAsync(id);

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

            AdapterContext.AdapterTypes.Remove(adapterType);
            await AdapterContext.SaveChangesAsync();

            return(adapterType);
        }
Пример #6
0
        public async Task <ActionResult <DbUser> > PostDbUser([Bind("Username", "Description")] DbUser dbUser, CancellationToken cancellationToken)
        {
            if (dbUser == null)
            {
                return(Forbid());
            }

            var server = Startup.Configuration.GetSection("NfcServer").Value;

            var tag = await new NfcServerClient(server).ReadTagIdAsync(cancellationToken);

            if (tag.Data != Convert.ToInt32(Startup.Configuration.GetSection("AdminKey").Value))
            {
                return(Forbid());
            }

            dbUser.Authorized = true;

            AdapterContext.DbUsers.Add(dbUser);
            await AdapterContext.SaveChangesAsync();

            return(CreatedAtAction("GetDbUser", new { id = dbUser.DbUserId }, dbUser));
        }