コード例 #1
0
ファイル: DAL.cs プロジェクト: Roshinigurram/c-practice
 public void DeleteDepartment(int departmentId)
 {
     using (Training2020DbContext context = new Training2020DbContext())
     {
         var department = context.Departments.Where(d => d.DepartmentId == departmentId).FirstOrDefault();
         if (department != null)
         {
             context.Departments.Remove(department);
             context.SaveChanges();
         }
     }
 }
コード例 #2
0
ファイル: DAL.cs プロジェクト: Roshinigurram/c-practice
        public void AddDepartment(string departmentName)
        {
            using (Training2020DbContext context = new Training2020DbContext())
            {
                Department department = new Department()
                {
                    Name = departmentName
                };

                context.Departments.Add(department);
                context.SaveChanges();
            }
        }
コード例 #3
0
ファイル: DAL.cs プロジェクト: Roshinigurram/c-practice
        public void UpdateDepartment(int departmentId, string newDepartmentName)
        {
            using (Training2020DbContext context = new Training2020DbContext())
            {
                //var department = context.Departments.Find(departmentId);

                var department = context.Departments.Where(d => d.DepartmentId == departmentId).FirstOrDefault();
                if (department != null)
                {
                    department.Name = newDepartmentName;
                    context.Entry(department).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                    context.SaveChanges();
                }
            }
        }