private void SetUpClient() { var builder = new WebHostBuilder() .UseStartup <Startup>() .ConfigureServices(services => { var context = new TestProjectContext(new DbContextOptionsBuilder <TestProjectContext>() .UseSqlite("DataSource=:memory:") .EnableSensitiveDataLogging() .Options); services.RemoveAll(typeof(TestProjectContext)); services.AddSingleton(context); context.Database.OpenConnection(); context.Database.EnsureCreated(); context.SaveChanges(); // Clear local context cache foreach (var entity in context.ChangeTracker.Entries().ToList()) { entity.State = EntityState.Detached; } }); _server = new TestServer(builder); Client = _server.CreateClient(); }
// PUT: api/Shedule/5 public void Put(Schedule value) { if (value != null && value.Id != 0) { using (var connection = ConnectToDataBase.GetConnection()) { connection.Open(); using (var context = new TestProjectContext()) { context.Schedules.Load(); var r = context.Schedules.Find(value.Id); if (r != null) { r.TeacherId = value.TeacherId; r.Data = value.Data; r.DisciplineId = value.DisciplineId; r.EndTime = value.EndTime; r.StartTime = value.StartTime; r.GroupId = value.GroupId; context.SaveChanges(); } } } } }
//GET: api/User public string Get() { try { var users = new List <User>(); using (var connection = ConnectToDataBase.GetConnection()) { connection.Open(); using (var context = new TestProjectContext()) { context.Users.Load(); users = context.Users.ToList(); return(JsonConvert.SerializeObject(users, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, ReferenceLoopHandling = ReferenceLoopHandling.Ignore })); } } } catch (Exception e) { Debug.WriteLine(e); throw; } }
// POST: api/User public void Post([FromBody] User value) { using (var connection = ConnectToDataBase.GetConnection()) { connection.Open(); using (var context = new TestProjectContext()) { context.Users.Load(); if (value != null) { context.Users.Add(value); context.SaveChanges(); } } } }
// DELETE: api/User/5 public void Delete(int id) { using (var connection = ConnectToDataBase.GetConnection()) { connection.Open(); using (var context = new TestProjectContext()) { var temp = context.Users.Find(id); if (temp != null) { context.Users.Load(); context.Users.Remove(temp); context.SaveChanges(); } } } }
// GET: api/Shedule/5 public Schedule Get(int id) { using (var connection = ConnectToDataBase.GetConnection()) { connection.Open(); var t = new Schedule(); using (var context = new TestProjectContext()) { context.Schedules.Load(); if (context.Schedules.Find(id) != null) { t = context.Schedules.Find(id); } } return(t); } }
// GET: api/Group/5 public Group Get(int id) { using (var connection = ConnectToDataBase.GetConnection()) { connection.Open(); var g = new Group(); using (var context = new TestProjectContext()) { context.Groups.Load(); if (context.Groups.Find(id) != null) { g = context.Groups.Find(id); } } return(g); } }
// GET: api/User/5 public User Get(int id) { using (var connection = ConnectToDataBase.GetConnection()) { connection.Open(); var u = new User(); using (var context = new TestProjectContext()) { context.Users.Load(); if (context.Users.Find(id) != null) { u = context.Users.Find(id); } } return(u); } }
// GET: api/Discipline/5 public Discipline Get(int id) { using (var connection = ConnectToDataBase.GetConnection()) { connection.Open(); var d = new Discipline(); using (var context = new TestProjectContext()) { context.Disciplines.Load(); if (context.Disciplines.Find(id) != null) { d = context.Disciplines.Find(id); } } return(d); } }
public JsonResult GetContact(ContactViewModel model) { try { TestProjectContext db = new TestProjectContext(); var contact = db.Contact.Where(a => !(a.Birthdate == null) && !(a.Nid == null)) .OrderBy(a => a.Nid ) .Skip(20 * (model.Page - 1)).Take(20).ToList(); return(Json(contact)); } catch (Exception ex) { return(Json(ex)); } }
// PUT: api/Group/5 public void Put(Group value) { using (var connection = ConnectToDataBase.GetConnection()) { connection.Open(); using (var context = new TestProjectContext()) { context.Groups.Load(); var r = context.Groups.Find(value.Id); if (r != null) { r.GroupName = value.GroupName; r.StartDate = value.StartDate; r.EndDate = value.EndDate; context.SaveChanges(); } } } }
// PUT: api/User/5 public void Put(User value) { using (var connection = ConnectToDataBase.GetConnection()) { connection.Open(); using (var context = new TestProjectContext()) { context.Users.Load(); var r = context.Users.Find(value.Id); if (r != null) { r.FullName = value.FullName; r.Login = value.Login; r.Password = value.Password; r.GroupId = value.GroupId; context.SaveChanges(); } } } }
// PUT: api/Discipline/5 public void Put(Discipline value) { if (value != null && value.DisciplineId != 0) { using (var connection = ConnectToDataBase.GetConnection()) { connection.Open(); using (var context = new TestProjectContext()) { context.Disciplines.Load(); var r = context.Disciplines.Find(value.DisciplineId); if (r != null) { r.DisciplineName = value.DisciplineName; r.TeacherId = value.TeacherId; context.SaveChanges(); } } } } }
// PUT: api/Teacher/5 public void Put(Teacher value) { if (value != null && value.Id != 0) { using (var connection = ConnectToDataBase.GetConnection()) { connection.Open(); using (var context = new TestProjectContext()) { context.Teachers.Load(); var r = context.Teachers.Find(value.Id); if (r != null) { r.FullName = value.FullName; r.Phone = value.Phone; context.SaveChanges(); } } } } }
public JsonResult CreateContact([FromBody] Contact model) { try { TestProjectContext db = new TestProjectContext(); var contact = new Contact(); contact.FirstName = model.FirstName; contact.LastName = model.LastName; contact.Birthdate = model.Birthdate; contact.Nid = model.Nid; db.Contact.Add(contact); db.SaveChanges(); return(Json(true)); } catch (Exception ex) { return(Json(ex)); } }
public void AddTransactionList(IList <TransactionData> t) { using (var context = new TestProjectContext()) { using (var transaction = context.Database.BeginTransaction()) { try { foreach (TransactionData Item in t) { _context.TransactionData.Add(Item); _context.SaveChanges(); } transaction.Commit(); } catch (Exception ex) { throw new Exception(ex.Message); } } } }
public JsonResult UpdateContact([FromBody] Contact model) { try { TestProjectContext db = new TestProjectContext(); var contact = db.Contact.Find(model.Id); if (contact != null) { contact.FirstName = model.FirstName; contact.LastName = model.LastName; contact.Nid = model.Nid; contact.Birthdate = model.Birthdate; db.SaveChanges(); } return(Json(contact)); } catch (Exception ex) { return(Json(ex)); } }
public UsersService(TestProjectContext testProjectContext) { _testProjectContext = testProjectContext; }
public AuthController(TestProjectContext testProjectContext) { _testProjectContext = testProjectContext; }
public BooksController(TestProjectContext context) { _context = context; }
public BooksService(TestProjectContext testProjectContext) { _testProjectContext = testProjectContext; }
public AdminRepository(TestProjectContext context) { _context = context as TestProjectContext; }
public AuthorsController(TestProjectContext context) { _context = context; }