public ResultHelper AddUserDepartment(UserDepartmentDto userDepartmentDto)
        {
            try
            {
                if (IsThere(userDepartmentDto))
                {
                    return(new ResultHelper(false, 0, ResultHelper.UnSuccessMessage));
                }
                userdepartment item = new userdepartment();
                item.UserID           = userDepartmentDto.UserID;
                item.UserDepartmentID = userDepartmentDto.UserDepartmentID;
                item.DepartmentID     = userDepartmentDto.DepartmentID;

                using (UnitOfWork unitofWork = new UnitOfWork())
                {
                    unitofWork.GetRepository <userdepartment>().Insert(item);
                    unitofWork.saveChanges();
                    return(new ResultHelper(true, item.UserDepartmentID, ResultHelper.SuccessMessage));
                }
            }
            catch (Exception ex)
            {
                return(new ResultHelper(false, 0, ResultHelper.UnSuccessMessage + "\n" + ResultHelper.IsThereItem));
            }
        }
Beispiel #2
0
        public List <UserDto> GetAllUser()
        {
            try
            {
                List <UserDto> list = new List <UserDto>();
                using (UnitOfWork unitofWork = new UnitOfWork())
                {
                    List <user> collection = unitofWork.GetRepository <user>().Select(null, null).ToList();
                    foreach (var item in collection)
                    {
                        UserDto user = new UserDto();
                        user.UserID      = item.UserID;
                        user.Name        = item.Name;
                        user.SurName     = item.SurName;
                        user.FullName    = item.Name + " " + item.SurName;
                        user.Gender      = item.Gender;
                        user.NationID    = item.NationID;
                        user.UserTitleID = (int)item.UserTitleID;

                        var          userTitle    = unitofWork.GetRepository <usertitle>().GetById(model => model.UserTitleID == item.UserTitleID);
                        UserTitleDto userTitleDto = new UserTitleDto();
                        userTitleDto.UserTitleId = item.UserTitleID.Value;
                        userTitleDto.TitleName   = userTitle.TitleName;
                        user.UserTitleDto        = userTitleDto;

                        var depUser = unitofWork.GetRepository <userdepartment>().GetById(model => model.UserID == user.UserID);
                        UserDepartmentDto userDepartmentDto = new UserDepartmentDto();
                        userDepartmentDto.UserDepartmentID = depUser.DepartmentID.Value;
                        userDepartmentDto.UserID           = item.UserID;
                        userDepartmentDto.UserDepartmentID = depUser.UserDepartmentID;
                        userDepartmentDto.UserDepartmentID = depUser.DepartmentID.Value;
                        user.UserDepartmentDto             = userDepartmentDto;

                        var           department    = unitofWork.GetRepository <department>().GetById(model => model.DepartmentID == depUser.DepartmentID);
                        DepartmentDto departmentDto = new DepartmentDto();
                        departmentDto.DepartmentID = department.DepartmentID;
                        departmentDto.Name         = department.Name;
                        user.DepartmentDto         = departmentDto;

                        var             password        = unitofWork.GetRepository <userpassword>().GetById(x => x.UserID == user.UserID);
                        UserPasswordDto userPasswordDto = new UserPasswordDto();
                        userPasswordDto.UserPasswordID = password.UserPasswordID;
                        userPasswordDto.Password       = password.Password;
                        user.UserPasswordDto           = userPasswordDto;
                        list.Add(user);
                    }
                    return(list);
                }
            }
            catch (Exception ex)
            {
                return(new List <UserDto>());
            }
        }
        public bool IsThere(UserDepartmentDto userDepartmentDto)
        {
            int userID = userDepartmentDto.UserID;
            int depID  = userDepartmentDto.DepartmentID;

            using (UnitOfWork unitofWork = new UnitOfWork())
            {
                var item = unitofWork.GetRepository <userdepartment>().GetById(x => x.DepartmentID == depID && x.UserID == userID);
                if (item != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
        public UserDepartmentDto GetUserDepartment(int UserDepartmentID)
        {
            try
            {
                using (UnitOfWork unitofWork = new UnitOfWork())
                {
                    userdepartment item = new userdepartment();
                    item = unitofWork.GetRepository <userdepartment>().GetById(x => x.UserDepartmentID == UserDepartmentID);
                    UserDepartmentDto userDepartmentDto = new UserDepartmentDto();
                    item.UserID           = userDepartmentDto.UserID;
                    item.UserDepartmentID = userDepartmentDto.UserDepartmentID;
                    item.DepartmentID     = userDepartmentDto.DepartmentID;

                    return(userDepartmentDto);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
        public ResultHelper SetUserDepartment(UserDepartmentDto userDepartmentDto)
        {
            try
            {
                userdepartment item = new userdepartment();
                item.UserID           = userDepartmentDto.UserID;
                item.UserDepartmentID = userDepartmentDto.UserDepartmentID;
                item.DepartmentID     = userDepartmentDto.DepartmentID;

                using (UnitOfWork unitofWork = new UnitOfWork())
                {
                    unitofWork.GetRepository <userdepartment>().Update(item);
                    unitofWork.saveChanges();
                    return(new ResultHelper(true, item.UserDepartmentID, ResultHelper.SuccessMessage));
                }
            }
            catch (Exception)
            {
                return(new ResultHelper(false, userDepartmentDto.UserID, ResultHelper.UnSuccessMessage));
            }
        }
        private async Task <UserDepartmentDto> GetDefaultUserDepartmentAsync(Guid userId)
        {
            var userDepartmentDtos = await _userDepartmentServices.GetCachedUserDepartmentDtos();

            var userDepartmentDto = userDepartmentDtos
                                    .OrderBy(ud => ud.DeptIndex)
                                    .ThenBy(ud => ud.DeptOrderNumber)
                                    .FirstOrDefault(ud => ud.UserID == userId);

            if (userDepartmentDto == null)
            {
                var userDto = _userServices.GetById(userId);
                if (userDto != null)
                {
                    userDepartmentDto = new UserDepartmentDto()
                    {
                        UserID   = userDto.Id,
                        UserName = userDto.UserName,
                        FullName = userDto.FullName,
                    };
                }
            }
            return(userDepartmentDto);
        }
Beispiel #7
0
 public string SetUserDepartment(UserDepartmentDto userDepartmentDto)
 {
     return(JsonConvert.SerializeObject(userDepartmentLogic.SetUserDepartment(userDepartmentDto)));
 }