예제 #1
0
        public IActionResult AddTeacherToGroup(AddTeacherToGroupViewModel addTeacher)
        {
            if (ModelState.IsValid)
            {
                using (HttpClient client = new HttpClient())
                {
                    GroupTeacher groupTeacher = new GroupTeacher()
                    {
                        GroupID   = addTeacher.GroupId,
                        TeacherID = addTeacher.TeacherId
                    };
                    var data    = JsonConvert.SerializeObject(groupTeacher);
                    var content = new StringContent(data, Encoding.UTF8, "application/json");
                    var url     = ($"http://localhost:56825/api/Group/AddTeacherToGroup?groupId={groupTeacher.GroupID}&teacherId={groupTeacher.TeacherID}");
                    var resp    = client.PostAsync($"{url}", content).Result;
                    if (resp.IsSuccessStatusCode)
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        return(RedirectToAction("Error"));
                    }
                }
            }


            return(View(addTeacher));
        }
예제 #2
0
 public bool AssignTeacher(int groupId, int teacherId)
 {
     try
     {
         var newRecord = new GroupTeacher()
         {
             GroupId   = groupId,
             TeacherId = teacherId
         };
         _context.GroupTeachers.Add(newRecord);
         _context.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public bool AddTeacherToGroup(int teacherId, int groupId)
 {
     try
     {
         var newRelationship = new GroupTeacher()
         {
             TeacherId      = teacherId,
             CreateDatetime = DateTime.UtcNow,
             CreateUser     = "******",
             GroupId        = groupId
         };
         _context.GroupTeachers.Add(newRelationship);
         _context.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }