Beispiel #1
0
        public IActionResult Update(string id, [FromBody] ProfileTeacher _ProfileTeacher)
        {
            var tEntity = context.ProfileTeacher.FirstOrDefault(e => e.ProfileId.Equals(id));


            if (tEntity != null)
            {
                try
                {
                    tEntity.Address      = _ProfileTeacher.Address;
                    tEntity.DepartmentId = _ProfileTeacher.DepartmentId;
                    tEntity.Email        = _ProfileTeacher.Email;
                    tEntity.PhoneNumber  = _ProfileTeacher.PhoneNumber;
                    tEntity.Specialize   = _ProfileTeacher.Specialize;

                    context.ProfileTeacher.Update(tEntity);
                    context.SaveChanges();
                    return(Ok(true));
                }
                catch (Exception)
                {
                    return(Ok(false));
                }
            }
            return(Ok(false));
        }
        public IActionResult Update(string id, [FromBody] ProfileTeacher profileTeacher)
        {
            var entity = context.ProfileTeachers.FirstOrDefault(e => e.ProfileId.Equals(id)); //Trả về đối tượng (gv) đầu tiên trong danh sách tìm thấy

            //so sánh id của gv vs id truyền vào

            if (entity != null)
            {
                try
                {
                    entity.FullName     = profileTeacher.FullName;
                    entity.Email        = profileTeacher.Email;
                    entity.Address      = profileTeacher.Address;
                    entity.PhoneNumber  = profileTeacher.PhoneNumber;
                    entity.DepartmentId = profileTeacher.DepartmentId;
                    entity.Specialize   = profileTeacher.Specialize;


                    context.ProfileTeachers.Update(entity);
                    context.SaveChanges();
                    return(Ok(true));
                }

                catch (Exception)
                {
                    return(Ok(false));
                }
            }

            return(Ok(false));
        }
Beispiel #3
0
 public IActionResult Create([FromBody] ProfileTeacher _ProfileTeacher)
 {
     try{
         _ProfileTeacher.ProfileId = Guid.NewGuid() + "";
         context.ProfileTeacher.Add(_ProfileTeacher);
         context.SaveChanges();
         return(Ok(true));
     }catch {
         return(Ok(false));
     };
 }