public async Task <IActionResult> Edit(string id, [Bind("Age,Attrition,BusinessTravel,DailyRate,Department,DistanceFromHome,Education,EducationField,EmployeeCount,EmployeeNumber,EnvironmentSatisfaction,Gender,HourlyRate,JobInvolvement,JobLevel,JobRole,JobSatisfaction,MaritalStatus,MonthlyIncome,MonthlyRate,NumCompaniesWorked,Over18,OverTime,PercentSalaryHike,PerformanceRating,RelationshipSatisfaction,StandardHours,StockOptionLevel,TotalWorkingYears,TrainingTimesLastYear,WorkLifeBalance,YearsAtCompany,YearsInCurrentRole,YearsSinceLastPromotion,YearsWithCurrManager")] Models.Data data) { if (id != data.EmployeeNumber) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(data); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DataExists(data.EmployeeNumber)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(data)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Surname,BirthDate,Job,Payment")] Employee employee) { if (id != employee.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(employee); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(employee.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(employee)); }
public async Task <IActionResult> Edit(string id, [Bind("Id,Name,NormalizedName,ConcurrencyStamp")] AspNetRoles aspNetRoles) { if (id != aspNetRoles.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(aspNetRoles); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AspNetRolesExists(aspNetRoles.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(aspNetRoles)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,EmployeeName,JoiningDate,Department,Salary,EmailAddress,Address")] Employees employees) { if (id != employees.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(employees); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeesExists(employees.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(employees)); }
public ActionResult EditEmployee(Employee employee) { if (employee.EmploymentDate == DateTime.MinValue) { return(View(employee)); } _employeeDb.Update(employee); return(RedirectToAction("Index")); }
public Employee Update(Employee employee) { int Id = employee.Id; var emp = _db.Employees.FirstOrDefault(x => x.Id == Id); emp.Name = employee.Name; emp.LastName = employee.LastName; emp.Email = employee.Email; emp.Department = employee.Department; _db.Update(emp); _db.SaveChanges(); return(emp); }
public async Task <IActionResult> AddOrEdit([Bind("EmployeeId,FullName,EmpCode,Position,OfficeLocation")] Employee employee) { if (ModelState.IsValid) { if (employee.EmployeeId == 0) { _context.Add(employee); } else { _context.Update(employee); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(employee)); }
// Замена старых данных сотрудника новыми данными public async Task <ActionResult <Employee> > Put(Employee employee) { // Возвращаем клиенту ответ, что данные некорректны if (employee == null) { return(BadRequest()); } // Возвращаем ответ со статусом NotFound в случае, если сотрудник с таким // ID не обнаружен if (!db.Employees.Any(x => x.Id == employee.Id)) { return(NotFound()); } db.Update(employee); await db.SaveChangesAsync(); return(Ok(employee)); }
public async Task <object> Save([FromBody] JObject o, [FromQuery] string type) { var assembly = _context.GetType().Assembly; var assemblyName = assembly.GetName().Name; var objectType = assembly.GetType($"{assemblyName}.Models.{type}"); var entity = o.ToObject(objectType); var id = objectType.GetProperty("Id")?.GetValue(entity); var result = id == null || (uint)id == 0 ? await _context.AddAsync(entity) : _context.Update(entity); await _context.SaveChangesAsync(); return(result?.Entity); }