コード例 #1
0
        public async Task <IActionResult> RegisterAgent(RegisterationModelForAgents registerationModelForAgents)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (await CheckIfUserExist(registerationModelForAgents.UserSecurity))
            {
                return(BadRequest());
            }

            var JobInDb = jobManager.
                          GetFirstOrDefaultByParam(j => j.Name == registerationModelForAgents.JobInfo.Name);

            if (JobInDb == null)
            {
                return(BadRequest());
            }

            //Get Skills from Database
            IEnumerable <Skill> skillsInDb = skillManager.GetAll().Where(s => registerationModelForAgents.Skills.ToList().Select(a => a.Name).Contains(s.Name));

            if (skillsInDb == null)
            {
                return(BadRequest());
            }

            agentManager.Add(registerationModelForAgents.AgentInfo);

            registerationModelForAgents.AgentInfo.Job = JobInDb;

            string id = await AddUserToAspNetUsers(registerationModelForAgents.UserSecurity, registerationModelForAgents.AgentInfo, "worker");

            if (id != null)
            {
                registerationModelForAgents.AgentInfo.AspNetUsersId = id;

                AddAgentSkills(skillsInDb, registerationModelForAgents.AgentInfo);

                string imagePath = UploadToCloudinary.UploadImageToCloudinary(registerationModelForAgents.AgentInfo.ImagePath);

                if (imagePath != null)
                {
                    registerationModelForAgents.AgentInfo.ImagePath = imagePath;
                    dbContextUser.Complete();
                    return(Ok());
                }
            }

            return(BadRequest());
        }
コード例 #2
0
        public async Task <IActionResult> EditAgentProfile(string userName, EditAgent editedAgent)
        {
            if (userName == null || !ModelState.IsValid)
            {
                return(BadRequest());
            }

            var userInaspNetTable = await aspUserManager.FindByNameAsync(userName);

            var agent = agentManager
                        .GetAllWithInclude(a => a.Job, a => a.AspNetUsersId == userInaspNetTable.Id).FirstOrDefault();

            if (agent.ImagePath != editedAgent.EditAgentInfo.ImagePath)
            {
                editedAgent.EditAgentInfo.ImagePath = UploadToCloudinary.UploadImageToCloudinary(editedAgent.EditAgentInfo.ImagePath);
            }

            mapper.Map(editedAgent.EditAgentInfo, agent);

            var agentEditedSkills = skillManager
                                    .GetAll()
                                    .Where(s => editedAgent.EditSkills.ToList().Select(a => a.Name).Contains(s.Name))
                                    .Select(s => s.Id)
                                    .ToList();

            var agentSkillsInDb = agentSkillManager
                                  .GetAll()
                                  .Where(s => s.AgentId == agent.Id)
                                  .ToList();


            UpdateAgentSkills(agentEditedSkills, agentSkillsInDb);


            agentManager.Complete();

            return(Ok());
        }
コード例 #3
0
 public IActionResult GetSkills()
 {
     return(Ok(skillManager.GetAll().Select(_mapper.Map <Skill, SkillsDto>)));
 }