コード例 #1
0
        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();
        }
コード例 #2
0
 // 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();
                 }
             }
         }
     }
 }
コード例 #3
0
 //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;
     }
 }
コード例 #4
0
 // 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();
             }
         }
     }
 }
コード例 #5
0
 // 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();
             }
         }
     }
 }
コード例 #6
0
 // 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);
     }
 }
コード例 #7
0
ファイル: GroupController.cs プロジェクト: Spaaay/TestProject
 // 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);
     }
 }
コード例 #8
0
 // 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);
     }
 }
コード例 #9
0
 // 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);
     }
 }
コード例 #10
0
        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));
            }
        }
コード例 #11
0
ファイル: GroupController.cs プロジェクト: Spaaay/TestProject
 // 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();
             }
         }
     }
 }
コード例 #12
0
 // 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();
             }
         }
     }
 }
コード例 #13
0
 // 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();
                 }
             }
         }
     }
 }
コード例 #14
0
 // 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();
                 }
             }
         }
     }
 }
コード例 #15
0
        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));
            }
        }
コード例 #16
0
 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);
             }
         }
     }
 }
コード例 #17
0
        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));
            }
        }
コード例 #18
0
 public UsersService(TestProjectContext testProjectContext)
 {
     _testProjectContext = testProjectContext;
 }
コード例 #19
0
 public AuthController(TestProjectContext testProjectContext)
 {
     _testProjectContext = testProjectContext;
 }
コード例 #20
0
 public BooksController(TestProjectContext context)
 {
     _context = context;
 }
コード例 #21
0
 public BooksService(TestProjectContext testProjectContext)
 {
     _testProjectContext = testProjectContext;
 }
コード例 #22
0
 public AdminRepository(TestProjectContext context)
 {
     _context = context as TestProjectContext;
 }
コード例 #23
0
 public AuthorsController(TestProjectContext context)
 {
     _context = context;
 }