Пример #1
0
        public ActionResult AddDepartmentAllocation()
        {
            UserAllocation userDepartment = new UserAllocation();

            userDepartment.Departments = departmentManagement.GetAllDepartments();
            return(PartialView("_UserAllocatedDepartment", userDepartment));
        }
        public ActionResult View(string userId, long groupNumber)
        {
            ViewBag.Title     = "Add/Update User Allocation";
            ViewBag.IsAddEdit = false;

            if (!PermissionControl.CheckPermission(UserAppPermissions.UserAllocation_Add) && !PermissionControl.CheckPermission(UserAppPermissions.UserAllocation_Edit))
            {
                logger.Info("Don't have rights to add new Requisition");
                return(Json(new { Message = Resources.Messages.MSG_RESTRICTED_ACCESS, MessageClass = MessageClass.Error, Response = false }));
            }
            var AdminUser = RoleManager.Roles.Where(x => x.Name.Equals(UserRoles.Admin)).SingleOrDefault();
            var userList  = UserManager.Users.Where(x => !x.IsDeleted && !(x.Roles.Select(y => y.RoleId).Contains(AdminUser.Id))).ToList();

            UserReAllocationVM allocationVM = new UserReAllocationVM();

            allocationVM.UserList = userList;
            allocationVM.UserId   = userId;

            var userAllocatedDepartments = userAllocationManagement.GetUserAllocationByGroupNumber(groupNumber);

            if (userAllocatedDepartments != null && userAllocatedDepartments.Count() > 0)
            {
                var departments = departmentManagement.GetAllDepartments();
                foreach (var userDept in userAllocatedDepartments)
                {
                    userDept.Departments = departments;
                }
                allocationVM.UserAllocatedDepartments = userAllocatedDepartments;
            }

            return(PartialView("_AddUpdateAllocation", allocationVM));
        }
Пример #3
0
        public ActionResult AddEdit(string id)
        {
            ViewBag.Title = "Add/Update Users";

            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>());
            var departments = departmentManagement.GetAllDepartments();
            var requisition = requisitionManagement.GetAllApprovedRequisition();
            var roles       = RoleManager.Roles.Where(x => !x.Name.Equals("Admin")).ToList().Select(x => new Core.ViewModel.SelectListItem()
            {
                Text  = x.Name,
                Value = x.Id
            });

            var user = new UserVM();

            user.RequisitionList = requisition;
            if (id != "0")
            {
                var appUser   = UserManager.FindById(id);
                var userRoles = UserManager.GetRoles(id);
                IEnumerable <UserDepartment> userDepartments = userdepartmentManagement.GetAllUserDepartmentById(appUser.Id);

                user.Id              = appUser.Id;
                user.FirstName       = appUser.FirstName;
                user.LastName        = appUser.LastName;
                user.Email           = appUser.Email;
                user.EmployeeNumber  = appUser.EmployeeNumber;
                user.Mobile          = appUser.Mobile;
                user.Designation     = appUser.Designation;
                user.UserPermissions = GetUserPermission(id);
                user.RequisitionID   = appUser.RequisitionID;
                if (userDepartments != null)
                {
                    foreach (var userDept in userDepartments)
                    {
                        userDept.Departments = departments;
                        userDept.RolesList   = roles;
                    }
                    user.UserDepartments = userDepartments;
                }
            }


            return(PartialView("_AddEditUser", user));
        }
        private ExcelFileProcess ProcessExpenseSheet(string path, string fileName, DateTime expenseDate)
        {
            logger.DebugFormat("Processing User Expense Sheet Name [{0}]", fileName);

            DataSet   ds    = ExcelFileReader.Read(path);
            DataTable table = ds.Tables[0];

            table = table.Rows.Cast <DataRow>().Where(row => !row.ItemArray.All(field => field is System.DBNull || string.Compare((Convert.ToString(field)).Trim(), string.Empty) == 0)).CopyToDataTable();
            if (table.Rows.Count == 0)
            {
                logger.DebugFormat("No rows found in file [{0}]", fileName);

                return(new ExcelFileProcess {
                    Message = "No rows to insert.", Response = false, MessageType = MessageClass.Error
                });
            }

            string missingcolumn = ExcelFileReader.CheckAllColumnExist(table, ColumnList);

            if (!string.IsNullOrWhiteSpace(missingcolumn))
            {
                logger.Debug(string.Format(Resources.Messages.MSG_GENERIC_COLUMN_MISSING, missingcolumn));

                return(new ExcelFileProcess {
                    Message = string.Format(Resources.Messages.MSG_GENERIC_COLUMN_MISSING, missingcolumn), Response = false, MessageType = MessageClass.Error
                });
            }

            string info = ExcelFileReader.ValidateData(table, MandatoryColumnList);

            if (!string.IsNullOrWhiteSpace(info))
            {
                logger.Debug(info);
                return(new ExcelFileProcess {
                    Message = info, Response = false, MessageType = MessageClass.Error
                });
            }

            string errors = ExcelFileReader.ValidateAmount(table, ValidateColumnList);

            if (!string.IsNullOrWhiteSpace(errors))
            {
                logger.Debug(errors);
                return(new ExcelFileProcess {
                    Message = errors, Response = false, MessageType = MessageClass.Error
                });
            }

            var department = departmentManagement.GetAllDepartments();
            var allocation = userAllocationManagement.GetAllUsersActiveAllocations();
            var users      = UserManager.Users.Where(x => !x.IsDeleted).ToList();

            errors = ExcelFileReader.ValidateDepartmentAndUsersAndAllocation(table, department, users, allocation);
            if (!string.IsNullOrWhiteSpace(errors))
            {
                logger.Debug(errors);
                return(new ExcelFileProcess {
                    Message = errors, Response = false, MessageType = MessageClass.Error
                });
            }

            ExcelFileProcess process = InsertData(table, fileName, users, expenseDate, allocation);

            return(process);
        }