Esempio 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());
        }
Esempio n. 2
0
 public IEnumerable <Result> GetResult()
 {
     using (var context = new testmsdaContext(_dbOptions))
     {
         return(context.Result.ToList());
     }
 }
Esempio n. 3
0
 private bool UserExists(int id)
 {
     using (var context = new testmsdaContext(_dbOptions))
     {
         return(context.User.Any(e => e.UserId == id));
     }
 }
Esempio n. 4
0
 private bool ResultExists(int id)
 {
     using (var context = new testmsdaContext(_dbOptions))
     {
         return(context.Result.Any(e => e.ResultId == id));
     }
 }
Esempio n. 5
0
 public IEnumerable <User> GetUser()
 {
     using (var context = new testmsdaContext(_dbOptions))
     {
         return(context.User.ToList());
     }
 }
Esempio n. 6
0
 public IEnumerable <App> GetApp()
 {
     using (var context = new testmsdaContext(_dbOptions))
     {
         return(context.App.ToList());
     }
 }
Esempio n. 7
0
 public IEnumerable <Device> GetDevice()
 {
     using (var context = new testmsdaContext(_dbOptions))
     {
         return(context.Device.ToList());
     }
 }
Esempio n. 8
0
 private bool DeviceExists(int id)
 {
     using (var context = new testmsdaContext(_dbOptions))
     {
         return(context.Device.Any(e => e.DeviceId == id));
     }
 }
Esempio 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));
            }
        }
Esempio 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));
            }
        }
Esempio 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));
            }
        }
Esempio 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));
            }
        }
Esempio 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));
            }
        }
Esempio 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));
            }
        }
Esempio n. 15
0
 private bool AppExists(int id, testmsdaContext context)
 {
     return(context.App.Any(e => e.AppId == id));
 }