コード例 #1
0
 public void AllocateUserInDepartment(long requisitionID, long departmentId, decimal percentage, UserAllocation allocate, long requestedDepartmentId)
 {
     if (allocate == null)
     {
         UserAllocation userAllocate = new UserAllocation();
         userAllocate.RequisitionID         = requisitionID;
         userAllocate.StartDate             = DateTime.Now;
         userAllocate.DepartmentID          = departmentId;
         userAllocate.Percentage            = percentage;
         userAllocate.RequestedDepartmentID = requestedDepartmentId;
         userAllocate.Status           = RequestStatus.Pending;
         userAllocate.CreatedBy        = new Guid(User.Identity.GetUserId());
         userAllocate.UserDepartmentID = requestedDepartmentId;
         userAllocate.GroupNumber      = requisitionID;
         userAllocate.IsActive         = false;
         userAllocationManagement.Add(userAllocate);
     }
     else
     {
         allocate.StartDate  = DateTime.Now;
         allocate.Percentage = percentage;
         allocate.IsActive   = false;
         allocate.Status     = RequestStatus.Pending;
         allocate.Comments   = string.Empty;
         allocate.ModifiedBy = new Guid(User.Identity.GetUserId());
         userAllocationManagement.Update(allocate);
     }
 }
コード例 #2
0
        private void UpdateUserAllocation(string userId, long?requisitionID)
        {
            if (requisitionID.HasValue)
            {
                long reqId           = Convert.ToInt64(requisitionID);
                var  userAllocations = userAllocationManagement.GetUserAllocationsByRequisition(reqId);
                foreach (var allocation in userAllocations)
                {
                    UserAllocation userAllocate = new UserAllocation();
                    userAllocate.RequestedDepartmentID = allocation.RequestedDepartmentID;
                    userAllocate.DepartmentID          = allocation.DepartmentID;
                    userAllocate.UserID        = userId;
                    userAllocate.RequisitionID = allocation.RequisitionID;
                    userAllocate.StartDate     = allocation.StartDate;
                    userAllocate.EndDate       = allocation.EndDate;
                    userAllocate.IsActive      = allocation.IsActive;
                    userAllocate.Percentage    = allocation.Percentage;
                    userAllocate.CreatedBy     = new Guid(User.Identity.GetUserId());
                    userAllocate.Status        = allocation.Status;

                    userAllocationManagement.Add(userAllocate);
                }

                userAllocationManagement.SaveUserAllocation();
            }
        }
コード例 #3
0
        public JsonResult AddEdit(UserReAllocationVM model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string deparmentError = ValidateUserDeparments(model);
                    if (!string.IsNullOrEmpty(deparmentError))
                    {
                        return(Json(new { Message = deparmentError, MessageClass = MessageClass.Error, Response = false }));
                    }

                    bool isHundredPercent = ValidateAllocationPercentage(model);
                    if (!isHundredPercent)
                    {
                        return(Json(new { Message = "Total user department allocation must equal to 100%", MessageClass = MessageClass.Error, Response = false }));
                    }

                    if (!PermissionControl.CheckPermission(UserAppPermissions.UserAllocation_Add) && !PermissionControl.CheckPermission(UserAppPermissions.UserAllocation_Edit))
                    {
                        logger.Info("Don't have rights to add update user allocation");
                        return(Json(new { Message = Resources.Messages.MSG_RESTRICTED_ACCESS, MessageClass = MessageClass.Error, Response = false }));
                    }

                    var userPendingAllocation = userAllocationManagement.GetUserPendingAllocationsByUserId(model.UserId);
                    if (userPendingAllocation != null && userPendingAllocation.Count() > 0)
                    {
                        logger.Info("user have already applied for user allocation and its in pending.");
                        return(Json(new { Message = "you have already applied for this user allocation and its in pending.", MessageClass = MessageClass.Error, Response = false }));
                    }

                    var user           = UserManager.FindById(User.Identity.GetUserId());
                    var userDepartment = userdepartmentManagement.GetUserPrimaryDepartmentById(model.UserId);

                    if (userDepartment == null)
                    {
                        logger.InfoFormat("Selected User with ID [{0}] has no department assigned yet", model.UserId);
                        return(Json(new { Message = "Selected User have no department assigned. first add his department to perform user allocation opertion.", MessageClass = MessageClass.Error, Response = false }));
                    }

                    var requesteduserDepartment = userdepartmentManagement.GetUserPrimaryDepartmentById(User.Identity.GetUserId());

                    if (requesteduserDepartment == null)
                    {
                        logger.InfoFormat("User Allocation requested User with ID [{0}] has no department assigned him", model.UserId);
                        return(Json(new { Message = "User Allocation requested User has no department assigned. first add his department to perform user allocation opertion.", MessageClass = MessageClass.Error, Response = false }));
                    }

                    long groupNumber = DateTime.Now.Ticks;
                    for (int i = 0; i < model.SelectedDepartment.Length; i++)
                    {
                        UserAllocation userAllocate = new UserAllocation();
                        userAllocate.UserID                = model.UserId;
                        userAllocate.StartDate             = DateTime.Now;
                        userAllocate.DepartmentID          = model.SelectedDepartment[i];
                        userAllocate.Percentage            = model.SelectedDepartmentPercentage[i];
                        userAllocate.RequestedDepartmentID = requesteduserDepartment.DepartmentID;
                        userAllocate.Status                = RequestStatus.Pending;
                        userAllocate.CreatedBy             = new Guid(User.Identity.GetUserId());
                        userAllocate.IsActive              = false;
                        userAllocate.GroupNumber           = groupNumber;
                        userAllocate.UserDepartmentID      = userDepartment.DepartmentID;
                        userAllocationManagement.Add(userAllocate);
                    }

                    userAllocationManagement.SaveUserAllocation();

                    SendUserAllocationEmailsToLevel1Departments(groupNumber);
                    logger.Info("Successfully Saved User Allocation ");
                    return(Json(new { Message = string.Format(Resources.Messages.MSG_GENERIC_ADD_SUCCESS, "User Allocation"), MessageClass = MessageClass.Success, Response = true }));
                }
                else
                {
                    return(Json(new { Message = string.Format(Resources.Messages.MSG_GENERIC_ADD_FAILED, "User Allocation"), MessageClass = MessageClass.Error, Response = false }));
                }
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Exception Raised : Message[{0}] Stack Trace [{1}] ", ex.Message, ex.StackTrace);
                return(Json(new { Message = Resources.Messages.MSG_GENERIC_FAILED, MessageClass = MessageClass.Error, Response = false }));
            }
        }