public async Task <IActionResult> Edit(int id, [Bind("Mon,Tue,Wed,Thur,Fri,Sat,Sun,ID,Status,HoursWorked")] Timesheet timesheet) { if (id != timesheet.ID) { return(NotFound()); } var currentUser = await _userManager.GetUserAsync(User); if (ModelState.IsValid) { try { timesheet.OwnerId = currentUser.Id; timesheet.HoursWorked = timesheet.Mon + timesheet.Tue + timesheet.Wed + timesheet.Thur + timesheet.Fri + timesheet.Sat + timesheet.Sun; _context.Update(timesheet); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TimesheetExists(timesheet.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(timesheet)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Employer,HourlyRate")] Contract contract) { if (id != contract.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(contract); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContractExists(contract.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(contract)); }
public async Task <IActionResult> Edit(string id, [Bind("Id,FirstName,LastName,RateOfPay,HoursWorked,PayWeek")] 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(int id, [Bind("Id,EmployeeId,FirstName,LastName,Relationship")] Dependent dependent) { if (id != dependent.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(dependent); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DependentExists(dependent.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(dependent)); }
public async Task <IActionResult> Edit(int id, [Bind("OwnerId,ID,Status,totalHoursWorked,totalEarnings")] Payslip payslip) { if (id != payslip.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(payslip); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PayslipExists(payslip.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(payslip)); }
public async Task <IActionResult> AddOrEdit(int id, [Bind("TransactionLogId,Date,ProductId,OperationId,BoxQty")] TransactionLog transactionLog) { TransactionLog exObj = new TransactionLog(); try { if (ModelState.IsValid) { transactionLog.Date = transactionLog.Date.Date; exObj = transactionLog; if (id == 0) { _context.Add(transactionLog); await _context.SaveChangesAsync(); } else { try { _context.Update(transactionLog); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TransactionLogExists(transactionLog.TransactionLogId)) { return(NotFound()); } else { throw; } } } return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "_ViewAll", _context.TransacionLog.Include(t => t.Operation).Include(t => t.Product) .Where(t => t.Date.Date >= DateTime.Today.AddDays(-14)).ToList()) })); } ViewData["OperationId"] = new SelectList(_context.Operation, "OperationId", "OperationName", transactionLog.OperationId); ViewData["ProductId"] = new SelectList(_context.Product, "ProductId", "ProductName", transactionLog.ProductId); return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEdit", transactionLog) })); } catch (Exception ex) { ViewBag.ErrorMessage = ex.InnerException.Message.ToString(); ViewData["OperationId"] = new SelectList(_context.Operation, "OperationId", "OperationName", exObj.OperationId); ViewData["ProductId"] = new SelectList(_context.Product, "ProductId", "ProductName", exObj.ProductId); return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEdit", exObj) })); } }
public async Task <IActionResult> Edit(int id, [Bind("PayrollReleaseId,Date,EmployeeId,Ammount")] PayrollRelease payrollRelease) { if (id != payrollRelease.PayrollReleaseId) { return(NotFound()); } if (ModelState.IsValid) { try { //take empId 'cause not sent to controller(disabled) var empid = _context.PayrollRelease.Where(p => p.PayrollReleaseId == id) .Select(p => p.EmployeeId).FirstOrDefault(); payrollRelease.EmployeeId = empid; _context.Update(payrollRelease); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PayrollReleaseExists(payrollRelease.PayrollReleaseId)) { return(NotFound()); } else { throw; } } return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "_ViewPayroll", _context.PayrollRelease.Include(p => p.Employee).ToList()) })); } ViewData["EmployeeId"] = new SelectList(_context.Employee, "EmployeeId", "Name", payrollRelease.EmployeeId); return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "Edit", payrollRelease) })); }
public async Task <TEntity> UpdateAsync(TEntity entity) { if (entity == null) { throw new ArgumentNullException($"{nameof(UpdateAsync)} entity must not be null"); } try { _payrollContext.Update(entity); await _payrollContext.SaveChangesAsync(); return(entity); } catch (Exception ex) { throw new Exception($"{nameof(entity)} could not be updated: {ex.Message}"); } }