public ManagersController(EmsContext context) { _context = context; if (Startup.ResetManagerDatabase == true) { Startup.ResetManagerDatabase = false; _context.Managers.RemoveRange(_context.Managers); _context.SaveChanges(); var vighnesh = _context.Employees.Where(e => e.Name == "Vighnesh").First().Id; var omkar = _context.Employees.Where(e => e.Name == "Omkar").First().Id; var bhanu = _context.Employees.Where(e => e.Name == "Bhanu").First().Id; var shubham = _context.Employees.Where(e => e.Name == "Shubham").First().Id; _context.Managers.Add(new Managers { EmployeeId = shubham, ManagerId = omkar }); _context.Managers.Add(new Managers { EmployeeId = bhanu, ManagerId = omkar }); _context.Managers.Add(new Managers { EmployeeId = omkar, ManagerId = vighnesh }); _context.SaveChanges(); } }
public EmployeesController(EmsContext context) { _context = context; if (Startup.ResetEmployeeDatabase == true) { Startup.ResetEmployeeDatabase = false; _context.Employees.RemoveRange(_context.Employees); _context.SaveChanges(); _context.Employees.Add(new Employee { Name = "Vighnesh", Age = 21, Salary = 10000000 }); _context.Employees.Add(new Employee { Name = "Shubham", Age = 30, Salary = 1232123 }); _context.Employees.Add(new Employee { Name = "Omkar", Age = 32, Salary = 131232 }); _context.Employees.Add(new Employee { Name = "Bhanu", Age = 45, Salary = 12313200 }); _context.SaveChanges(); } }
public bool Add(Department entity) { try { context.Departments.Add(entity); var result = context.SaveChanges(); if (result > 0) { return(true); } return(false); } catch (Exception ex) { throw ex; } }
private bool InsertAlarmIntoDb(AlarmHelper alarm) { bool success = true; EmsContext ems = new EmsContext(); try { Alarm a = new Alarm() { Gid = alarm.Gid, AlarmValue = alarm.Value, MinValue = alarm.MinValue, MaxValue = alarm.MaxValue, AlarmTimeStamp = alarm.TimeStamp, AckState = alarm.AckState, AlarmType = alarm.Type, AlarmMessage = alarm.Message, Severity = alarm.Severity, CurrentState = alarm.CurrentState }; ems.Alarms.Add(a); ems.SaveChanges(); } catch (Exception e) { success = false; string message = string.Format("Failed to insert alarm into database. {0}", e.Message); CommonTrace.WriteTrace(CommonTrace.TraceError, message); Console.WriteLine(message); } return(success); }
public ManagerController(EmsContext context) { _context = context; if (_context._managers.Count() == 0) { _context._managers.Add(new Manager { Name = "vighnesh", Salary = 600000 }); _context._managers.Add(new Manager { Name = "shubham", Salary = 600000 }); _context._managers.Add(new Manager { Name = "bhanu", Salary = 600000 }); _context._managers.Add(new Manager { Name = "raunak", Salary = 600000 }); _context._managers.Add(new Manager { Name = "omkar", Salary = 600000 }); _context.SaveChanges(); } }
public void Add(TEntity entity) { _context.Add(entity); _context.SaveChanges(); }
public bool Commit() { return(_context.SaveChanges() > 0); }