Exemple #1
0
        public ActionResult AddDepartmentAllocation()
        {
            UserAllocation userDepartment = new UserAllocation();

            userDepartment.Departments = departmentManagement.GetAllDepartments();
            return(PartialView("_UserAllocatedDepartment", userDepartment));
        }
        private void DeActivatedPreviousAllocation(UserAllocation req, string selectedType)
        {
            if (req.UserID != null && !req.RequisitionID.HasValue && selectedType == RequestStatus.Approved)
            {
                var allocation         = userAllocationManagement.GetUserAllocationByGroupNumber(req.GroupNumber);
                var deActiveAllocation = allocation.Where(x => !x.IsActive).ToList();

                if (deActiveAllocation != null && deActiveAllocation.Count == 0)
                {
                    var activeUserAllocation = userAllocationManagement.GetActiveUserAllocationExceptGroupNumber(req.UserID, req.GroupNumber);
                    foreach (var allocate in activeUserAllocation)
                    {
                        allocate.IsActive   = false;
                        allocate.Status     = RequestStatus.Closed;
                        allocate.ModifiedBy = new Guid(User.Identity.GetUserId());
                        userAllocationManagement.Update(allocate);
                    }


                    var groupAllocation = userAllocationManagement.GetUserAllocationByGroupNumber(req.GroupNumber);
                    foreach (var allocate in groupAllocation)
                    {
                        allocate.IsActive   = true;
                        allocate.Status     = RequestStatus.Approved;
                        allocate.ModifiedBy = new Guid(User.Identity.GetUserId());
                        userAllocationManagement.Update(allocate);
                    }

                    userAllocationManagement.SaveUserAllocation();

                    SendUserAllocationEmailsToRequestCreator(req.GroupNumber, RequestStatus.Approved, req.Comments);
                }
            }
        }
Exemple #3
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);
     }
 }
Exemple #4
0
        /// <summary>
        /// 加载导出Excel页面
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Excel(int id = 0)
        {
            if (id == 0)
            {
                var entity = new UserAllocation()
                {
                    Id = 0,
                    AllocationStare = 1,
                    StartNumber     = 1,
                    EndNumber       = 1,
                    NumCount        = 1,
                    UaId            = 1
                };
                ViewData["entity"] = entity;
            }
            else
            {
                var entity = UserAllocationContract.GetByKey(id);
                //    //后台容错,有异常数据直接抛出。框架会自动跳转到错误页面。
                if (entity == null)
                {
                    throw new Exception("未找到该实体");
                }

                ViewData["entity"] = entity;
            }


            return(View());
        }
Exemple #5
0
        public int UpdateUserAllocation(UserAllocation UserAllocation)
        {
            using (SqlConnection con = new SqlConnection(_ConnectionString.Value.ConnectionString))
            {
                con.Open();
                SqlTransaction sqltrans = con.BeginTransaction();
                var            param    = new DynamicParameters();
                param.Add("@Id", UserAllocation.Id);
                param.Add("@UserId", UserAllocation.UserId);
                param.Add("@AllocationId", UserAllocation.AllocationId);
                param.Add("@Comment", UserAllocation.Comment);
                param.Add("@PriorityId", UserAllocation.PriorityId);
                var result = con.Execute("InsertUpdateUserAllocation", param, sqltrans, 0, System.Data.CommandType.StoredProcedure);

                if (result > 0)
                {
                    sqltrans.Commit();
                }
                else
                {
                    sqltrans.Rollback();
                }
                return(result);
            }
        }
Exemple #6
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();
            }
        }
Exemple #7
0
 public IActionResult EditUserAllocation(int id, UserAllocation UserAllocation)
 {
     try
     {
         _IAllocation.UpdateUserAllocation(UserAllocation);
         return(RedirectToAction("UserAllocation"));
     }
     catch
     {
         return(View());
     }
 }
Exemple #8
0
 public IActionResult DeleteUserAllocation(int id, UserAllocation UserAllocation)
 {
     try
     {
         _IAllocation.DeleteUserAllocation(UserAllocation.Id);
         return(RedirectToAction("UserAllocation"));
     }
     catch
     {
         return(View());
     }
 }
