public async Task <IActionResult> PutEmployeeTb(int id, EmployeeTb employeeTb) { if (id != employeeTb.EmployeeId) { return(BadRequest()); } _context.Entry(employeeTb).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeTbExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <EmployeeTb> > PostEmployeeTb(EmployeeTb employeeTb) { _context.EmployeeTb.Add(employeeTb); await _context.SaveChangesAsync(); return(CreatedAtAction("GetEmployeeTb", new { id = employeeTb.EmployeeId }, employeeTb)); }
public async Task <IActionResult> Edit(int id, [Bind("EmployeeId,Name,DepartmentId,Salary,Gender")] EmployeeTb employeeTb) { if (id != employeeTb.EmployeeId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(employeeTb); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeTbExists(employeeTb.EmployeeId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(employeeTb)); }
// GET: Employee/Edit/5 public ActionResult Edit(int id) { EmployeeTb Emp = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:64051/api/"); var editdata = client.GetAsync("EmployeeTbs/" + id); editdata.Wait(); var result = editdata.Result; if (result.IsSuccessStatusCode) { var readdata = result.Content.ReadAsAsync <EmployeeTb>(); readdata.Wait(); Emp = readdata.Result; } } IEnumerable <DepartmentTb> Dept = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:64051/api/"); var response = client.GetAsync("DepartmentTbs"); response.Wait(); var result = response.Result; if (result.IsSuccessStatusCode) { var readtask = result.Content.ReadAsAsync <IList <DepartmentTb> >(); readtask.Wait(); Dept = readtask.Result; } } ViewBag.Dept = new SelectList(Dept, "DepartmentId", "Department", Emp.DepartmentId); return(View(Emp)); }
public async Task <IActionResult> Create([Bind("EmployeeId,Name,DepartmentId,Salary,Gender")] EmployeeTb employeeTb) { if (ModelState.IsValid) { _context.Add(employeeTb); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(employeeTb)); }
public async Task <IActionResult> PostEmployee([FromBody] EmployeeTb employee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.EmployeeModel.Add(employee); await _context.SaveChangesAsync(); return(CreatedAtAction("GetEmployee", new { id = employee.EmployeeID }, employee)); }
public ActionResult Edit(EmployeeTb Emp) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:56768/api/EmployeeTbs"); //HTTP POST var putTask = client.PutAsJsonAsync <EmployeeTb>("EmployeeTbs", Emp); putTask.Wait(); var result = putTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } return(View(Emp)); }
public ActionResult Create(IFormCollection collection) { try { EmployeeTb emp = new EmployeeTb(); emp.DepartmentId = Convert.ToInt32(collection["DepartmentId"]); emp.Name = collection["Name"]; emp.Salary = Convert.ToInt64(collection["Salary"]); emp.Gender = collection["gender"]; dc.EmployeeTb.Add(emp); dc.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(EmployeeTb Emp) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:56768/api/EmployeeTbs"); //HTTP POST var postTask = client.PostAsJsonAsync <EmployeeTb>("EmployeeTbs", Emp); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); return(View(Emp)); }
// GET: Employee/Edit/5 public ActionResult Edit(int id) { EmployeeTb Emp = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:56768/api/"); //HTTP GET var responseTask = client.GetAsync("EmployeeTbs?id=" + id.ToString()); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <EmployeeTb>(); readTask.Wait(); Emp = readTask.Result; } } return(View(Emp)); }
public ActionResult Create(EmployeeTb Emp) { try { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:64051/api/"); var posttask = client.PostAsJsonAsync <EmployeeTb>("EmployeeTbs", Emp); posttask.Wait(); var result = posttask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } return(View()); } catch { return(View()); } }