public JsonResult Add(List <string> list, string IDGV)
 {
     foreach (var i in list)
     {
         var sb = StudentTeacherService.getByStudentId(Convert.ToInt32(i));
         if (sb == null)
         {
             var model = new StudentTeacherRelationship
             {
                 StudentID = Convert.ToInt32(i),
                 TeacherID = Convert.ToInt32(IDGV),
                 CreateBy  = Convert.ToInt32(Session["UserId"])
             };
             StudentTeacherService.Create(model);
         }
         else
         {
             var model = new StudentTeacherRelationship
             {
                 StudentID = Convert.ToInt32(i),
                 TeacherID = Convert.ToInt32(IDGV),
                 ModifyBy  = Convert.ToInt32(Session["UserId"])
             };
             StudentTeacherService.Update(model);
         }
     }
     return(Json(true, JsonRequestBehavior.AllowGet));
 }
Exemplo n.º 2
0
        public bool Create(StudentTeacherRelationship model)
        {
            try
            {
                //Initialization empty item
                var item = new StudentTeacherRelationship();

                //Set value for item with value from model
                item.StudentID  = model.StudentID;
                item.TeacherID  = model.TeacherID;
                item.CreateBy   = model.CreateBy;
                item.CreateTime = DateTime.Now;


                //Add item to entity
                context.StudentTeacherRelationships.Add(item);
                //Save to database
                context.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 3
0
 public bool Update(StudentTeacherRelationship model)
 {
     try
     {
         if (model == null)
         {
             return(false);
         }
         var update = studentTeacherDAL.Update(model);
         return(update);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 4
0
        public bool Update(StudentTeacherRelationship model)
        {
            try
            {
                //Initialization empty item
                var item = context.StudentTeacherRelationships.Where(i => i.StudentID == model.StudentID && (i.IsDeleted == false || i.IsDeleted.Equals(null))).FirstOrDefault();

                //Set value for item with value from model
                item.TeacherID  = model.TeacherID;
                item.ModifyBy   = model.ModifyBy;
                item.CreateTime = DateTime.Now;


                //Save change to database
                context.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }