Ejemplo n.º 1
0
        private KeyValuePair <DateTime, DateTime> GetValidationPeriod(int userId, int departmentId)
        {
            UserDepartment userDepartment = _userDepartmentRepository.FindByUserId(userId).Where(ud => ud.DepartmentId == departmentId).SingleOrDefault();

            if (userDepartment == null)
            {
                User user = _userRepository.FindById(userId);

                foreach (UserRole ur in user.UserRoles)
                {
                    if (ur.Role.RoleTypeId == (int)FixedRoleType.DepartmentManager && !ur.IsDeleted && ur.ValidFrom < DateTime.Now && ur.ValidTo > DateTime.Now.AddDays(1))
                    {
                        return(new KeyValuePair <DateTime, DateTime>(ur.ValidFrom, ur.ValidTo));
                    }
                }
            }
            return(new KeyValuePair <DateTime, DateTime>(userDepartment.ValidFrom, userDepartment.ValidTo));
        }
Ejemplo n.º 2
0
        public void DeleteUserDepartment(int Id, int departmentId)
        {
            using (IUnitOfWork work = UnitOfWork.Begin())
            {
                UserDepartment userDepartment = _userDepartmentRepository.FindByUserId(Id).Where(ud => ud.DepartmentId == departmentId).Single();

                userDepartment.IsDeleted = true;

                var message = new XElement(XMLLogLiterals.LOG_MESSAGE);
                message.Add(XMLLogMessageHelper.TemplateToXml("LogMessageUserRemovedFromDepartment", new List <string> {
                    userDepartment.User.LoginName,
                    userDepartment.Department.Name
                }));

                work.Commit();

                _logService.CreateLog(CurrentUser.Get().Id, "web", flag, CurrentUser.Get().HostName, CurrentUser.Get().CompanyId,
                                      message.ToString());
            }
        }