public LeaveEntitlementModel(LeaveEntitlement leaveEntitlement) { Id = leaveEntitlement.Id; if (leaveEntitlement.Employee.User.Person != null) { Employee = leaveEntitlement.Employee.User.Person.Name; } if (leaveEntitlement.LeaveType != null) { LeaveType = leaveEntitlement.LeaveType.Title; } if (leaveEntitlement.LeaveTimePeriod != null) { LeaveTimePeriod = leaveEntitlement.LeaveTimePeriod.Title; } if (leaveEntitlement.CreatedByUser.Person != null) { AllocatedBy = leaveEntitlement.CreatedByUser.Person.Name; } Allocation = leaveEntitlement.Allocation; Comments = leaveEntitlement.Comments; CreatedOn = leaveEntitlement.CreatedOn; }
public ActionResult DeleteConfirmed(int id) { LeaveEntitlement leaveEntitlement = db.LeaveEntitlements.Find(id); db.LeaveEntitlements.Remove(leaveEntitlement); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "LeaveEntitlementID,LeaveYear,LeaveTypeID,LeaveDays,Attendance")] LeaveEntitlement leaveEntitlement) { if (ModelState.IsValid) { db.Entry(leaveEntitlement).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.LeaveTypeID = new SelectList(db.LeaveTypes, "LeaveTypeID", "LeaveTypeName", leaveEntitlement.LeaveTypeID); return(View(leaveEntitlement)); }
// GET: LeaveEntitlements/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LeaveEntitlement leaveEntitlement = db.LeaveEntitlements.Find(id); if (leaveEntitlement == null) { return(HttpNotFound()); } return(View(leaveEntitlement)); }
// GET: LeaveEntitlements/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LeaveEntitlement leaveEntitlement = db.LeaveEntitlements.Find(id); if (leaveEntitlement == null) { return(HttpNotFound()); } ViewBag.LeaveTypeID = new SelectList(db.LeaveTypes, "LeaveTypeID", "LeaveTypeName", leaveEntitlement.LeaveTypeID); return(View(leaveEntitlement)); }
public UpdateLeaveEntitlementViewModel(LeaveEntitlement entitlement) { Id = entitlement.Id; LeaveTimePeriodId = entitlement.LeaveTimePeriodId; EmployeeId = entitlement.EmployeeId.Value; LeaveTypeId = entitlement.LeaveTypeId; if (entitlement.Employee.User.Person != null) { Employee = entitlement.Employee.User.Person.Name; } if (entitlement.LeaveType != null) { LeaveType = entitlement.LeaveType.Title; } if (entitlement.LeaveTimePeriod != null) { LeaveTimePeriod = entitlement.LeaveTimePeriod.Title; } Allocation = entitlement.Allocation; Comments = entitlement.Comments; }
public ActionResult Manage([Bind(Include = "LeaveEntitlementID,LeaveYear,LeaveTypeID,LeaveDays")] LeaveEntitlement item) { return(base.BaseSave <LeaveEntitlement>(item, item.LeaveEntitlementID > 0)); }
public JsonResult UpdateLeaveEntitlement(UpdateLeaveEntitlementViewModel vm) { var currentEntitlements = _leaveEntitlementRepository.GetBy(e => e.EmployeeId == vm.EmployeeId && e.LeaveTimePeriodId == vm.LeaveTimePeriodId && e.LeaveTypeId == vm.LeaveTypeId); if (vm.Operation == LeaveOperation.Deduct) { if (currentEntitlements != null) { if (currentEntitlements.Allocation - vm.Allocation >= 0) { // Create a log var newLeaveEntitlementUpdate = new LeaveEntitlementUpdate { EmployeeId = vm.EmployeeId, LeaveTimePeriodId = vm.LeaveTimePeriodId, LeaveTypeId = vm.LeaveTypeId, Operation = vm.Operation, LeaveCount = vm.Allocation, PreviousBalance = currentEntitlements.Allocation, NewBalance = currentEntitlements.Allocation - vm.Allocation, Comments = vm.Comments, CreatedByUserId = WebUser.Id }; _leaveEntitlementUpdateRepository.Create(newLeaveEntitlementUpdate); _unitOfWork.Commit(); // Update Entitlements currentEntitlements.Allocation = currentEntitlements.Allocation - vm.Allocation; currentEntitlements.UpdatedByUserId = WebUser.Id; _leaveEntitlementRepository.Update(currentEntitlements); _unitOfWork.Commit(); return(Json(true)); } return(Json(false)); } return(Json(false)); } else { if (currentEntitlements != null) { // Create a log var newLeaveEntitlementUpdate = new LeaveEntitlementUpdate { EmployeeId = vm.EmployeeId, LeaveTimePeriodId = vm.LeaveTimePeriodId, LeaveTypeId = vm.LeaveTypeId, Operation = vm.Operation, LeaveCount = vm.Allocation, PreviousBalance = currentEntitlements.Allocation, NewBalance = currentEntitlements.Allocation + vm.Allocation, Comments = vm.Comments, CreatedByUserId = WebUser.Id }; _leaveEntitlementUpdateRepository.Create(newLeaveEntitlementUpdate); _unitOfWork.Commit(); // Update Entitlements currentEntitlements.Allocation = currentEntitlements.Allocation + vm.Allocation; currentEntitlements.UpdatedByUserId = WebUser.Id; _leaveEntitlementRepository.Update(currentEntitlements); _unitOfWork.Commit(); return(Json(true)); } else { // Create a log var newLeaveEntitlementUpdate = new LeaveEntitlementUpdate { EmployeeId = vm.EmployeeId, LeaveTimePeriodId = vm.LeaveTimePeriodId, LeaveTypeId = vm.LeaveTypeId, Operation = vm.Operation, LeaveCount = vm.Allocation, PreviousBalance = 0, NewBalance = vm.Allocation, Comments = vm.Comments, CreatedByUserId = WebUser.Id }; _leaveEntitlementUpdateRepository.Create(newLeaveEntitlementUpdate); _unitOfWork.Commit(); // Create Entitlements var newEntitlement = new LeaveEntitlement { EmployeeId = vm.EmployeeId, LeaveTimePeriodId = vm.LeaveTimePeriodId, LeaveTypeId = vm.LeaveTypeId, Allocation = vm.Allocation, Comments = vm.Comments, CreatedByUserId = WebUser.Id }; _leaveEntitlementRepository.Create(newEntitlement); _unitOfWork.Commit(); return(Json(true)); } } }