public async Task <JsonResult> Edit(string loan) { try { if (ModelState.IsValid) { Loan loanEntity = JsonConvert.DeserializeObject <Loan>(loan); var loanToUpdate = _context.Loan.Where(u => u.LoanCode == loanEntity.LoanCode).FirstOrDefault(); loanToUpdate.LoanCode = loanEntity.LoanCode; loanToUpdate.Principal = loanEntity.Principal; loanToUpdate.WithInterest = loanEntity.WithInterest; loanToUpdate.TotalPayments = loanEntity.TotalPayments; loanToUpdate.Balance = loanEntity.Balance; loanToUpdate.Amortization = loanEntity.Amortization; loanToUpdate.ApprovedDate = loanEntity.ApprovedDate; loanToUpdate.StartDate = loanEntity.StartDate; loanToUpdate.Remarks = loanEntity.Remarks; loanToUpdate.Hold = loanEntity.Hold; loanToUpdate.Frequency = loanEntity.Frequency; _context.Entry(loanToUpdate).State = EntityState.Modified; //_context.Entry(loanToUpdate).CurrentValues.SetValues(loanObj); // TODO: Add update logic here await _context.SaveChangesAsync(); } return(Json(new { Success = true })); } catch { throw; } }
public JsonResult UpdateEmployeePersonal(string employee) { try { // TODO: Add update logic here if (ModelState.IsValid) { Employee employeeObj = JsonConvert.DeserializeObject <Employee>(employee); var employeeToUpdate = _context.Employee.Where(e => e.EmployeeId.Trim() == employeeObj.EmployeeId.Trim()).FirstOrDefault(); employeeObj.CompanyId = HttpContext.Session.GetString("CompanyId"); employeeObj.CreatedBy = "admin"; employeeObj.CreatedDate = DateTime.Now; employeeObj.LastUpdBy = "admin"; employeeObj.LastUpdDate = DateTime.Now; _context.Entry(employeeToUpdate).CurrentValues.SetValues(employeeObj); _context.SaveChanges(); } return(Json(new { Success = true })); } catch { throw; } }
public virtual void Edit(T entity) { //DbEntityEntry dbEntityEntry = DbContext.Entry<T>(entity); //dbEntityEntry.State = EntityState.Modified; dbSet.Attach(entity); dataContext.Entry(entity).State = EntityState.Modified; }
public virtual void Delete(TEntity entityToDelete) { if (context.Entry(entityToDelete).State == EntityState.Detached) { dbSet.Attach(entityToDelete); } dbSet.Remove(entityToDelete); }
public ActionResult Edit([Bind(Include = "SalaryGradeID,Salary,Grade")] SalaryGrade salarygrade) { if (ModelState.IsValid) { db.Entry(salarygrade).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(salarygrade)); }
public ActionResult Edit([Bind(Include = "EmployeeID,FirstName,Lastname,SalaryGradeID,DOB")] Employee employee) { if (ModelState.IsValid) { db.Entry(employee).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SalaryGradeID = new SelectList(db.SalaryGrades, "SalaryGradeID", "Grade", employee.SalaryGradeID); return(View(employee)); }
public ActionResult Edit([Bind(Include = "WorkId,TimeIn,TimeOut,WorkDate,EmployeeID")] Work work) { if (ModelState.IsValid) { db.Entry(work).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "FirstName", work.EmployeeID); return(View(work)); }
public ActionResult Edit([Bind(Include = "LocationID,Location,WorkID,EmployeeID")] WorkLocation worklocation) { if (ModelState.IsValid) { db.Entry(worklocation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "FirstName", worklocation.EmployeeID); ViewBag.WorkID = new SelectList(db.Works, "WorkId", "WorkId", worklocation.WorkID); return(View(worklocation)); }
public void Update(T entity, string[] propertyToUpdate) { _dbSet.Attach(entity); foreach (string property in propertyToUpdate) { _context.Entry <T>(entity).Property(property).IsModified = true; } if (!_sharedContext) { _context.SaveChanges(); } }
public async Task <JsonResult> EditTimeSheet(string timeSheet, string employeeId) { try { if (ModelState.IsValid) { var tsData = await _context.Timesheet2.AsNoTracking().Where(t => t.EmployeeId == employeeId).ToListAsync(); if (tsData == null) { List <Timesheet2> timeSheetEntity = JsonConvert.DeserializeObject <List <Timesheet2> >(timeSheet); foreach (var ts in timeSheetEntity) { ts.EmployeeId = employeeId; ts.CompanyId = HttpContext.Session.GetString("CompanyId"); _context.Add(ts); await _context.SaveChangesAsync(); } } else { List <Timesheet2> timeSheetEntity = JsonConvert.DeserializeObject <List <Timesheet2> >(timeSheet); foreach (var ts in timeSheetEntity) { var timeSheetToUpdate = _context.Timesheet2.Where(u => u.EmployeeId == employeeId && u.TsCode == ts.TsCode).FirstOrDefault(); if (timeSheetToUpdate == null) { ts.EmployeeId = employeeId; ts.CompanyId = HttpContext.Session.GetString("CompanyId"); _context.Add(ts); } else { timeSheetToUpdate.TsDays = ts.TsDays; timeSheetToUpdate.TsHrs = ts.TsHrs; timeSheetToUpdate.TsMins = ts.TsMins; _context.Entry(timeSheetToUpdate).State = EntityState.Modified; } await _context.SaveChangesAsync(); } } } return(Json(new { Success = true })); } catch { throw; } }