public IHttpActionResult UpdateLink(string type, CUSTOM_PROFILE path) { // Verify Input if (!ModelState.IsValid) { string errors = ""; foreach (var modelstate in ModelState.Values) { foreach (var error in modelstate.Errors) { errors += "|" + error.ErrorMessage + "|" + error.Exception; } } throw new BadInputException() { ExceptionMessage = errors }; } var authenticatedUser = this.ActionContext.RequestContext.Principal as ClaimsPrincipal; var username = authenticatedUser.Claims.FirstOrDefault(x => x.Type == "user_name").Value; _profileService.UpdateProfileLink(username, type, path); return(Ok()); }
/// <summary> /// Sets the path for the profile links. /// </summary> /// <param name="username">The username</param> /// <param name="type"></param> /// <param name="path"></param> public void UpdateProfileLink(string username, string type, CUSTOM_PROFILE path) { var original = _unitOfWork.ProfileCustomRepository.GetByUsername(username); if (original == null) { var nameParam = new SqlParameter("@USERNAME", username); var fParam = new SqlParameter("@FACEBOOK", DBNull.Value); var tParam = new SqlParameter("@TWITTER", DBNull.Value); var iParam = new SqlParameter("@INSTAGRAM", DBNull.Value); var lParam = new SqlParameter("@LINKEDIN", DBNull.Value); var hParam = new SqlParameter("@HANDSHAKE", DBNull.Value); var context = new CCTEntities1(); context.Database.ExecuteSqlCommand("CREATE_SOCIAL_LINKS @USERNAME, @FACEBOOK, @TWITTER, @INSTAGRAM, @LINKEDIN, @HANDSHAKE", nameParam, fParam, tParam, iParam, lParam, hParam); //run stored procedure to create a row in the database for this user. original = _unitOfWork.ProfileCustomRepository.GetByUsername(username); } switch (type) { case "facebook": original.facebook = path.facebook; break; case "twitter": original.twitter = path.twitter; break; case "instagram": original.instagram = path.instagram; break; case "linkedin": original.linkedin = path.linkedin; break; case "handshake": original.handshake = path.handshake; break; } _unitOfWork.Save(); }