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());
        }
Ejemplo n.º 2
0
 public void Add(AgentDomainModel agentDomainModel)
 {
     _agentManager.Add(agentDomainModel);
 }