示例#1
0
        public string Update <Employee>(int id, Library.Models.Employee empl)
        {
            try
            {
                Library.Models.Employee employee = context.Employees.Where(s => s.Id == id).FirstOrDefault();

                if (employee == null)
                {
                    return("Работника с таким именем нет в базе данных");
                }
                using (var dbCtx = new LibraryContext())
                {
                    employee.FIO                = empl.FIO;
                    employee.Phone              = empl.Phone;
                    employee.Department         = empl.Department;
                    dbCtx.Entry(employee).State = System.Data.Entity.EntityState.Modified;
                    dbCtx.SaveChanges();
                }

                context = new LibraryContext();
                return("Данные изменены");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#2
0
 public string Insert <Employee>(Library.Models.Employee employee)
 {
     try
     {
         context.Employees.Add(employee);
         context.SaveChanges();
         return("Запись была добавлена");
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#3
0
 public string Delete <Employee>(Library.Models.Employee employee)
 {
     try
     {
         var delBook = context.Employees.Find(employee.Id);
         context.Employees.Remove(delBook);
         context.SaveChanges();
         return("Запись удалена");
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }