public ActionResult Edit(EditLeaveAllocationViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var allocation = _mapper.Map <LeaveAllocation>(model); allocation.Employee = _repository.GetEmployeeById(allocation.EmployeeId); allocation.LeaveType = _repository.GetLeaveTypeById(allocation.LeaveTypeId); var Success = _repository.Update(allocation); if (!Success) { ModelState.AddModelError("", "Error While Saving"); return(View(model)); } return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); } catch { return(View()); } }
public async Task <ActionResult> Edit(EditLeaveAllocationVM model) { try { if (!ModelState.IsValid) { return(View(model)); } var record = await _leaveallocationrepo.FindById(model.Id); record.NumberOfDays = model.NumberOfDays; var isSuccess = await _leaveallocationrepo.Update(record); if (!isSuccess) { ModelState.AddModelError("", "Error while saving"); return(View(model)); } //no quiero retornar a Index, a la lista de leaveTypes. Quiero retronar a Details, y Details requiere un string id como prametro return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); } catch { return(View(model)); } }
public async Task <ActionResult> ApproveRequest(int id) { try { var request = await _requestRepo.FindById(id); var user = await _userManager.GetUserAsync(User); var allocation = await _allocationRepo.GetAllocationsByEmployeeAndType(request.RequestingEmployeeId, request.LeaveTypeId); request.Approved = true; request.ApprovedById = user.Id; //request.ApprovedBy.FirstName = user.FirstName; //request.ApprovedBy.LastName = user.LastName; request.DateActioned = DateTime.Now; int daysRequested = (int)(request.EndDate - request.StartDate).TotalDays; allocation.NumberOfDays -= daysRequested; await _requestRepo.Update(request); await _allocationRepo.Update(allocation); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { return(RedirectToAction(nameof(Index))); } }
public async Task <ActionResult> Edit(EditLeaveAllocationVM model) { try { if (!ModelState.IsValid) { return(View(model)); } //Both Works //This one Updates Whole Model received here //var allocation = _mapper.Map<LeaveAllocation>(model); //var isSuccess = _leaveallocationrepo.Update(allocation); //This one model is created here and updated only one filed and then saved var record = await _leaveallocationrepo.FindById(model.Id); record.NumberOfDays = model.NumberOfDays; var isSuccess = await _leaveallocationrepo.Update(record); if (!isSuccess) { ModelState.AddModelError("", "Error occured while saving data!"); return(View(model)); } return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); } catch { return(View(model)); } }
public async Task <ActionResult> ApproveRequest(int id) { try { var user = await _userManager.GetUserAsync(User); var leaveRequest = await _leaveRequestrepo.FindById(id); var empId = leaveRequest.requestEmployeeid; var leaveId = leaveRequest.LeaveTypeId; var allocation = await _leavaAllocRepo.getLeaveAllocationDetailonLeaveTypeId(empId, leaveId); var requestedDays = (int)(leaveRequest.endDate.Date - leaveRequest.startDate.Date).TotalDays; allocation.NumberOfDays -= requestedDays; leaveRequest.Approved = true; leaveRequest.approvedByid = user.Id; leaveRequest.dateActioned = DateTime.Now; await _leaveRequestrepo.Update(leaveRequest); await _leavaAllocRepo.Update(allocation); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { return(RedirectToAction(nameof(Index))); } }
public ActionResult ApproveRequest(int id) { try { var user = _userManager.GetUserAsync(User).Result; var leaveRequest = _leaveRequestRepo.FindById(id); leaveRequest.Approved = true; var allocation = _leaveAllocationRepo.GetLeaveAllocationsByEmployeeAndType(leaveRequest.RequestingEmployeeId, leaveRequest.LeaveTypeId); int daysRequested = (int)(leaveRequest.EndDate - leaveRequest.StartDate).TotalDays; allocation.NumberOfDays -= daysRequested; leaveRequest.ApprovedById = user.Id; leaveRequest.DateActioned = DateTime.Now; _leaveRequestRepo.Update(leaveRequest); _leaveAllocationRepo.Update(allocation); // ModelState.AddModelError("", "You do not have sufficient days for this request."); return(RedirectToAction(nameof(Index), "LeaveRequest")); } catch { ModelState.AddModelError("", "Something went wrong."); return(RedirectToAction(nameof(Index), "LeaveRequest")); } }
public async Task <ActionResult> EditLeaveAllocation(EditLeaveAllocationVM model) { try { if (!ModelState.IsValid) { return(View(model)); } var record = await _leaveallocationrepo.FindById(model.Id); record.NumberOfDays = model.NumberOfDays; var isSuccess = await _leaveallocationrepo.Update(record); if (!isSuccess) { ModelState.AddModelError("", "Error while saving"); return(View(model)); } return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); } catch { return(View()); } }
public ActionResult ApproveRequest(int id) { try { var user = _userManager.GetUserAsync(User).Result; var leaveRequest = _leaveRequestRepo.FindById(id); var employeeid = leaveRequest.RequestingEmployeeId; var leaveTypeId = leaveRequest.LeaveTypeId; var allocation = _leaveAllocationRepo.GetLeaveAllocationsByEmployeeAndType(employeeid, leaveTypeId); int daysRequested = (int)(leaveRequest.EndDate - leaveRequest.StartDate).TotalDays; allocation.NumberofDays = allocation.NumberofDays - daysRequested; leaveRequest.Approved = true; leaveRequest.ApprovedById = user.Id; leaveRequest.DateActioned = DateTime.Now; _leaveRequestRepo.Update(leaveRequest); _leaveAllocationRepo.Update(allocation); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { return(RedirectToAction(nameof(Index))); } }
public async Task <ActionResult> Edit(EditLeaveAllocationVMClass par_EditLeaveAllocationVMClass) { try { if (!ModelState.IsValid) { return(View(par_EditLeaveAllocationVMClass)); } var varRecord = await _ILeaveAllocationRepository.FindByID(par_EditLeaveAllocationVMClass.LeaveAllocationID); varRecord.NumberOfDays = par_EditLeaveAllocationVMClass.NumberOfDays; bool isSuccess = await _ILeaveAllocationRepository.Update(varRecord); if (!isSuccess) { ModelState.AddModelError("", "Error with update"); return(View(par_EditLeaveAllocationVMClass)); } // TODO: Add update logic here return(RedirectToAction(nameof(Details), new { id = par_EditLeaveAllocationVMClass.EmployeeID })); } catch { return(View()); } }
public async Task <ActionResult> ApproveRequest(int id) { var employee = await _userManager.GetUserAsync(User); var leaveRequest = await _leaveRequestRepo.FindById(id); var allocation = await _leaveAllocationRepo .GetLeaveAllocationByEmployeeAndType(leaveRequest.RequestingEmployeeId, leaveRequest.LeaveTypeId); int daysRequested = (int)(leaveRequest.EndDate.Date - leaveRequest.StartDate.Date).TotalDays; allocation.NumberOfDays -= daysRequested; leaveRequest.Approved = true; leaveRequest.ApprovedById = employee.Id; leaveRequest.DateActioned = DateTime.Now; await _leaveAllocationRepo.Update(allocation); await _leaveRequestRepo.Update(leaveRequest); await _leaveRequestRepo.Save(); await _leaveAllocationRepo.Save(); return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult> Edit(EditLeaveAllocationViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } /* find the original of the record we would * like to mutate. * Set the value of the field. */ var record = await _allocationrepo.FindById(model.Id); record.NumberOfDays = model.NumberOfDays; var isSuccess = await _allocationrepo.Update(record); if (!isSuccess) { ModelState.AddModelError("", "Error editing a leave allocation."); return(View(model)); } return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); } catch { return(View(model)); } }
public async Task <ActionResult> ApproveRequest(int id) { try { var admin = await _userManager.GetUserAsync(User); var leaveRequest = await _leaveRequestRepo.FindById(id); var allocation = await _leaveAllocationRepo.GetLeaveAllocationByEmployeeAndType(leaveRequest.RequestingEmployeeId, leaveRequest.LeaveTypeId); int daysRequested = (int)(leaveRequest.EndDate - leaveRequest.StartDate).TotalDays; allocation.NumberOfDays -= daysRequested; leaveRequest.Approved = true; leaveRequest.ApprovedById = admin.Id; leaveRequest.DateActioned = DateTime.Now; await _leaveRequestRepo.Update(leaveRequest); await _leaveAllocationRepo.Update(allocation); return(RedirectToAction(nameof(Index))); } catch (Exception e) { ModelState.AddModelError("", "Something went wrong"); return(RedirectToAction(nameof(Index))); } }
public ActionResult Edit(EditLeaveAllocationVM model) { try { if (!ModelState.IsValid) { return(View(model)); } // TODO: Add update logic here var record = _leaverepo.FindById(model.Id); record.NumberOfDays = model.NumberOfDays; //var allocation = _mapper.Map<LeaveAllocation>(model); var isSuccess = _leaverepo.Update(record); if (!isSuccess) { ModelState.AddModelError("", "Something Went Wrong"); return(View(model)); } return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); } catch { return(View()); } }
public async Task <ActionResult> ApproveRequest(int id) { try { var user = await _userManager.GetUserAsync(User); var leaveRequest = await _leaveRequestRepo.FindById(id); var employeeId = leaveRequest.RequestingEmployeeId; var leaveTypeId = leaveRequest.LeaveTypeId; var allocation = await _leaveAllocRepo.GetLeaveAllocationsByEmployeeAndType(employeeId, leaveTypeId); //Substract days from allocation var numberOfDays = (int)(leaveRequest.EndDate - leaveRequest.StartDate).TotalDays; allocation.NumberOfDays -= numberOfDays; leaveRequest.Approved = true; leaveRequest.ApprovedById = user.Id; leaveRequest.DateActioned = DateTime.Now; //Save await _leaveRequestRepo.Update(leaveRequest); await _leaveAllocRepo.Update(allocation); return(RedirectToAction(nameof(Index))); } catch (Exception e) { return(RedirectToAction(nameof(Index))); } }
public async Task <ActionResult> ApproveRequest(int id) { try { var leaveRequest = await _leaveRequestRepo.FindById(id); leaveRequest.Approved = true; leaveRequest.ApprovedById = _userManager.GetUserAsync(User).Result.Id; leaveRequest.DateActioned = DateTime.Now; var isSuccess = await _leaveRequestRepo.Update(leaveRequest); if (!isSuccess) { ModelState.AddModelError("", "Something Went Wrong with the registration...."); return(RedirectToAction(nameof(Index))); } else { var employeeAllocation = await _leaveAllocationRepo.GetLeaveAllocationsByEmployeeAndType(leaveRequest.RequestingEmployeeId, leaveRequest.LeaveTypeId); var InitialNumberOfDays = employeeAllocation.NumberOfDays; var DaysRequested = (int)(leaveRequest.EndDate.Date - leaveRequest.StartDate.Date).TotalDays; var DaysRemaining = InitialNumberOfDays - DaysRequested; employeeAllocation.NumberOfDays = DaysRemaining; var IsSuccess = await _leaveAllocationRepo.Update(employeeAllocation); if (!isSuccess) { ModelState.AddModelError("", "Something Went Wrong with the registration...."); return(RedirectToAction(nameof(Index))); } return(RedirectToAction(nameof(Index))); } } catch { ModelState.AddModelError("", "Something Went Wrong with the registration...."); return(RedirectToAction(nameof(Index))); } }
public IActionResult Details(LeaveRequestViewModel model) { var request = _mapper.Map <LeaveRequest>(model); request.RequestingEmployee = _employeeRepository.FindById(Guid.Parse(model.RequestingEmployeeId)); request.ApprovedBy = _employeeRepository.FindById(Guid.Parse(_userManager.GetUserAsync(User).Result.Id)); request.LeaveType = _leaveTypeRepository.FindById(model.LeaveTypeId); if (request.Approved == true) { var allocation = _leaveAllocationRepository.GetLeaveAllocationByEmployeeAndLeaveType(request.RequestingEmployee.Id, request.LeaveType.Id); allocation.NumberOfDays -= (int)(request.EndDate - request.StartDate).TotalDays; _leaveAllocationRepository.Update(allocation); } _leaveRequestRepository.Update(request); return(RedirectToAction("Index")); }
public async Task <ActionResult> ApproveRequest(int id) { try { var user = await _userManager.GetUserAsync(User); var leaveRequest = await _leaveRequestRepo.FindById(id); var employeeId = leaveRequest.RequestingEmployeeId; var currentUser = _userManager.GetUserAsync(User).Result; if (employeeId == currentUser.Id) { return(NotFound("Bạn không thể phê duyệt yêu cầu nghỉ phép của chính mình.")); } var LichSuChamCongList = await nhatKylamViecRepository.FindByMaNhanVien(employeeId); foreach (var item in LichSuChamCongList) { if (leaveRequest.StartDate.CompareTo(item.ThoiGianBatDau.Date) <= 0 && leaveRequest.EndDate.CompareTo(item.ThoiGianBatDau.Date) >= 0 ) { string errorMessage = "Khoảng thời gian của nghỉ phép được phê duyệt trùng với lịch biểu chấm công" + "\n Khoảng thời gian của nghỉ phép: " + leaveRequest.StartDate + " => " + leaveRequest.EndDate + "\n Lịch biểu bị trùng: " + item.ThoiGianBatDau + " => " + item.ThoiGianKetThuc; return(NotFound(errorMessage)); } } var leaveTypeId = leaveRequest.LeaveTypeId; var allocation = await _leaveAllocationRepo.GetLeaveAllocationsByEmployeeAndType(employeeId, leaveTypeId); int daysRequested = (int)(leaveRequest.EndDate - leaveRequest.StartDate).TotalDays; allocation.NumberOfDays -= daysRequested; leaveRequest.Approved = true; leaveRequest.ApprovedById = user.Id; leaveRequest.DateActioned = DateTime.Now; await _leaveRequestRepo.Update(leaveRequest); await _leaveAllocationRepo.Update(allocation); return(RedirectToAction(nameof(Index))); } catch { return(RedirectToAction(nameof(Index))); } }
public ActionResult Edit(EditAllocationVM entity) { if (ModelState.IsValid == false) { return(View(entity)); } var record = _leaveAllocationRepo.FindById(entity.Id); record.NumberOfDays = entity.NumberofDays; if (_leaveAllocationRepo.Update(record) == false) { ModelState.AddModelError("", "Error while updating the record"); return(View(entity)); } return(RedirectToAction(nameof(Details), new { Id = entity.EmployeeId })); }
public ActionResult Edit(int id, LeaveAllocationViewModel model) { try { var leaveAllocation = _mapper.Map <LeaveAllocation>(model); if (!_repo.Update(leaveAllocation)) { ModelState.AddModelError("", "Something went wrong...."); return(View(model)); } return(RedirectToAction(nameof(ListEmployees))); } catch { ModelState.AddModelError("", "Something went wrong...."); return(View()); } }
public async Task <ActionResult> Edit(EditLeaveAllocationVM model) { if (!ModelState.IsValid) { return(View(model)); } var allocation = await _leaveAllocationRepo.FindById(model.Id); allocation.NumberOfDays = model.NumberOfDays; var isSuccess = await _leaveAllocationRepo.Update(allocation); if (!isSuccess) { ModelState.AddModelError("", "Error al guardar"); return(View(model)); } await _leaveAllocationRepo.Save(); return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); }
public ActionResult Edit(EditLeaveAllocationViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var allocation = _leaveallocationrepo.FindById(model.Id); allocation.NumberOfDays = model.NumberOfDays; var isSuccess = _leaveallocationrepo.Update(allocation); if (!isSuccess) { ModelState.AddModelError("", "Error while saving"); return(View(model)); } return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); } catch { return(View()); } }
public ActionResult Edit(EditLeaveAllocationVM model) { try { if (!ModelState.IsValid) { return(View(model)); } var allocation = _mapper.Map <LeaveAllocation>(model); allocation.Period = DateTime.Now.Year; var isSuccess = _leaveallocationrepo.Update(allocation); if (!isSuccess) { ModelState.AddModelError("", "Error while saving"); return(View(model)); } return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); } catch { return(View()); } }
public ActionResult Edit(EditLeaveAllocationViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var record = _leaveallocationrepo.FindById(model.Id); record.NumberofDays = model.NumberofDays; var isSuccess = _leaveallocationrepo.Update(record); if (!isSuccess)//If their was not a successful update: { ModelState.AddModelError("", "Save Error"); return(View(model)); } return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); } catch { ModelState.AddModelError("", "Something went wrong..."); return(View()); } }
public ActionResult Edit(EditLeaveAllocationVM model) { try { // TODO: Add update logic here if (!ModelState.IsValid) { return(View(model)); } var record = _leaveallocationrepo.FindById(model.Id); record.NumberOfDays = model.NumberOfDays; var isSuccess = _leaveallocationrepo.Update(record); if (!isSuccess) { ModelState.AddModelError("", "Error While Saving"); return(View(model)); } return(RedirectToAction(nameof(Details), new { id = model.EmployeeId })); } catch { return(View(model)); } }