public ProfileDetailsDTO ChangeProfileDetailsDL(int personID) { try { using (var context = new MiniBirdEntities()) { var person = context.Person.Where(p => p.PersonID == personID).First(); var profileDetailsDTO = new ProfileDetailsDTO(); profileDetailsDTO.PersonalDescription = person.PersonalDescription; profileDetailsDTO.WebSiteURL = person.WebSiteURL; if (person.Birthdate.HasValue) { profileDetailsDTO.Birthdate = BirthDatePhrase(person.Birthdate); profileDetailsDTO.Day = person.Birthdate.Value.Day.ToString(); profileDetailsDTO.Month = person.Birthdate.Value.Month.ToString(); profileDetailsDTO.Year = person.Birthdate.Value.Year.ToString(); } return(profileDetailsDTO); } } catch { throw; } }
public ProfileDetailsDTO ChangeProfileDetailsDL(ProfileDetailsDTO data, int personID) { try { using (var context = new MiniBirdEntities()) { var person = context.Person.Where(p => p.PersonID == personID).First(); person.PersonalDescription = data.PersonalDescription; person.WebSiteURL = data.WebSiteURL; if (string.IsNullOrWhiteSpace(data.Year) && string.IsNullOrWhiteSpace(data.Month) && string.IsNullOrWhiteSpace(data.Day)) { person.Birthdate = null; data.Birthdate = null; } else { person.Birthdate = new DateTime(Convert.ToInt32(data.Year), Convert.ToInt32(data.Month), Convert.ToInt32(data.Day)); data.Birthdate = BirthDatePhrase(person.Birthdate); } context.SaveChanges(); return(data); } } catch { throw; } }
public HttpResponseMessage GetMembersBySearchWord(string searchWord) { VolunteerMatchDbContext db = new VolunteerMatchDbContext(); try { var usersWIthSearchWord = db.Members.Where(x => x.fullName.Contains(searchWord)).ToList(); List <ProfileDetailsDTO> usersToSend = new List <ProfileDetailsDTO>(); foreach (Member m in usersWIthSearchWord) { ProfileDetailsDTO profileDTO = new ProfileDetailsDTO() { fullName = m.fullName, pictureUrl = m.pictureUrl, memberId = m.id }; usersToSend.Add(profileDTO); } ; return(Request.CreateResponse(HttpStatusCode.OK, usersToSend)); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message)); } }
/// <param name='operations'> /// Reference to the DataExportSales.IProfiles. /// </param> /// <param name='id'> /// Required. Profile Id /// </param> /// <param name='updatedProfile'> /// Required. Description of updates to the Profile /// </param> public static object UpdateProfile(this IProfiles operations, string id, ProfileDetailsDTO updatedProfile) { return(Task.Factory.StartNew((object s) => { return ((IProfiles)s).UpdateProfileAsync(id, updatedProfile); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
public JsonResult EditDetailsForm(ProfileDetailsDTO model) { if (!ModelState.IsValid) { return(Json(new { message = "Fallaron las validaciones" })); } ProfileDetailsDTO newDetails = Account.ChangeProfileDetailsSL(model, ActiveSession.GetPersonID()); return(Json(new { personalDescription = newDetails.PersonalDescription, websiteURL = newDetails.WebSiteURL, birthDate = newDetails.Birthdate })); }
public IHttpActionResult UpdateSetting(ProfileDetailsDTO model) { var user = _unitOfWork.MembersRepository.GetUser(User.Identity.Name); user.AppearInSearch = model.AppearInSearch; user.Status = model.Status; _unitOfWork.Complete(); return(Ok(new ProfileDetailsDTO { AppearInSearch = model.AppearInSearch, Status = model.Status, Image = user.Image })); }
private HttpClient httpClient; // Client to CRM server communication /// <summary> /// Primary method that demonstrates the Data Export Service API. /// </summary> public async Task RunAsync() { //HttpRequestMessage request; //HttpResponseMessage response; string myOrgUrl = "https://crmue.crm.dynamics.com/"; //Dynamics 365 organization URL string myOrgId = "883278f5-07af-45eb-a0bc-3fea67caa544"; //Dynamics 365 organization ID //Call a method just to confirm connection var response = httpClient.GetAsync("WhoAmI", HttpCompletionOption.ResponseHeadersRead).Result; if (response.IsSuccessStatusCode) { //Get the response content and parse it. JObject body = JObject.Parse(response.Content.ReadAsStringAsync().Result); Guid userId = (Guid)body["UserId"]; Console.WriteLine("Your system user ID is: {0}", userId); } else { Console.WriteLine("The WhoAmI request failed with a status of '{0}'", response.ReasonPhrase); } //Use the metadata API to obtain a connector instance to your Dynamics 365 service. DataExportSalesClient discoveryClient = new DataExportSalesClient(); ConnectorDetailResponse connResponse = (ConnectorDetailResponse)discoveryClient. Metadata.GetConnectorDetailsAsync(myOrgUrl, myOrgId).Result; if (connResponse == null) { Console.Write("Failed to obtain a connector instance from the discovery service!"); throw new NullReferenceException("ConnectorDetailResponse is null!"); } //Use the connector to perform profile operations via the profiles API. //First, create another client instance, but now using the discovered connector URL. DataExportSalesClient salesClient = new DataExportSalesClient(new Uri(connResponse.ConnectorUrl)); //Then obtain the collection of sales profiles. Profiles salesProfiles = new Profiles(salesClient); //With this client, can work with an existing Data Export profile. salesProfiles.Activate("SalesExport1"); ProfileDetailsDTO salesProfile1 = (ProfileDetailsDTO)salesProfiles.GetProfileById("SalesExport1"); //Or can create new Data Export profile. ProfileDetailsDTO salesProfile2 = (ProfileDetailsDTO)salesProfiles.CreateProfile(new DataExportSales.Models.ProfileDescriptionBase() { DestinationKeyVaultUri = "https://mykv.vault.azure.net:443/secrets/SampleDataExportSecret/f593bcd8f3b8461584935e0a3e7325dd;", Name = "SalesExport1" //... }); //Test the new profile. object testResult = salesProfiles.GetTestResultById(salesProfile1.Id); //Activate the new profile. salesProfiles.Activate(salesProfile1.Id); }
public HttpResponseMessage GetMyProfile(int id) { VolunteerMatchDbContext db = new VolunteerMatchDbContext(); try { Member member = db.Members.SingleOrDefault(x => x.id == id); int unixDateOfBirth = (int)member.dateOfBirth; DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); dtDateTime = dtDateTime.AddSeconds(unixDateOfBirth).ToLocalTime(); var today = DateTime.Today; // Calculate the age. int age = today.Year - dtDateTime.Year; // Go back to the year in which the person was born in case of a leap year if (dtDateTime.Date > today.AddYears(-age)) { age--; } string dateOfBirth = dtDateTime.ToString(); string dateOfBirthLabel = dateOfBirth.Substring(0, dateOfBirth.IndexOf(" ")); ProfileDetailsDTO profileDetailsDTO = new ProfileDetailsDTO() { pictureUrl = member.pictureUrl, fullName = member.fullName, age = age, city = member.city, occupation = member.occupation, bio = member.biography, gender = member.gender, dateOfBirth = dateOfBirthLabel, hobbies = db.MembersHobbies.Where(h => h.memberId == member.id).Select(z => new HobbiesDTO { name = z.Hobby.name }).ToList() }; var ratings = db.Reviews.Where(x => x.memberId == id).ToList(); double rating = 0; double ratingSum = 0; int numOfRatings = ratings.Count(); if (ratings.Count() > 0) { foreach (var r in ratings) { ratingSum += (int)r.stars; } ; rating = ratingSum / (double)ratings.Count(); rating = Math.Round(rating, 1); profileDetailsDTO.rating = rating; profileDetailsDTO.reviewsCount = ratings.Count(); //CHECK IF GOLD MEMBER if (ratings.Count() >= 5 && rating > 4) { profileDetailsDTO.goldMember = true; } else { profileDetailsDTO.goldMember = false; } } return(Request.CreateResponse(HttpStatusCode.OK, profileDetailsDTO)); /* return Request.CreateResponse(HttpStatusCode.OK, rating);*/ } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public HttpResponseMessage UpdateProfile(ProfileDetailsDTO profileDetailsDTO, int userId) { VolunteerMatchDbContext db = new VolunteerMatchDbContext(); Member member = db.Members.Where(x => x.id == userId).FirstOrDefault(); try { if (profileDetailsDTO.unixDate == null) { member.city = profileDetailsDTO.city; member.biography = profileDetailsDTO.bio; member.occupation = profileDetailsDTO.occupation; member.gender = profileDetailsDTO.gender; member.pictureUrl = profileDetailsDTO.pictureUrl; } else { member.city = profileDetailsDTO.city; member.biography = profileDetailsDTO.bio; member.occupation = profileDetailsDTO.occupation; member.gender = profileDetailsDTO.gender; member.pictureUrl = profileDetailsDTO.pictureUrl; member.dateOfBirth = profileDetailsDTO.unixDate; } if (profileDetailsDTO.hobbies != null) { foreach (MembersHobby hobby in db.MembersHobbies.Where(x => x.memberId == userId)) { MembersHobby membersHobby = hobby; db.MembersHobbies.Remove(membersHobby); } foreach (HobbiesDTO hobby in profileDetailsDTO.hobbies) { MembersHobby hobbies = new MembersHobby(); hobbies.hobbyId = hobby.id; hobbies.memberId = member.id; db.MembersHobbies.Add(hobbies); } } db.SaveChanges(); } catch (DbEntityValidationException ex) { string errors = ""; foreach (DbEntityValidationResult vr in ex.EntityValidationErrors) { foreach (DbValidationError er in vr.ValidationErrors) { errors += $"PropertyName - {er.PropertyName }, Error {er.ErrorMessage} <br/>"; } } return(Request.CreateResponse(HttpStatusCode.BadRequest, errors)); } catch (DbUpdateException ex) { DbUpdateException e = (DbUpdateException)ex; string errors = ""; foreach (DbEntityEntry entry in e.Entries) { errors += $"Error in entity - {entry.Entity.GetType().Name}, entity state - {entry.State} <br/>"; foreach (string prop in entry.CurrentValues.PropertyNames) { errors += $"for column - {prop}, value - {entry.CurrentValues[prop]} <br/>"; } errors += "---------------"; } return(Request.CreateResponse(HttpStatusCode.BadRequest, errors)); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message)); } return(Request.CreateResponse(HttpStatusCode.OK, "Profile updated successfully")); }
/// <param name='operations'> /// Reference to the DataExportSales.IProfiles. /// </param> /// <param name='id'> /// Required. Profile Id /// </param> /// <param name='updatedProfile'> /// Required. Description of updates to the Profile /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> public static async Task <object> UpdateProfileAsync(this IProfiles operations, string id, ProfileDetailsDTO updatedProfile, CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { Microsoft.Rest.HttpOperationResponse <object> result = await operations.UpdateProfileWithOperationResponseAsync(id, updatedProfile, cancellationToken).ConfigureAwait(false); return(result.Body); }
public ProfileDetailsDTO ChangeProfileDetailsSL(ProfileDetailsDTO data, int personID) { return(Account.ChangeProfileDetailsDL(data, personID)); }