Exemple #9
0
        public ActionResult InsertAsync(UserAllocation entity)
        {
            entity.CreatorId   = mLogin.Id.ToString();
            entity.CreatedTime = DateTime.Now;

            //所有AJAX的结果,返回统一数据格式
            var result = new AjaxResult();

            try
            {
                if (UserAccountContract.GetByKey(entity.UaId).UserStare != 2)
                {
                    result.Type    = AjaxResultType.Error;
                    result.Content = "当前账户没有通过或已经被禁用";
                }
                else
                {
                    //判断是否已经存在码被分配
                    var isok = UserAllocationContract.Entities.Where(d => d.IsDeleted == false && ((d.StartNumber <= entity.StartNumber && d.EndNumber >= entity.StartNumber) ||
                                                                                                   (d.StartNumber <= entity.EndNumber && d.EndNumber >= entity.EndNumber) || (d.StartNumber >= entity.StartNumber && d.StartNumber <= entity.EndNumber) ||
                                                                                                   (d.EndNumber >= entity.StartNumber && d.EndNumber <= entity.EndNumber))).Count() > 0;
                    if (isok)
                    {
                        result.Type    = AjaxResultType.Error;
                        result.Content = "您输入的码已经被分配";
                    }
                    else
                    {
                        var count = UserAllocationContract.Insert(entity);
                        if (count > 0)
                        {
                            result.Type    = AjaxResultType.Success;
                            result.Content = "录入成功";
                        }
                        else
                        {
                            result.Type    = AjaxResultType.Error;
                            result.Content = "录入失败";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.Type    = AjaxResultType.Error;
                result.Content = "异常操作";
            }
            return(JsonEx(result));
        }
        private void DeActiveUserGroupAllocation(UserAllocation req)
        {
            var allocation = userAllocationManagement.GetUserAllocationByGroupNumber(req.GroupNumber);

            foreach (var allocate in allocation)
            {
                allocate.IsActive   = false;
                allocate.ModifiedBy = new Guid(User.Identity.GetUserId());
                allocate.Status     = RequestStatus.Rejected;
                allocate.Comments   = req.Comments;
                userAllocationManagement.Update(allocate);
            }

            SendUserAllocationEmailsToRequestCreator(req.GroupNumber, RequestStatus.Rejected, req.Comments);
        }
        private void UpdateRequisitionStatus(UserAllocation req, string type)
        {
            var requisition = requisitionManagement.GetRequisition(Convert.ToInt64(req.RequisitionID));

            if (req.User == null && req.RequisitionID.HasValue && type == RequestStatus.Approved)
            {
                var allocation         = userAllocationManagement.GetUserAllocationsByRequisition(Convert.ToInt64(req.RequisitionID));
                var deActiveAllocation = allocation.Where(x => !x.IsActive).ToList();

                if (deActiveAllocation != null && deActiveAllocation.Count == 0)
                {
                    requisition.Status = RequisitionStatus.Level1_Approved;
                    requisitionManagement.Update(requisition);
                    requisitionManagement.SaveRequisition();


                    foreach (var allocate in allocation)
                    {
                        allocate.IsActive   = true;
                        allocate.Status     = RequestStatus.Approved;
                        allocate.ModifiedBy = new Guid(User.Identity.GetUserId());
                        userAllocationManagement.Update(allocate);
                    }
                    userAllocationManagement.SaveUserAllocation();

                    RequisitionStatusEmailToUser(Convert.ToInt64(req.RequisitionID), RequisitionStatus.Level1_Approved, req.Comments);
                    SendRequisitionEmailsToLevel2Department(Convert.ToInt64(req.RequisitionID));
                }
            }
            else if (req.User == null && req.RequisitionID.HasValue)
            {
                requisition.Status = RequisitionStatus.Level1_Rejected;
                requisitionManagement.Update(requisition);
                requisitionManagement.SaveRequisition();

                var allocation = userAllocationManagement.GetUserAllocationsByRequisition(Convert.ToInt64(req.RequisitionID));
                foreach (var allocate in allocation)
                {
                    allocate.IsActive   = false;
                    allocate.Status     = RequestStatus.Rejected;
                    allocate.ModifiedBy = new Guid(User.Identity.GetUserId());
                    userAllocationManagement.Update(allocate);
                }
                userAllocationManagement.SaveUserAllocation();

                RequisitionStatusEmailToUser(Convert.ToInt64(req.RequisitionID), RequisitionStatus.Level1_Rejected, req.Comments);
            }
        }
Exemple #12
0
        /// <summary>
        /// 修改信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public ActionResult EditAsync(UserAllocation entity)
        {
            var result = new AjaxResult();

            try
            {
                //判断是否已经存在码被分配
                var isok = UserAllocationContract.Entities.Where(d => d.IsDeleted == false && d.Id != entity.Id && ((d.StartNumber <= entity.StartNumber && d.EndNumber >= entity.StartNumber) ||
                                                                                                                    (d.StartNumber <= entity.EndNumber && d.EndNumber >= entity.EndNumber) || (d.StartNumber >= entity.StartNumber && d.StartNumber <= entity.EndNumber) ||
                                                                                                                    (d.EndNumber >= entity.StartNumber && d.EndNumber <= entity.EndNumber))).Count() > 0;

                if (isok)
                {
                    result.Type    = AjaxResultType.Error;
                    result.Content = "您输入的码已经被分配";
                }
                else
                {
                    var count = UserAllocationContract.UpdateDirect(d => d.Id == entity.Id, d =>
                                                                    new UserAllocation
                    {
                        UaId            = entity.UaId,
                        AllocationStare = entity.AllocationStare,
                        StartNumber     = entity.StartNumber,
                        EndNumber       = entity.EndNumber,
                        NumCount        = entity.NumCount
                    });
                    if (count > 0)
                    {
                        result.Type    = AjaxResultType.Success;
                        result.Content = "修改成功";
                    }
                    else
                    {
                        result.Type    = AjaxResultType.Error;
                        result.Content = "修改失败";
                    }
                }
            }
            catch
            {
                result.Type    = AjaxResultType.Error;
                result.Content = "异常操作";
            }
            return(JsonEx(result));
        }
Exemple #13
0
        public IActionResult CreateUserAllocation(UserAllocation UserAllocation)
        {
            try
            {
                // TODO: Add insert logic here

                if (ModelState.IsValid)
                {
                    UserAllocation.Id = 0;
                    _IAllocation.InsertUserAllocation(UserAllocation);
                    return(RedirectToAction("UserAllocation", new { UserId = UserAllocation.UserId }));
                }
                return(View(UserAllocation));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
 /// <summary>
 /// 更新实体对象
 /// </summary>
 /// <param name="entity">更新后的实体对象</param>
 /// <returns>操作影响的行数</returns>
 public int Update(UserAllocation entity)
 {
     return(Repository.Update(entity));
 }
Exemple #15
0
 public bool Update(UserAllocation model)
 {
     return(userAllocationRepository.Update(model));
 }
Exemple #16
0
 public bool Delete(UserAllocation model)
 {
     return(userAllocationRepository.Delete(model));
 }
Exemple #17
0
 public bool Add(UserAllocation model)
 {
     return(userAllocationRepository.Add(model));
 }
 /// <summary>
 /// 删除实体
 /// </summary>
 /// <param name="entity">实体对象</param>
 /// <returns>操作影响的行数</returns>
 public int Delete(UserAllocation entity)
 {
     return(Repository.Delete(entity));
 }
 /// <summary>
 /// 插入实体
 /// </summary>
 /// <param name="entity">实体对象</param>
 /// <returns>操作影响的行数</returns>
 public int Insert(UserAllocation entity)
 {
     return(Repository.Insert(entity));
 }
 /// <summary>
 /// 异步更新实体对象
 /// </summary>
 /// <param name="entity">更新后的实体对象</param>
 /// <returns>操作影响的行数</returns>
 public Task <int> UpdateAsync(UserAllocation entity)
 {
     return(Repository.UpdateAsync(entity));
 }
 /// <summary>
 /// 异步插入实体
 /// </summary>
 /// <param name="entity">实体对象</param>
 /// <returns>操作影响的行数</returns>
 public Task <int> InsertAsync(UserAllocation entity)
 {
     return(Repository.InsertAsync(entity));
 }
        public JsonResult Operation(string id_type, string comments)
        {
            try
            {
                var values = id_type.Split('_');
                logger.DebugFormat(" User Allocation updated with  With ID [{0}] and action [{1}] ", values[0], values[1]);

                if (!PermissionControl.CheckPermission(UserAppPermissions.UserAllocation_Approve_Reject))
                {
                    logger.Info("Don't have right to Approve/Reject User Allocation record");
                    return(Json(new { Message = Resources.Messages.MSG_RESTRICTED_ACCESS, MessageClass = MessageClass.Error, Response = false }));
                }

                UserAllocation req = userAllocationManagement.GetUserAllocation(Convert.ToInt64(values[0]));
                if (req == null)
                {
                    return(Json(new { Message = "User Allocation not found", MessageClass = MessageClass.Error, Response = false }));
                }

                string selectedType = Convert.ToInt32(values[1]) == 1 ? RequestStatus.Approved : RequestStatus.Rejected;
                if (req.UserID != null && selectedType == RequestStatus.Rejected) // If user is not null and operation is rejected
                {
                    req.Comments = comments;
                    DeActiveUserGroupAllocation(req);
                }
                if (selectedType == RequestStatus.Approved)
                {
                    req.IsActive = true;
                    req.Status   = RequestStatus.PartialApproved;
                }
                else
                {
                    req.IsActive = true;
                    req.Status   = RequestStatus.Rejected;
                }

                req.ModifiedBy = new Guid(User.Identity.GetUserId());
                req.Comments   = comments;


                if (userAllocationManagement.Update(req))
                {
                    userAllocationManagement.SaveUserAllocation();
                    logger.InfoFormat("User Allocation record Successfully {0}", selectedType);

                    if (req.RequisitionID.HasValue)
                    {
                        UpdateRequisitionStatus(req, selectedType);
                    }

                    if (req.UserID != null && selectedType == RequestStatus.Approved) // If user is not null and operation is Approved
                    {
                        DeActivatedPreviousAllocation(req, selectedType);
                    }
                    string msg = string.Format("User Allocation record Successfully {0}", selectedType);
                    return(Json(new { Message = msg, MessageClass = MessageClass.Success, Response = true }));
                }
                else
                {
                    string msg = string.Format("User Allocation record not {0}", selectedType);
                    logger.InfoFormat("User Allocation record not {0}", selectedType);
                    return(Json(new { Message = msg, 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_DELETE_FAILED, MessageClass = MessageClass.Error, Response = false }));
            }
        }
        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 }));
            }
        }