Exemplo n.º 1
0
        public async Task <IActionResult> PutResult([FromRoute] int id, [FromBody] Result result)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != result.ResultId)
            {
                return(BadRequest());
            }

            using (var context = new testmsdaContext(_dbOptions))
            {
                context.Entry(result).State = EntityState.Modified;

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

            return(NoContent());
        }
Exemplo n.º 2
0
 public IEnumerable <Result> GetResult()
 {
     using (var context = new testmsdaContext(_dbOptions))
     {
         return(context.Result.ToList());
     }
 }
Exemplo n.º 3
0
 private bool UserExists(int id)
 {
     using (var context = new testmsdaContext(_dbOptions))
     {
         return(context.User.Any(e => e.UserId == id));
     }
 }
Exemplo n.º 4
0
 private bool ResultExists(int id)
 {
     using (var context = new testmsdaContext(_dbOptions))
     {
         return(context.Result.Any(e => e.ResultId == id));
     }
 }
Exemplo n.º 5
0
 public IEnumerable <User> GetUser()
 {
     using (var context = new testmsdaContext(_dbOptions))
     {
         return(context.User.ToList());
     }
 }
Exemplo n.º 6
0
 public IEnumerable <App> GetApp()
 {
     using (var context = new testmsdaContext(_dbOptions))
     {
         return(context.App.ToList());
     }
 }
Exemplo n.º 7
0
 public IEnumerable <Device> GetDevice()
 {
     using (var context = new testmsdaContext(_dbOptions))
     {
         return(context.Device.ToList());
     }
 }
Exemplo n.º 8
0
 private bool DeviceExists(int id)
 {
     using (var context = new testmsdaContext(_dbOptions))
     {
         return(context.Device.Any(e => e.DeviceId == id));
     }
 }
Exemplo n.º 9
0
        public async Task <IActionResult> PostResult([FromBody] Result result)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (var context = new testmsdaContext(_dbOptions))
            {
                context.Result.Add(result);
                await context.SaveChangesAsync();

                return(CreatedAtAction("GetResult", new { id = result.ResultId }, result));
            }
        }
Exemplo n.º 10
0
        public async Task <IActionResult> PostUser([FromBody] User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (var context = new testmsdaContext(_dbOptions))
            {
                context.User.Add(user);
                await context.SaveChangesAsync();

                return(CreatedAtAction("GetUser", new { id = user.UserId }, user));
            }
        }
Exemplo n.º 11
0
        public async Task <IActionResult> PostApp([FromBody] App app)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (var context = new testmsdaContext(_dbOptions))
            {
                context.App.Add(app);
                await context.SaveChangesAsync();

                return(CreatedAtAction("GetApp", new { id = app.AppId }, app));
            }
        }
Exemplo n.º 12
0
        public async Task <IActionResult> PostDevice([FromBody] Device device)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (var context = new testmsdaContext(_dbOptions))
            {
                context.Device.Add(device);
                await context.SaveChangesAsync();

                return(CreatedAtAction("GetDevice", new { id = device.DeviceId }, device));
            }
        }
Exemplo n.º 13
0
        public async Task <IActionResult> GetResult([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (var context = new testmsdaContext(_dbOptions))
            {
                var result = await context.Result.FindAsync(id);

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

                return(Ok(result));
            }
        }
Exemplo n.º 14
0
        public async Task <IActionResult> DeleteUser([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (var context = new testmsdaContext(_dbOptions))
            {
                var user = await context.User.FindAsync(id);

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

                context.User.Remove(user);
                await context.SaveChangesAsync();

                return(Ok(user));
            }
        }
Exemplo n.º 15
0
 private bool AppExists(int id, testmsdaContext context)
 {
     return(context.App.Any(e => e.AppId == id));
 }