public IActionResult RegisterEmployee(Employee emp) { Employee CheckEmail = _context.Employees .Where(e => e.Email == emp.Email) .SingleOrDefault(); if (CheckEmail != null) { ViewBag.errors = "That email already exists"; return(RedirectToAction("Register")); } if (ModelState.IsValid) { PasswordHasher <Employee> Hasher = new PasswordHasher <Employee>(); Employee newEmp = new Employee { Name = emp.Name, Email = emp.Email, Password = Hasher.HashPassword(emp, emp.Password), Active = true, Age = emp.Age, Title = emp.Title, Department = emp.Department, Salary = emp.Salary }; _context.Add(newEmp); _context.SaveChanges(); ViewBag.success = "Successfully registered"; return(RedirectToAction("Login")); } else { return(View("Register")); } }
public Employee AddNewEmployee(Employee newEmployee) { Guid newUUID = Guid.NewGuid(); newEmployee.EmployeeCode = newUUID.ToString(); DbContext.Employees.Add(newEmployee); DbContext.SaveChanges(); return(newEmployee); }
public ActionResult Create([Bind(Include = "EmployeeID,EmployeeName,Department,Salary")] Employee employee) { if (ModelState.IsValid) { db.Employees.Add(employee); db.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.Message = "Failed!"; } return(View(employee)); }
public ManagerController(EmployeeManagerContext context) { _context = context; if (_context.Managers.Count() == 0) { _context.Managers.Add(new Manager { Name = "Bhanu" }); _context.Managers.Add(new Manager { Name = "Omkar" }); _context.Managers.Add(new Manager { Name = "Gogawale" }); _context.SaveChanges(); } }
public EmployeeController(EmployeeManagerContext context) { _context = context; if (_context.Employees.Count() == 0) { _context.Employees.Add(new Employee { Name = "Vighnesh", ManagersId = 1 }); _context.Employees.Add(new Employee { Name = "Raunak", ManagersId = 2 }); _context.Employees.Add(new Employee { Name = "Ibraham", ManagersId = 2 }); _context.Employees.Add(new Employee { Name = "DJ", ManagersId = 1 }); _context.Employees.Add(new Employee { Name = "Deepak", ManagersId = 3 }); _context.SaveChanges(); } }
public void Save() { context.SaveChanges(); }