public ActionResult FindEmployee(FormCollection formCollection) { // The input conversion is valid. if (ModelState.IsValid) { Models.Employees result = new Models.Employees(); if (!string.IsNullOrEmpty(formCollection["employeeName"]) && !string.IsNullOrEmpty(formCollection["employeeEmail"])) { // The employeeName and employeeEmail query fields were not empty so list find the items. result = businessLogicLayer.FindEmployeeByNameAndEmail(formCollection["employeeName"], formCollection["employeeEmail"]); } else if (!string.IsNullOrEmpty(formCollection["employeeName"]) && string.IsNullOrEmpty(formCollection["employeeEmail"])) { // The employeeEmail was empty, but the employeeName was not, so find the items based on the employeeName query field. result = businessLogicLayer.FindEmployeeByName(formCollection["employeeName"]); } else if (string.IsNullOrEmpty(formCollection["employeeName"]) && !string.IsNullOrEmpty(formCollection["employeeEmail"])) { // The employeeName was empty, but the employeeEmail was not, so find the items based on the employeeEmail query field. result = businessLogicLayer.FindEmployeeByEmail(formCollection["employeeEmail"]); } else { // The employeeName and employeeEmail query fields were empty so list all items. result = businessLogicLayer.ListEmployees(); } // Store the result in the ViewBag. ViewBag.Employees = result; } return(View()); }
/// <summary> /// Lists the Employees. /// </summary> /// <returns>The list of Employees or null.</returns> public Models.Employees ListEmployees() { try { // Open a connection to the database. SqlConnection sqlConnection = new SqlConnection(url); sqlConnection.Open(); // List the items from the Employees table with the stored procedure. Models.Employees employees = new Models.Employees(); SqlCommand sqlCommand = new SqlCommand("spListEmployees", sqlConnection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); // Store the items in an Employee list. while (sqlDataReader.Read()) { employees.Items.Add(new Models.Employee(sqlDataReader.GetInt32(0), sqlDataReader.GetString(1), sqlDataReader.GetString(2), sqlDataReader.GetBoolean(3))); } // Close the dataReader and the connection. sqlDataReader.Close(); sqlConnection.Close(); return(employees); } catch { return(null); } }
/// <summary> /// Finds an Employee by name and email. /// </summary> /// <param name="name">The Employee name to find.</param> /// <param name="email">The Employee email to find.</param> /// <returns>The Employee list or null.</returns> public Models.Employees FindEmployeeByNameAndEmail(string name, string email) { try { // Open a connection to the database. SqlConnection sqlConnection = new SqlConnection(url); sqlConnection.Open(); // Find the items in the Employees table with the stored procedure. Models.Employees employees = new Models.Employees(); SqlCommand sqlCommand = new SqlCommand("spFindEmployeeByNameAndEmail", sqlConnection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@name", name); sqlCommand.Parameters.AddWithValue("@email", email); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); // Store the items in an Employee list. while (sqlDataReader.Read()) { employees.Items.Add(new Models.Employee(sqlDataReader.GetInt32(0), sqlDataReader.GetString(1), sqlDataReader.GetString(2), sqlDataReader.GetBoolean(3))); } // Close the dataReader and the connection. sqlDataReader.Close(); sqlConnection.Close(); return(employees); } catch { return(null); } }
public async Task <ActionResult <Employees> > SaveEmployees([FromBody] Employees _VendorType) { string valorrespuesta = ""; try { Employees _listVendorType = new Employees(); string baseadress = config.Value.urlbase; HttpClient _client = new HttpClient(); _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token")); var result = await _client.GetAsync(baseadress + "api/Employees/GetEmployeesByIdentidad/" + _VendorType.Identidad); if (result.IsSuccessStatusCode) { valorrespuesta = await(result.Content.ReadAsStringAsync()); _listVendorType = JsonConvert.DeserializeObject <Employees>(valorrespuesta); if (_listVendorType != null && _VendorType.IdEmpleado == 0) { if (_listVendorType.Identidad == _VendorType.Identidad) { return(await Task.Run(() => BadRequest($"Ya existe un Empleado registrado con esa Identidad."))); } } } result = await _client.GetAsync(baseadress + "api/Employees/GetEmployeesById/" + _VendorType.IdEmpleado); _VendorType.FechaModificacion = DateTime.Now; _VendorType.Usuariomodificacion = HttpContext.Session.GetString("user"); if (result.IsSuccessStatusCode) { valorrespuesta = await(result.Content.ReadAsStringAsync()); _listVendorType = JsonConvert.DeserializeObject <Employees>(valorrespuesta); } if (_listVendorType == null) { _listVendorType = new Models.Employees(); } if (_listVendorType.IdEmpleado == 0) { _VendorType.FechaCreacion = DateTime.Now; _VendorType.Usuariocreacion = HttpContext.Session.GetString("user"); var insertresult = await Insert(_VendorType); } else { var updateresult = await Update(_VendorType.IdEmpleado, _VendorType); } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; } return(Json(_VendorType)); }
/// <summary> /// Finds an Relation by Employee. /// </summary> /// <param name="input">The Relation Employee to find.</param> /// <returns>The Relation list or null.</returns> public Models.Relations FindRelationByEmployee(string input) { try { // Open a connection to the database. SqlConnection sqlConnection = new SqlConnection(url); sqlConnection.Open(); // Find the items in the Employees table with the stored procedure. Models.Employees employees = new Models.Employees(); SqlCommand sqlCommand1 = new SqlCommand("spFindEmployeeByName", sqlConnection); sqlCommand1.CommandType = System.Data.CommandType.StoredProcedure; sqlCommand1.Parameters.AddWithValue("@name", input); SqlDataReader sqlDataReader1 = sqlCommand1.ExecuteReader(); // Store the items in an Employee list. while (sqlDataReader1.Read()) { employees.Items.Add(new Models.Employee(sqlDataReader1.GetInt32(0), sqlDataReader1.GetString(1), sqlDataReader1.GetString(2), sqlDataReader1.GetBoolean(3))); } // Close the dataReader. sqlDataReader1.Close(); // There is at least one item that was found. int input2 = 0; if (employees.Items.Count > 0) { // Because the previous search was on an Id, there should only be one item found. input2 = employees.Items[0].EmployeeId; } // Find the items in the Relations table with the stored procedure. Models.Relations relations = new Models.Relations(); SqlCommand sqlCommand = new SqlCommand("spFindRelationByEmployee", sqlConnection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@employee", input2); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); // Store the items in an Relation list. while (sqlDataReader.Read()) { relations.Items.Add(new Models.Relation(sqlDataReader.GetInt32(0), sqlDataReader.GetInt32(1), sqlDataReader.GetInt32(2))); } // Close the dataReader and the connection. sqlDataReader.Close(); sqlConnection.Close(); return(relations); } catch { return(null); } }
private void DeleteUser(Models.Employees employee) { if (employee != null) { Console.Write(String.Format("Are you sure you want to delete the user {0} {1}? (y/n)", employee.EmployeeFirstName, employee.EmployeeLastName)); if (Console.ReadLine().ToUpper() == "Y") { employee.Delete(); } } }
private void lst_ItemSelected(object sender, SelectedItemChangedEventArgs e) { if (e.SelectedItem == null) { return; } Models.Employees emp = e.SelectedItem as Models.Employees; Navigation.PushAsync(new View.Employee.Details(emp)); lst.SelectedItem = null; }
private void btnEdit_Clicked(object sender, EventArgs e) { Models.Employees emp = new Models.Employees { Id = int.Parse(lblId.Text), Name = lblName.Text, Phone = lblPhone.Text, Email = lblEmail.Text, Address = lblAddress.Text }; Navigation.PushAsync(new View.Employee.Edit(emp)); }
public ActionResult Index(Models.Employees emp) { if (string.IsNullOrEmpty(emp.Employee)) { ModelState.AddModelError("Employee", new Exception()); } if (ModelState.IsValid) { return(RedirectToAction("Message")); } return(View()); }
private void btnAdd_Clicked(object sender, EventArgs e) { Models.Employees emp = new Models.Employees { Name = txtName.Text, Phone = txtPhone.Text, Email = txtEmail.Text, Address = txtAddress.Text }; context.Add(emp); DisplayAlert("added", "added employee successful", "ok"); Navigation.PopAsync(); }
private void btnSave_Clicked(object sender, EventArgs e) { Models.Employees emp = new Models.Employees { Id = int.Parse(lblId.Text), Name = txtName.Text, Phone = txtPhone.Text, Email = txtEmail.Text, Address = txtAddress.Text }; context.Update(emp); DisplayAlert("updated", "employee updated successful", "ok"); Navigation.PopAsync(); }
/// <summary> /// Lists the database tables. /// </summary> /// <returns>The Index view.</returns> public ActionResult Index() { // List the items from the tables. Models.Workplaces workplaces = businessLogicLayer.ListWorkplaces(); Models.Employees employees = businessLogicLayer.ListEmployees(); Models.Relations relations = businessLogicLayer.ListRelations(); // Store the items in the ViewBag so the Index view can use them. ViewBag.Workplaces = workplaces; ViewBag.Employees = employees; ViewBag.Relations = relations; return(View()); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } Employees = await _context.Employees.FirstOrDefaultAsync(m => m.EmployeesID == id); if (Employees == null) { return(NotFound()); } return(Page()); }
private void btnDelete_Clicked(object sender, EventArgs e) { Models.Employees emp = new Models.Employees { Id = int.Parse(lblId.Text), Name = lblName.Text, Phone = lblPhone.Text, Email = lblEmail.Text, Address = lblAddress.Text }; context.Delete(emp); DisplayAlert("deleted", "employee deleted successful", "ok"); Navigation.PopAsync(); }
/// <summary> /// Adds a Relation. /// </summary> /// <returns>The AddRelation view.</returns> // Load the view. public ActionResult AddRelation() { // List the Relations and store them in the ViewBag. Models.Relations relations = businessLogicLayer.ListRelations(); ViewBag.Relations = relations; // List the Workplaces and store them in the ViewBag. Models.Workplaces workplaces = businessLogicLayer.ListWorkplaces(); ViewBag.Workplaces = workplaces; // List the Employees and store them in the ViewBag. Models.Employees employees = businessLogicLayer.ListEmployees(); ViewBag.Employees = employees; return(View()); }
/// <summary> /// Edits a Relation. /// </summary> /// <param name="id">The relationId that was selected.</param> /// <returns>The EditRelation view.</returns> // Load the view. public ActionResult EditRelation(int id) { // Find the selected Relation and store it in the ViewBag. Models.Relation relation = businessLogicLayer.ListRelations().Items.Find(x => x.RelationId == id); ViewBag.Relation = relation; // List the Workplaces and store them in the ViewBag. Models.Workplaces workplaces = businessLogicLayer.ListWorkplaces(); ViewBag.Workplaces = workplaces; // Lists the Employees and store them in the ViewBag. Models.Employees employees = businessLogicLayer.ListEmployees(); ViewBag.Employees = employees; return(View()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Employees = await _context.Employees.FindAsync(id); if (Employees != null) { _context.Employees.Remove(Employees); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public ActionResult Create(Models.Employees employee) { if (!ModelState.IsValid) { return(View(employee)); } db.Employees.Add(employee); try { db.SaveChanges(); } catch (Exception e) { return(View(employee)); } return(RedirectToAction("Index")); }
public ActionResult Edit(Models.Employees employee) { if (!ModelState.IsValid) { return(View(employee)); } var originalEmployee = (from e in db.Employees where e.Id == employee.Id select e).First(); db.Entry(originalEmployee).CurrentValues.SetValues(employee); try { db.SaveChanges(); } catch (Exception e) { return(View(employee)); } return(RedirectToAction("Index")); }
// GET: EditEmployee public ActionResult EditEmployee(Models.Employees e) { SqlConnection cn = new SqlConnection("Data Source=(localdb)\\MSSQLLocalDB; Initial Catalog=MVCKuaforContext-20180723110834; Integrated Security=True; MultipleActiveResultSets=True; AttachDbFilename=|DataDirectory|MVCKuaforContext-20180723110834.mdf"); string _sql = "SELECT * FROM Employees WHERE employee_id = " + ((TempData["to-edit-id"] != null) ? TempData["to-edit-id"] : -1); Debug.WriteLine(_sql); cn.Open(); SqlCommand cmd = new SqlCommand(_sql, cn); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { e.employee_id = sdr.GetInt32(0); e.name = sdr.GetString(1); e.surname = sdr.GetString(2); e.username = sdr.GetString(3); e.password = sdr.GetString(4); e.email = sdr.GetString(5); e.telephonenumber = sdr.GetInt64(6); } cn.Close(); return(View(e)); }
/// <summary> /// Lists the Employees. /// </summary> /// <returns>The list of Employees or null.</returns> public Models.Employees ListEmployees() { try { // Open a connection to the database. SqlConnection sqlConnection = new SqlConnection(url); sqlConnection.Open(); // List the items from the Employees table with the stored procedure. Models.Employees employees = new Models.Employees(); SqlCommand sqlCommand = new SqlCommand("spListEmployees", sqlConnection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); // Store the items in an Employee list. while (sqlDataReader.Read()) { employees.Items.Add(new Models.Employee(sqlDataReader.GetInt32(0), sqlDataReader.GetString(1), sqlDataReader.GetString(2), sqlDataReader.GetBoolean(3))); } // Close the dataReader and the connection. sqlDataReader.Close(); sqlConnection.Close(); return employees; } catch { return null; } }
/// <summary> /// Finds an Relation by Employee and Workplace. /// </summary> /// <param name="employee">The Relation Employee to find.</param> /// <param name="workplace">The Relation Workplace to find.</param> /// <returns>The Relation list or null.</returns> public Models.Relations FindRelationByEmployeeAndWorkplace(string employee, string workplace) { try { // Open a connection to the database. SqlConnection sqlConnection = new SqlConnection(url); sqlConnection.Open(); // Find the items in the Employees table with the stored procedure. Models.Employees employees = new Models.Employees(); SqlCommand sqlCommand1 = new SqlCommand("spFindEmployeeByName", sqlConnection); sqlCommand1.CommandType = System.Data.CommandType.StoredProcedure; sqlCommand1.Parameters.AddWithValue("@name", employee); SqlDataReader sqlDataReader1 = sqlCommand1.ExecuteReader(); // Store the items in an Employee list. while (sqlDataReader1.Read()) { employees.Items.Add(new Models.Employee(sqlDataReader1.GetInt32(0), sqlDataReader1.GetString(1), sqlDataReader1.GetString(2), sqlDataReader1.GetBoolean(3))); } // Close the dataReader. sqlDataReader1.Close(); // Find the items in the Workplaces table with the stored procedure. Models.Workplaces workplaces = new Models.Workplaces(); SqlCommand sqlCommand2 = new SqlCommand("spFindWorkplaceByName", sqlConnection); sqlCommand2.CommandType = System.Data.CommandType.StoredProcedure; sqlCommand2.Parameters.AddWithValue("@name", workplace); SqlDataReader sqlDataReader2 = sqlCommand2.ExecuteReader(); // Store the items in an Workplace list. while (sqlDataReader2.Read()) { workplaces.Items.Add(new Models.Workplace(sqlDataReader2.GetInt32(0), sqlDataReader2.GetString(1), sqlDataReader2.GetBoolean(2))); } // Close the dataReader. sqlDataReader2.Close(); // There is at least one item that was found. int input2 = 0; int input3 = 0; if (employees.Items.Count > 0) { // Because the previous search was on an Id, there should only be one item found. input2 = employees.Items[0].EmployeeId; } if (workplaces.Items.Count > 0) { // Because the previous search was on an Id, there should only be one item found. input3 = workplaces.Items[0].WorkplaceId; } // Find the items in the Relations table with the stored procedure. Models.Relations relations = new Models.Relations(); SqlCommand sqlCommand = new SqlCommand("spFindRelationByEmployeeAndWorkplace", sqlConnection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@employee", input2); sqlCommand.Parameters.AddWithValue("@workplace", input3); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); // Store the items in an Relation list. while (sqlDataReader.Read()) { relations.Items.Add(new Models.Relation(sqlDataReader.GetInt32(0), sqlDataReader.GetInt32(1), sqlDataReader.GetInt32(2))); } // Close the dataReader and the connection. sqlDataReader.Close(); sqlConnection.Close(); return relations; } catch { return null; } }
/// <summary> /// Finds an Employee by name and email. /// </summary> /// <param name="name">The Employee name to find.</param> /// <param name="email">The Employee email to find.</param> /// <returns>The Employee list or null.</returns> public Models.Employees FindEmployeeByNameAndEmail(string name, string email) { try { // Open a connection to the database. SqlConnection sqlConnection = new SqlConnection(url); sqlConnection.Open(); // Find the items in the Employees table with the stored procedure. Models.Employees employees = new Models.Employees(); SqlCommand sqlCommand = new SqlCommand("spFindEmployeeByNameAndEmail", sqlConnection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@name", name); sqlCommand.Parameters.AddWithValue("@email", email); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); // Store the items in an Employee list. while (sqlDataReader.Read()) { employees.Items.Add(new Models.Employee(sqlDataReader.GetInt32(0), sqlDataReader.GetString(1), sqlDataReader.GetString(2), sqlDataReader.GetBoolean(3))); } // Close the dataReader and the connection. sqlDataReader.Close(); sqlConnection.Close(); return employees; } catch { return null; } }
public ActionResult FindEmployee(FormCollection formCollection) { // The input conversion is valid. if (ModelState.IsValid) { Models.Employees result = new Models.Employees(); if (!string.IsNullOrEmpty(formCollection["employeeName"]) && !string.IsNullOrEmpty(formCollection["employeeEmail"])) { // The employeeName and employeeEmail query fields were not empty so list find the items. result = businessLogicLayer.FindEmployeeByNameAndEmail(formCollection["employeeName"], formCollection["employeeEmail"]); } else if (!string.IsNullOrEmpty(formCollection["employeeName"]) && string.IsNullOrEmpty(formCollection["employeeEmail"])) { // The employeeEmail was empty, but the employeeName was not, so find the items based on the employeeName query field. result = businessLogicLayer.FindEmployeeByName(formCollection["employeeName"]); } else if (string.IsNullOrEmpty(formCollection["employeeName"]) && !string.IsNullOrEmpty(formCollection["employeeEmail"])) { // The employeeName was empty, but the employeeEmail was not, so find the items based on the employeeEmail query field. result = businessLogicLayer.FindEmployeeByEmail(formCollection["employeeEmail"]); } else { // The employeeName and employeeEmail query fields were empty so list all items. result = businessLogicLayer.ListEmployees(); } // Store the result in the ViewBag. ViewBag.Employees = result; } return View(); }
public Details(Models.Employees emp) { InitializeComponent(); this.BindingContext = emp; }