public async Task <string> CreatePersonalCard(string accessJwt, PersonalCardModel personal_card_obj, List <int> attachments, string udid) { personal_card_obj.SubscriptionID = null; using (HttpClient client = new HttpClient()) { if (attachments != null) { if (attachments.Count != 0) { personal_card_obj.Person.Attachments = attachments; } } client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessJwt); client.DefaultRequestHeaders.Add(Constants.XClientIdentifier, udid); personal_card_obj.Employment.Email = null; var myContent = JsonConvert.SerializeObject(personal_card_obj /*new { pushToken = "any uniqueidentifier", clientName = "Application" }*/); var content = new StringContent(myContent.ToString(), Encoding.UTF8, "application/json"); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var res = await client.PostAsync(main_url, content); if (res.StatusCode.ToString().ToLower().Contains(Constants.status_code401) || res.StatusCode.ToString().ToLower().Contains("401")) { return(Constants.image_upload_status_code401.ToString()); //means that we got 401 } return(await res.Content.ReadAsStringAsync()); //var response_result = content_response.Result; //return response_result; } }
public void Save(PersonalCardModel model) { var personalCard = context.PersonalCards.AsNoTracking() .SingleOrDefault(_ => _.Id == model.Id); if (personalCard == null) { var newPersonalCardModel = modelMapper.MapTo <PersonalCardModel, PersonalCard>(model); newPersonalCardModel.CycleCommission = null; model.Id = context.PersonalCards.Add(newPersonalCardModel).Entity.Id; } else { var newPersonalCard = modelMapper.MapTo <PersonalCardModel, PersonalCard>(model); context.PersonalCards.Update(newPersonalCard); } context.SaveChanges(); var personalCardsSubjects = model.Subjects.Select(_ => new PersonalCardSubject() { PersonalCardId = model.Id, SubjectId = _.Id }); foreach (var personalCardSubject in personalCardsSubjects) { var personalCardSubjectEntity = context.PersonalCardsSubjects.AsNoTracking() .FirstOrDefault(_ => _.SubjectId == personalCardSubject.SubjectId && _.PersonalCardId == personalCardSubject.PersonalCardId); if (personalCardSubjectEntity == null) { context.PersonalCardsSubjects.Add(personalCardSubject); context.SaveChanges(); } } context.SaveChanges(); }
public IActionResult Save(PersonalCardModel model) { try { personalCardService.Save(model); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public PersonalCardModel GetDataFromUsersCard(int?company_id, int subscription_id, string position_alternative, string corporative_phone_alternative) { //if (db == null) //db = new SQLiteConnection(dbPath); using (var db = new SQLiteConnection(dbPath)) { db.CreateTable <UsersCardTable>(); var users_card_table = db.Table <UsersCardTable>(); foreach (var user_card in users_card_table) { var location_obj = new LocationModel { Country = user_card.country, PostalCode = user_card.index, Region = user_card.region, Address = user_card.address, City = user_card.city, Notes = user_card.notes, Latitude = user_card.latitude, Longitude = user_card.longitude }; var employment_obj = new EmploymentModel { Position = GetPositonInCompany(), Phone = GetCorporativePhoneInCompany(), Email = user_card.email, CompanyID = company_id }; if (String.IsNullOrEmpty(employment_obj.Position) && !String.IsNullOrEmpty(employment_obj.Phone)) { employment_obj = new EmploymentModel { Position = position_alternative, Phone = GetCorporativePhoneInCompany(), Email = user_card.email, CompanyID = company_id } } ; else if (String.IsNullOrEmpty(employment_obj.Position) && String.IsNullOrEmpty(employment_obj.Phone)) { employment_obj = new EmploymentModel { Position = position_alternative, Phone = corporative_phone_alternative, Email = user_card.email, CompanyID = company_id } } ; else if (!String.IsNullOrEmpty(employment_obj.Position) && String.IsNullOrEmpty(employment_obj.Phone)) { employment_obj = new EmploymentModel { Position = GetPositonInCompany(), Phone = corporative_phone_alternative, Email = user_card.email, CompanyID = company_id } } ; var person_obj = new PersonModel { FirstName = user_card.name, LastName = user_card.surname, MiddleName = user_card.middlename, MobilePhone = user_card.phone, HomePhone = user_card.home_phone, BirthDate = user_card.birthdate, AddressForm = null, Email = user_card.email, SiteUrl = user_card.personal_site, Education = user_card.education, Location = location_obj, SocialNetworks = GetPersonalNetworkList() }; var personal_card_obj = new PersonalCardModel { SubscriptionID = subscription_id, Name = user_card.card_name, Culture = "ru_RU", IsPrimary = false, Person = person_obj, Employment = employment_obj }; return(personal_card_obj); } return(null); } }
public async Task <HttpResponseMessage> CardUpdate(string accessJwt, int card_id, PersonalCardModel personal_card_obj, bool is_primary, List <SocialNetworkModel> socialNetworksList, List <int> attachments, string udid) { using (HttpClient client = new HttpClient()) { personal_card_obj.SubscriptionID = null; if (attachments.Count != 0) { personal_card_obj.Person.Attachments = attachments; } if (personal_card_obj == null) { var res_card_data = await CardDataGet(databaseMethods.GetAccessJwt(), card_id, udid); personal_card_obj = JsonConvert.DeserializeObject <PersonalCardModel>(res_card_data); } string myContent; if (personal_card_obj.Person.SocialNetworks == null) { personal_card_obj.Person.SocialNetworks = socialNetworksList; } else if (personal_card_obj.Person.SocialNetworks.Count == 0) { personal_card_obj.Person.SocialNetworks = socialNetworksList; } personal_card_obj.Employment.Email = null; if (is_primary) { personal_card_obj.IsPrimary = true; myContent = JsonConvert.SerializeObject(personal_card_obj);//new { pushToken = "any uniqueidentifier", clientName = "Application" }); } else { PersonalCardModelWithoutPrimary cardModelWithoutPrimary = new PersonalCardModelWithoutPrimary(); //cardModelWithoutPrimary.SubscriptionID = personal_card_obj.SubscriptionID; cardModelWithoutPrimary.Person = personal_card_obj.Person; cardModelWithoutPrimary.Name = personal_card_obj.Name; cardModelWithoutPrimary.Employment = personal_card_obj.Employment; cardModelWithoutPrimary.Culture = personal_card_obj.Culture; myContent = JsonConvert.SerializeObject(cardModelWithoutPrimary); } var content = new StringContent(myContent.ToString(), Encoding.UTF8, "application/json"); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessJwt); client.DefaultRequestHeaders.Add(Constants.XClientIdentifier, udid); HttpResponseMessage response = null; try { response = await client.PutAsync(main_url + "/" + card_id, content); var content_response = await response.Content.ReadAsStringAsync(); } catch (HttpRequestException re) { } return(response); } }