public ActionResult Create([Bind(Include = "EmployeeId,First_Name,Last_Name,Position,Age,Salary")] MvcEmployeeModel mvcEmployeeModel) { // if (ModelState.IsValid) // { // mvcEmployeeModel.EmployeeId = Guid.NewGuid(); // db.EmployeeModels.Add(mvcEmployeeModel); // db.SaveChanges(); // return RedirectToAction("Index"); // } // return View(mvcEmployeeModel); //} mvcEmployeeModel.EmployeeId = Guid.NewGuid(); var errors = ModelState .Where(x => x.Value.Errors.Count > 0) .Select(x => new { x.Key, x.Value.Errors }) .ToArray(); if (ModelState.IsValid) { db.EmployeeModels.Add(mvcEmployeeModel); db.SaveChanges(); } return(View(mvcEmployeeModel)); }
public ActionResult DeleteConfirmed(Guid id) { MvcEmployeeModel mvcEmployeeModel = db.EmployeeModels.Find(id); db.EmployeeModels.Remove(mvcEmployeeModel); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "EmployeeId,First_Name,Last_Name,Position,Age,Salary")] MvcEmployeeModel mvcEmployeeModel) { if (ModelState.IsValid) { db.Entry(mvcEmployeeModel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(mvcEmployeeModel)); }
public ActionResult AddOrEdit(MvcEmployeeModel emp) { if (emp.EmployeeID == 0) { HttpResponseMessage response = GlobalVariables.webApiClient.PostAsJsonAsync("Employee", emp).Result; TempData["SuccessMessage"] = "Saved Successfully"; } else { HttpResponseMessage response = GlobalVariables.webApiClient.PutAsJsonAsync("Employee/" + emp.EmployeeID, emp).Result; TempData["SuccessMessage"] = "Updated Successfully"; } return(RedirectToAction("Index")); }
// GET: MvcEmployeeModels/Edit/5 public ActionResult Edit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MvcEmployeeModel mvcEmployeeModel = db.EmployeeModels.Find(id); if (mvcEmployeeModel == null) { return(HttpNotFound()); } return(View(mvcEmployeeModel)); }
public ActionResult AddOrEdit(int id = 0) { if (id == 0) { return(View(new MvcEmployeeModel())); } else { MvcEmployeeModel emp = new MvcEmployeeModel(); HttpResponseMessage response = GlobalsVariables.webApiClient.GetAsync("Employees/" + id.ToString()).Result; emp = response.Content.ReadAsAsync <MvcEmployeeModel>().Result; return(View(emp)); } }
public ActionResult AddOrEdit(MvcEmployeeModel prn) { // Insert Functionality if (prn.Id == 0) { HttpResponseMessage Response = GlobalVariables.WebApiClient.PostAsJsonAsync("Employee", prn).Result; TempData["SuccessMessage"] = "Saved Successfully"; } // Update Functionality else { HttpResponseMessage Response = GlobalVariables.WebApiClient.PutAsJsonAsync("Employee/" + prn.Id, prn).Result; TempData["SuccessMessage"] = "Updated Successfully"; } return(RedirectToAction("Contactlist")); }
public ActionResult AddOrEdit(MvcEmployeeModel emp) { if (emp.EmployeeId == 0) { HttpResponseMessage response = GlobalsVariables.webApiClient.PostAsJsonAsync("Employees", emp).Result; TempData["SuccessMessage"] = "Saved Successfully"; return(RedirectToAction("index")); } else { HttpResponseMessage response = GlobalsVariables.webApiClient.PutAsJsonAsync("Employees/" + emp.EmployeeId, emp).Result; TempData["SuccessMessage"] = "Your item has been updated Successfully"; return(RedirectToAction("index")); } }
public ActionResult AddOrEdit(MvcEmployeeModel emp) { HttpResponseMessage response = GlobalVariables.WebApiClient.PostAsJsonAsync("Employee", emp).Result; return(RedirectToAction("Index")); }