Exemplo n.º 1
0
        public async Task <ResponseEntity> getUser(string keyword = "")
        {
            IEnumerable <UserJira> entity  = _useJiraRepository.GetAllAsync().Result;
            List <Member>          members = new List <Member>();

            if (entity.Count() != 0)
            {
                keyword = FuncUtilities.BestLower(keyword);
                List <UserJira> lstTimTheoTen = entity.Where(n => n.alias.Contains(keyword)).ToList();

                List <UserJira> lstTimTheoSdt = entity.Where(n => n.phoneNumber.Contains(keyword)).ToList();

                List <UserJira> lstTimTheoEmail = entity.Where(n => n.email.Contains(keyword)).ToList();

                List <UserJira> lstTimTheoMa = entity.Where(n => n.id.ToString().Contains(keyword)).ToList();

                IEnumerable <UserJira> result = new List <UserJira>();
                result = result.Union(lstTimTheoTen);
                result = result.Union(lstTimTheoSdt);
                result = result.Union(lstTimTheoEmail);
                result = result.Union(lstTimTheoMa);



                foreach (UserJira item in result)
                {
                    Member mem = new Member();

                    mem.userId      = item.id;
                    mem.name        = item.name;
                    mem.avatar      = item.avatar;
                    mem.phoneNumber = item.phoneNumber;
                    mem.email       = item.email;

                    members.Add(mem);
                }
                return(new ResponseEntity(StatusCodeConstants.OK, members, MessageConstants.MESSAGE_SUCCESS_200));
            }
            return(new ResponseEntity(StatusCodeConstants.OK, members, MessageConstants.MESSAGE_SUCCESS_200));
        }
        public async Task <ResponseEntity> createProject(ProjectInsert model, string token = "")
        {
            string alias = FuncUtilities.BestLower(model.projectName.Trim());

            var project = await _projectRepository.GetSingleByConditionAsync("alias", alias);


            if (project != null)
            {
                return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Project name already exists", MessageConstants.MESSAGE_ERROR_500));
            }
            var projectCate = _projectCategoryRepository.GetSingleByConditionAsync("id", model.categoryId).Result;

            if (projectCate == null)
            {
                model.categoryId = 1;
            }
            Project newProject = new Project();

            newProject.alias       = alias;
            newProject.categoryId  = model.categoryId;
            newProject.deleted     = false;
            newProject.description = FuncUtilities.Base64Encode(model.description);
            newProject.projectName = model.projectName;
            if (!string.IsNullOrEmpty(token))
            {
                var user = _userJira.GetSingleByConditionAsync("id", _userService.getUserByToken(token).Result.id).Result;
                newProject.creator = user.id;
            }
            else
            {
                newProject.creator = _userJira.GetAllAsync().Result.First().id;//set mặc định khai admin
            }
            newProject = await _projectRepository.InsertAsync(newProject);

            newProject.description = FuncUtilities.Base64Decode(newProject.description);
            return(new ResponseEntity(StatusCodeConstants.OK, newProject, MessageConstants.MESSAGE_SUCCESS_200));
        }