示例#1
0
        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;
        }
示例#2
0
        public ActionResult DeleteConfirmed(int id)
        {
            LeaveEntitlement leaveEntitlement = db.LeaveEntitlements.Find(id);

            db.LeaveEntitlements.Remove(leaveEntitlement);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#3
0
 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));
 }
示例#4
0
        // 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));
        }
示例#5
0
        // 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));
        }
示例#6
0
        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;
        }
示例#7
0
 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));
                }
            }
        }