Пример #1
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();
                 }
             }
         }
     }
 }
Пример #2
0
        // POST: api/Authorization
        public string Post([FromBody] User value)
        {
            User user = null;

            using (var connection = ConnectToDataBase.GetConnection())
            {
                connection.Open();
                using (SQLiteCommand fmd = connection.CreateCommand())
                {
                    fmd.CommandText = $"Select * from user t where t.login ='******' and t.password='******'";
                    fmd.CommandType = CommandType.Text;
                    SQLiteDataReader reader = fmd.ExecuteReader();
                    while (reader.Read())
                    {
                        user = new User
                        {
                            GroupId  = Convert.ToInt32(reader["group_id"]),
                            FullName = Convert.ToString(reader["fullname"]),
                            Login    = Convert.ToString(reader["login"]),
                            Password = Convert.ToString(reader["password"])
                        };
                    }
                    return(user != null
                        ? JsonConvert.SerializeObject(user, Formatting.None,
                                                      new JsonSerializerSettings
                    {
                        NullValueHandling = NullValueHandling.Ignore,
                        ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                    })
                        : null);
                }
            }
        }
Пример #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
 // 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);
     }
 }
Пример #6
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();
             }
         }
     }
 }
Пример #7
0
 // 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/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);
     }
 }
Пример #9
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);
     }
 }
Пример #10
0
 // 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();
             }
         }
     }
 }
Пример #11
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();
             }
         }
     }
 }
Пример #12
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();
                 }
             }
         }
     }
 }
Пример #13
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();
                 }
             }
         }
     }
 }