Beispiel #1
0
        public async Task <ActionResult <Response> > EditProfile(ProfileReq input)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var result = await _profileDataService.EditProfileByIdAsync(this.User.Identity.Name, input);

                    return(Created("", new Response
                    {
                        Success = true,
                        Data = new ResponseData
                        {
                            ProfileModels = new List <ProfileDto> {
                                result
                            },
                            OfficeModels = new List <OfficeDto> {
                                await _officeDataService.GetOfficeContainingProfileIdAsync(result.Id)
                            }
                        }
                    }));
                }
                catch (Exception e)
                {
                    return(BadRequest(new Response {
                        Success = false, ErrorMessage = e.Message
                    }));
                }
            }
            return(BadRequest(new Response {
                Success = false, ErrorMessage = ModelState.Values.ToString()
            }));
        }
        /// <summary>
        /// Signs in a user with some parameters such as <paramref name="userName"/>, <paramref name="password"/>, <paramref name="name"/> and <paramref name="surname"/>
        /// </summary>
        /// <param name="name"></param>
        /// <param name="surname"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task <ProfileResp> SignUpAsync(string name, string surname, string userName, SecureString password)
        {
            // get token using an admin user
            var token = await GetToken();

            GlobalSettings.AccessToken = token.access_token;

            // create new user
            var user = new ProfileReq {
                accountEnabled    = true,
                givenName         = name,
                surname           = surname,
                displayName       = name + " " + surname,
                mailNickname      = name,
                userPrincipalName = userName,
                passwordProfile   = new Models.PasswordProfile {
                    forceChangePasswordNextSignIn = false, password = new NetworkCredential(string.Empty, password).Password
                }
            };
            var newUser = await restPoolService.ProfilesAPI.CreateUserAsync(user);

            if (newUser.userPrincipalName == null)
            {
                throw new InvalidOperationException(Localization.Resources.Snack_Message_Profile_NoProfileCreated);
            }
            authenticatedUser = newUser.displayName;
            return(newUser);
        }
        public async Task <ProfileDto> EditProfileByIdAsync(string ownerId, ProfileReq input)
        {
            try
            {
                var existingProfile = await _dbContext.ProfileModels.Include(x => x.Competences)
                                      .Include(x => x.ImageModel)
                                      .Include(x => x.ProjectProfileRoles).ThenInclude(x => x.ProjectModel).ThenInclude(x => x.TimePeriod)
                                      .Include(x => x.ProjectProfileRoles).ThenInclude(x => x.ProjectModel).ThenInclude(x => x.Techniques)
                                      .FirstOrDefaultAsync(x => x.OwnerID == ownerId);

                if (input.OfficeModelId != 0)
                {
                    _dbContext.Entry(existingProfile).Property("OfficeModelId").CurrentValue = input.OfficeModelId;
                }

                existingProfile.AboutMe     = input.AboutMe;
                existingProfile.FirstName   = input.FirstName;
                existingProfile.LastName    = input.LastName;
                existingProfile.Position    = input.Position;
                existingProfile.LinkedInUrl = input.LinkedInUrl;
                existingProfile.ResumeUrl   = input.ResumeUrl;
                existingProfile.Modified    = DateTime.UtcNow;
                foreach (var competence in input.Competences)
                {
                    var existingCompetence = existingProfile.Competences.FirstOrDefault(c => c.Id == competence.Id);
                    if (existingCompetence == null)
                    {
                        existingProfile.Competences.Add(competence);
                    }
                    else
                    {
                        _dbContext.Entry(existingCompetence).CurrentValues.SetValues(competence);
                    }
                }

                foreach (var competence in existingProfile.Competences)
                {
                    if (!input.Competences.Any(c => c.Id == competence.Id))
                    {
                        _dbContext.Remove(competence);
                    }
                }
                _dbContext.Update(existingProfile);
                await _dbContext.SaveChangesAsync();

                return(_mapper.Map <ProfileModel, ProfileDto>(existingProfile));
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates a user using a <paramref name="profile"/> as parameter.
        /// </summary>
        /// <param name="profile"></param>
        /// <returns></returns>
        public async Task <ProfileResp> CreateUserAsync(ProfileReq profile)
        {
            var client = new RestClient("https://graph.microsoft.com/v1.0/users/");

            client.Timeout = -1;
            var jsonData = JsonHelper.FromClass(profile);

            var request = new RestRequest(Method.POST);

            request
            .AddHeader("Authorization", "Bearer " + GlobalSettings.AccessToken)
            .AddHeader("Content", "application/json")
            .AddHeader("Content-Type", "application/json")
            .AddParameter("application/json", jsonData, ParameterType.RequestBody);
            IRestResponse response = await client.ExecuteAsync(request);

            var profileResponse = JsonHelper.ToClass <ProfileResp>(response.Content);

            return(profileResponse);
        }
        public IHttpActionResult PostProfRequirements(ProfileReq data)
        {
            try
            {
                if (data.req.EduArr != null)
                {
                    var obj = new tEducationalBackground();
                    foreach (var a in data.req.EduArr)
                    {
                        obj.School      = a.School;
                        obj.Course      = a.Course;
                        obj.Address     = a.Address;
                        obj.DateStared  = a.DateStared;
                        obj.DateEnded   = a.DateEnded;
                        obj.DateCreated = DateTime.Now;
                        obj.Status      = 0;
                        obj.PersonId    = data.req.globalID;
                        db.tEducationalBackgrounds.Add(obj);
                        db.SaveChanges();
                    }
                }


                if (data.req.EmpArr != null)
                {
                    var obj2 = new tEmploymentHistory();
                    foreach (var a in data.req.EmpArr)
                    {
                        obj2.CompanyName    = a.CompanyName;
                        obj2.CompanyAddress = a.CompanyAddress;
                        obj2.Position       = a.Position;
                        obj2.StartedDate    = a.StartedDate;
                        obj2.EndedDate      = a.EndedDate;
                        obj2.DateCreated    = DateTime.Now;
                        obj2.PersonId       = data.req.globalID;
                        obj2.Status         = 0;
                        db.tEmploymentHistories.Add(obj2);
                        db.SaveChanges();
                    }
                }


                if (data.req.TrainArr != null)
                {
                    var obj3 = new tTraining();
                    foreach (var a in data.req.TrainArr)
                    {
                        obj3.TrainingTitle = a.TrainingTitle;
                        obj3.TrainingVenue = a.TrainingVenue;
                        obj3.Description   = a.Description;
                        obj3.PersonId      = data.req.globalID;
                        obj3.Date          = a.Date;
                        obj3.DateCreated   = DateTime.Now;
                        obj3.Status        = 0;
                        db.tTrainings.Add(obj3);
                        db.SaveChanges();
                    }
                }

                if (data.profTempArr != null)
                {
                    byte[] bitimage = Convert.FromBase64String(data.req.img.ToString());
                    data.profTempArr.ProfileImg  = bitimage;
                    data.profTempArr.PersonId    = Guid.NewGuid().ToString("N").Substring(0, 5).ToUpper();
                    data.profTempArr.DateCreated = DateTime.Now;
                    data.profTempArr.Status      = 0;
                    data.profTempArr.UserId      = data.req.globalID;
                    db.tPersonInfoes.Add(data.profTempArr);
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                return(Json(e.Message));
            }
            return(Json(data));
        }