public bool Update(ApiEmployee item) { using (var context = new EmployeesEntities()) { var employer = context.Employees.Where(p => p.id == item.id).FirstOrDefault(); employer.fullName = item.fullName; employer.aditional_info = item.aditional_info; employer.aditional_service = item.aditional_service; employer.another_building = item.another_building; employer.another_company = item.another_company; employer.fk_buildingaccess = item.fk_buildingaccess; employer.cellphone = item.cellphone; employer.email = item.email; employer.fk_companylist = item.fk_companylist; employer.fk_hiredfor = item.fk_hiredfor; employer.hiringManagerEmail = item.hiringManagerEmail; employer.initiationDate = item.initiationDate; employer.restricted_access = item.restricted_access; employer.service_equipmentneeded = item.service_equipmentneeded; employer.startDate = item.startDate; context.SaveChanges(); return(true); } return(false); }
public static bool Login(string username, string password) { using (EmployeesEntities db = new EmployeesEntities()) { return(db.Users.Any(user => user.UserName.Equals(username, StringComparison.OrdinalIgnoreCase) && user.Password == password)); } }
private void DeleteEmployeeExecute() { try { using (EmployeesEntities context = new EmployeesEntities()) { // geting the registration number of the user string jmbg = ViewEmployee.JMBG; // confirmation for the action MessageBoxResult messageBoxResult = MessageBox.Show("Deleting the employee will delete all his records. \nAre you sure you want to delete?", "Delete Confirmation", MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.Yes) { // getting the user from the database tblEmployee employeeToDelete = (from x in context.tblEmployees where x.JMBG == jmbg select x).First(); // removin the user from the database context.tblEmployees.Remove(employeeToDelete); context.SaveChanges(); // logging the action FileActions.Instance.DeletingEmployee(FileActions.path, FileActions.actions, DateTime.Now, employeeToDelete.FullName); EmployeeList = GetAllEmployees().ToList(); } } } catch (Exception) { MessageBox.Show("The employee can not be deleted, please try again."); } }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { var identity = new ClaimsIdentity(context.Options.AuthenticationType); EmployeesEntities obj = new EmployeesEntities(); var userdata = obj.EF_UserLogin(context.UserName, context.Password).FirstOrDefault(); if (context.UserName == "admin" && context.Password == "admin") { identity.AddClaim(new Claim(ClaimTypes.Role, "admin")); identity.AddClaim(new Claim("username", "admin")); identity.AddClaim(new Claim(ClaimTypes.Name, "Akshay Jadhav")); context.Validated(identity); } else if (userdata != null) { identity.AddClaim(new Claim(ClaimTypes.Role, userdata.Role)); identity.AddClaim(new Claim(ClaimTypes.Name, userdata.UserName)); context.Validated(identity); } else { context.SetError("invalid_grant", "Provided UserName and Password is incorrect"); context.Rejected(); return; } }
public IEnumerable <Employee> get() { using (EmployeesEntities db = new EmployeesEntities()) { return(db.Employees.ToList()); } }
public ActionResult Edit(int id = 0) { using (EmployeesEntities db = new EmployeesEntities()) { return(View(db.Employees.Where(x => x.EmployeeID == id).FirstOrDefault <Employee>())); } }
IEnumerable <EmployeeTbl> GetAllEmployee() { using (EmployeesEntities db = new EmployeesEntities()) { return(db.EmployeeTbls.ToList <EmployeeTbl>()); } }
/*########################################################## * put *##########################################################*/ public HttpResponseMessage Put(int id, [FromBody] Employee employee) { try { using (EmployeesEntities entities = new EmployeesEntities()) { //1.get the employee from database var entity = entities.Employees.FirstOrDefault(e => e.EmpID == id); //2.if the employee is not found (wrong id) => 404 if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee with Id " + id.ToString() + " not found to update")); } //3.if the employee already exist in the database => (200 ok) else { entity.EmpID = employee.EmpID; entity.Name = employee.Name; entity.Salary = employee.Salary; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, entity)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
/*##################################################### * delete *####################################################*/ public HttpResponseMessage Delete(int id) { try { using (EmployeesEntities entities = new EmployeesEntities()) { //1.get the employee which user want to delete var entity = entities.Employees.FirstOrDefault(e => e.EmpID == id); //2.if the employee is not found (wrong id) => 404 if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee with Id = " + id.ToString() + " not found to delete")); } //3.if the employee already exist in the database => (200 ok) else { entities.Employees.Remove(entity); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public ApiEmployee Add(ApiEmployee item) { ApiEmployee returnValue = null; using (var _context = new EmployeesEntities()) { try { item.id = -1; Employee user = _context.Employees.Add(item.AsEmployee()); _context.SaveChanges(); returnValue = user.AsApiEmployee(); } catch (DbEntityValidationException ex) { throw ex.DBValidationEntityExceptionAsFriendlyException(); } catch (Exception ex) { throw ex.EntityExceptionAsFriendlyException(); } } return(returnValue); }
public JsonResult Get() { using (var db = new EmployeesEntities()) { var employees = db.Employees.ToList(); return(Json(employees, JsonRequestBehavior.AllowGet)); } }
public void AddEmployee(Shared.Entities.Employee emp) { using (var db = new EmployeesEntities()) { db.Employees.Add(emp); db.SaveChanges(); } }
public void DeleteEmployee(int id) { using (var db = new EmployeesEntities()) { db.Employees.Remove(db.Employees.Find(id)); db.SaveChanges(); } }
public ActionResult GetData() { using (EmployeesEntities db = new EmployeesEntities()) { List <Employee> empList = db.Employees.ToList <Employee>(); return(Json(new { data = empList }, JsonRequestBehavior.AllowGet)); } }
public Shared.Entities.Employee GetEmployee(int id) { using (var db = new EmployeesEntities()) { //return (from Employee in db.Employees where Employee.Id == id select new Employee); return(db.Employees.Find(id)); } }
private void Form1_Load(object sender, EventArgs e) { this.proxy = new EmployeesEntities (new Uri("http://localhost:2671/EmployeeService.svc/")); this.iniNavigator(); this.createColumns(); this.fillDataGrid(); }
public ActionResult AddOrEdit(Employee emp) { using (EmployeesEntities db = new EmployeesEntities()) { db.Employees.Add(emp); db.SaveChanges(); return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Edit(Employee emp) { using (EmployeesEntities db = new EmployeesEntities()) { db.Entry(emp).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// Constructs a new instance of /// <see cref="T:EmployeeManager.BusinessLayer.EmployeesRepository" /> and /// returns a reference to it. /// </summary> /// <param name="context"> /// A /// <see cref="T:EmployeeManager.Data.EmployeesEntities" /> /// that provides access to the underlying data source. /// </param> protected EmployeesRepository(EmployeesEntities context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } _dataset = context.Set <TEntity>(); }
public List <Shared.Entities.Employee> GetAllEmployees() { using (var db = new EmployeesEntities()) { //List<Shared.Entities.Employee> lEmp = new List<Shared.Entities.Employee>(); //return db.Employees.ToList(); return((from Employee in db.Employees select Employee).ToList()); } }
public void UpdateEmployee(Shared.Entities.Employee emp) { using (var db = new EmployeesEntities()) { db.Employees.Attach(emp); var entry = db.Entry(emp); entry.State = EntityState.Modified; db.SaveChanges(); } }
public ActionResult Delete(int id) { using (EmployeesEntities db = new EmployeesEntities()) { Employee emp = db.Employees.Where(x => x.EmployeeID == id).FirstOrDefault <Employee>(); db.Employees.Remove(emp); db.SaveChanges(); return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet)); } }
public void Remove(int id) { using (var context = new EmployeesEntities()) { var employer = context.Employees.Where(p => p.id == id).FirstOrDefault(); context.Employees.Attach(employer); context.Employees.Remove(employer); context.SaveChanges(); } }
/// <summary> /// Checks whether a database associated with the given DbContext is even /// available /// (i.e., online vs. offline). /// </summary> /// <returns>True if the database is online and accessible; false otherwise.</returns> public static bool IsDatabaseOnline() { var result = false; using (var db = new EmployeesEntities()) { result = TestConnectionToDatabase(db); } return(result); }
public IEnumerable <ApiBeingHiredFor> GetAll() { List <ApiBeingHiredFor> List = new List <ApiBeingHiredFor>(); using (var context = new EmployeesEntities()) { foreach (BeingHiredFor bhfr in context.BeingHiredFors.ToList()) { List.Add(bhfr.AsApiBeingHiredFor()); } } return(List); }
public IEnumerable <ApiEmployee> GetAll() { List <ApiEmployee> List = new List <ApiEmployee>(); using (var context = new EmployeesEntities()) { foreach (Employee employee in context.Employees.ToList()) { List.Add(employee.AsApiEmployee()); } } return(List); }
public ActionResult AddOrEdit(int id = 0) { EmployeeTbl emp = new EmployeeTbl(); if (id != 0) { using (EmployeesEntities db = new EmployeesEntities()) { emp = db.EmployeeTbls.Where(x => x.EmployeeId == id).FirstOrDefault <EmployeeTbl>(); } } return(View(emp)); }
/// <summary> /// Safely disposes of this object, releasing all associated resources. /// </summary> /// <param name="disposing"> /// True if this object is disposed deterministically; /// Set to false if this method is being called by a finalizer. /// </param> protected virtual void Dispose(bool disposing) { if (!disposing) { return; } if (Context == null) { return; } Context.Dispose(); Context = null; }
public IEnumerable <ApiBuilding> GetAll() { List <ApiBuilding> List = new List <ApiBuilding>(); using (var context = new EmployeesEntities()) { foreach (Building building in context.Buildings.ToList()) { List.Add(building.AsApiBuilding()); } } return(List); }
public IEnumerable <ApiCompany> GetAll() { List <ApiCompany> List = new List <ApiCompany>(); using (var context = new EmployeesEntities()) { foreach (Company company in context.Companies.ToList()) { List.Add(company.AsApiCompany()); } } return(List); }
public BaseController() { _db = new EmployeesEntities(); _attributes = null; }