// POST: api/EmployeeType public string Post(HttpRequestMessage value) { try { Employee_Type type = new Employee_Type(); string message = HttpContext.Current.Server.UrlDecode(value.Content.ReadAsStringAsync().Result).Substring(5); JObject json = JObject.Parse(message); JObject empType = (JObject)json["employee_type"]; int key = db.Employee_Type.Count() == 0 ? 1 : (from t in db.Employee_Type orderby t.Employee_Type_ID descending select t.Employee_Type_ID).First() + 1; type.Employee_Type_ID = key; type.Name = (string)empType["name"]; type.Description = (string)empType["description"]; JArray access = (JArray)empType["access"]; //Insert the access levels for this emp type foreach (JObject aa in access) { bool flag = (bool)aa["access"]; int a_ID = (int)aa["ID"]; Model.Access_Employee_Type aet = new Access_Employee_Type(); aet.Access_ID = a_ID; aet.Acess = flag; aet.Employee_Type_ID = key; db.Access_Employee_Type.Add(aet); } string errorString = "false|"; bool error = false; if ((from t in db.Employee_Type where t.Name == type.Name select t).Count() != 0) { error = true; errorString += "The Employee Category already exists on the system."; } if (error) { return(errorString); } db.Employee_Type.Add(type); db.SaveChanges(); return("true|Employee Category #" + key + " successfully added."); } catch (Exception e) { ExceptionLog.LogException(e, "EmployeeTypeController POST"); return("false|An error has occured adding the Employee Category to the system."); } }
public ActionResult MaintainEmployeeType(Employee_Type employee_type, string button) { if (button == "Save") { try { Employee_Type searchemployee_type = db.Employee_Type.Find(employee_type.Emp_Type_ID); if (searchemployee_type == null) { TempData["EditMessage"] = "Error is completed"; return(RedirectToAction("SearchEmployeeType")); } else { db.Entry(searchemployee_type).CurrentValues.SetValues(employee_type); db.SaveChanges(); } } catch (Exception e) { TempData["EditMessage"] = e.Message; return(RedirectToAction("", "")); } } else if (button == "Cancel") { return(RedirectToAction("Index", "Home")); } return(RedirectToAction("Index", "Home")); }
private void btnDelete_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Would you like to delete this Employee Type?", "Delete Employee Type", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { try { Employee_Type Emt2 = new Employee_Type(); Emt2 = db.Employee_Type.Find(tempID); db.Employee_Type.Remove(Emt2); db.SaveChanges(); int Marketing = Emt2.Employee_Type_ID; string Marketing_Template_Value = Convert.ToString(Emt2); MessageBox.Show("Employee Type Successfully Deleted"); this.Close(); } catch (Exception) { //MessageBox.Show("Error: Employee Type was not deleted"); } } }
public async Task <ActionResult <Employee_Type> > PostEmployee_Type(Employee_Type employee_Type) { _context.Employee_Type.Add(employee_Type); await _context.SaveChangesAsync(); return(CreatedAtAction("GetEmployee_Type", new { id = employee_Type.Id_EmployeeType }, employee_Type)); }
public async Task <IActionResult> PutEmployee_Type(int id, Employee_Type employee_Type) { if (id != employee_Type.Id_EmployeeType) { return(BadRequest()); } _context.Entry(employee_Type).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Employee_TypeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public int InsertTableEmployee_Type(Employee_Type objEmployee_Type, string query) { string queryToUpdate = string.Empty; int rowsAffected = 0; try { if (query.Equals("update")) { queryToUpdate = "UPDATE [dbo].[SD_Employee_Type] SET[Employee_Name] ='" + objEmployee_Type.Employee_Name + "' WHERE Employee_Id=" + objEmployee_Type.Employee_Id; } else if (query.Equals("insert")) { queryToUpdate = "INSERT INTO [dbo].[SD_Employee_Type]([Employee_Name],[Status])VALUES('" + objEmployee_Type.Employee_Name + "','A')"; } rowsAffected = _objIGenericProcedures.UpdateDelete(queryToUpdate); } catch (Exception ex) { _log.ErrorMessage("MasterLogicLayer class file in UpdateTableLogin and option is : " + queryToUpdate); _log.ErrorMessage(ex.StackTrace); _log.ErrorMessage(ex.Message); _log.ErrorException(ex); } return(rowsAffected); }
public ActionResult DeleteConfirmed(int id) { Employee_Type employee_type = db.Employee_Type.Find(id); db.Employee_Type.Remove(employee_type); db.SaveChanges(); return(RedirectToAction("Index")); }
// PUT: api/EmployeeType/5 public string Put(int id, HttpRequestMessage value) { try { Employee_Type type = new Employee_Type(); type = (from p in db.Employee_Type where p.Employee_Type_ID == id select p).First(); string message = HttpContext.Current.Server.UrlDecode(value.Content.ReadAsStringAsync().Result).Substring(5); JObject json = JObject.Parse(message); JObject empType = (JObject)json["employee_type"]; type.Name = (string)empType["name"]; type.Description = (string)empType["description"]; db.Access_Employee_Type.RemoveRange(db.Access_Employee_Type.Where(x => x.Employee_Type_ID == id)); JArray access = (JArray)empType["access"]; //Insert the access levels for this emp type foreach (JObject aa in access) { bool flag = (bool)aa["access"]; int a_ID = (int)aa["ID"]; Model.Access_Employee_Type aet = new Access_Employee_Type(); aet.Access_ID = a_ID; aet.Acess = flag; aet.Employee_Type_ID = id; db.Access_Employee_Type.Add(aet); } string errorString = "false|"; bool error = false; if ((from t in db.Employee_Type where t.Name == type.Name && t.Employee_Type_ID != id select t).Count() != 0) { error = true; errorString += "The Employee Category already exists on the system."; } if (error) { return(errorString); } db.SaveChanges(); return("true|Employee Category successfully updated."); } catch (Exception e) { ExceptionLog.LogException(e, "EmployeeTypeController PUT"); return("false|An error has occured updating the Employee Category on the system."); } }
public ActionResult Edit([Bind(Include = "EmployeeType_ID,Employee_Types")] Employee_Type employee_type) { if (ModelState.IsValid) { db.Entry(employee_type).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employee_type)); }
public ActionResult Create([Bind(Include = "EmployeeType_ID,Employee_Types")] Employee_Type employee_type) { if (ModelState.IsValid) { db.Employee_Type.Add(employee_type); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employee_type)); }
private void btnAdd_Click(object sender, EventArgs e) { correct = true; Employee_Type EmT = new Employee_Type(); try { foreach (var item in db.Employee_Type) { if (item.Employees_Type_Description == rtxtDescription.Text) { MessageBox.Show("Employee Type already exists"); correct = false; } } //if (ValidateIfEmployeeTypeExists(rtxtDescription.Text) == true) //{ // MessageBox.Show("Employee Type already exists"); // correct = false; //} if (rtxtDescription.Text == "") { lblDescription.Visible = true; //MessageBox.Show("Please Enter Employee type details"); correct = false; } else if (rtxtDescription.Text == "") { lblDescription.Visible = true; // MessageBox.Show("Please Enter Employee type details"); correct = false; } else { correct = true; EmT.Employees_Type_Description = rtxtDescription.Text; //EmT.Employees_Type1 = txtEmployeeType.Text; db.Employee_Type.Add(EmT); db.SaveChanges(); MessageBox.Show("Employee Type Added Successfully"); this.Close(); } } catch { } }
public int insert(Employee_Type type) { var result = 0; con = new SqlConnection(constr); string sql = string.Format("Insert into Employee_Type(Employee_Types)values('{0}')", type.Employee_Types); cmd = new SqlCommand(sql, con); con.Open(); result = cmd.ExecuteNonQuery(); con.Close(); return(result); }
// GET: /Employee_Type/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Employee_Type employee_type = db.Employee_Type.Find(id); if (employee_type == null) { return(HttpNotFound()); } return(View(employee_type)); }
public Employee_Type findEmployeeType(int employeeTypeId) { Employee_Type employeeType = null; try { using (var db = new PayrollModel()) { employeeType = db.Employee_Type.Find(employeeTypeId); } } catch (Exception ex) { Console.WriteLine("find employee" + ex.InnerException); } return(employeeType); }
public ActionResult MaintainEmployeeType(int?id) { if (id == null) { TempData["EditMessage"] = "Error is completed"; return(RedirectToAction("SearchEmployee")); } Employee_Type employeetype = db.Employee_Type.Find(id); if (employeetype == null) { TempData["EditMessage"] = "Employee Succesfully Updated"; return(RedirectToAction("Index", "Home")); } TempData["SuccessMessage"] = "Employee Succesfully Updated"; return(View(employeetype)); }
protected void Button1_Click(object sender, EventArgs e) { Employee_Type d = new Employee_Type(); d.Employee_Types = TextBox1.Text; GridView1.DataSourceID = SqlDataSource2.ID; if (new EmployeeType_Access().insert(d) > 0) { ScriptManager.RegisterStartupScript(this, this.GetType(), "ClientScript", "alert('Suceesfully saved')", true); } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "ClientScript", "alert('Suceesfully saved')", true); } }
public ActionResult AddEmployeeType(Employee_Type employee_type, string button) { ViewBag.errorMessage = ""; if (button == "Save") { try { List <Employee_Type> Employeetype = new List <Employee_Type>(); Employeetype = db.Employee_Type.ToList(); if (Employeetype.Count != 0) { int count = 0; foreach (var item in Employeetype) { if (item.Emp_Type_Name == employee_type.Emp_Type_Name) { count++; TempData["EditMessage"] = "There is a duplicate Donation Type Already"; return(View()); } } if (count == 0) { db.Employee_Type.Add(employee_type); db.SaveChanges(); } } else { db.Employee_Type.Add(employee_type); } } catch (Exception e) { TempData["EditMessage"] = "There was an Error with network please try again: " + e.Message; return(View()); } } else if (button == "Cancel") { return(RedirectToAction("Index", "Home")); } TempData["SuccessMessage"] = "Employee Succesfully Updated"; return(RedirectToAction("Index", "Home")); }
public Boolean addEmployeeType(Employee_Type employeeType) { Boolean status = false; try { using (var db = new PayrollModel()) { db.Employee_Type.Add(employeeType); db.SaveChanges(); status = true; } } catch (Exception ex) { Console.WriteLine(ex.InnerException); } return(status); }
public Boolean updateEmployeeType(Employee_Type employeeType) { Boolean status = false; try { using (var db = new PayrollModel()) { Console.WriteLine("Employee detail updated"); db.Employee_Type.AddOrUpdate(employeeType); db.SaveChanges(); status = true; } } catch (Exception ex) { Console.WriteLine("Update employeeType problem " + ex.InnerException); } return(status); }
public Boolean deleteMemberType(int id) { Boolean status = false; try { using (var db = new PayrollModel()) { Employee_Type employee = db.Employee_Type.First(b => b.Employee_Type_ID == id); db.Employee_Type.Remove(employee); db.SaveChanges(); status = true; } } catch (Exception ex) { Console.WriteLine("delete employeeID " + ex.InnerException); } return(status); }
public ActionResult updateEmployeeData(Employee_Type objEmployee_Type) { int rowsAffected = 0; string message = "Record Not Affected"; try { if (objEmployee_Type != null) { rowsAffected = _objIMasterLogicLayer.InsertTableEmployee_Type(objEmployee_Type, "insert"); } if (rowsAffected > 0) { message = "Record Affected"; } } catch (Exception e) { _log.ErrorMessage("MasterController controller in insertEmployeeData Method"); _log.ErrorException(e); } return(Content(message)); }
public List <Employee_Type> Display() { List <Employee_Type> lst = new List <Employee_Type>(); con = new SqlConnection(constr); string sql = string.Format("select * from Employee_Type order by Employee_Types asc"); cmd = new SqlCommand(sql, con); con.Open(); reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { Employee_Type d = new Employee_Type(); d.Employee_Types = reader["Employee_Types"].ToString(); d.EmployeeType_ID = int.Parse(reader["EmployeeType_ID"].ToString()); lst.Add(d); } } con.Close(); return(lst); }