How to save multiple contact? - windows-phone-7

I am developing windows phone app which require to save multiple contact. I have store the contact in list. I want to save the contact one by one.
Here is my code
var data = from q in document.Descendants("Contact")
select new ContactList
{
DisplayName = q.Element("Name").Value,
Email = !string.IsNullOrEmpty(q.Element("Email").Value) ? q.Element("Email").Value : " ",
Address = !string.IsNullOrEmpty(q.Element("Address").Value) ? q.Element("Address").Value : " ",
//PhoneNumber = m.PhoneNumbers.FirstOrDefault()
PhoneNumber = !string.IsNullOrEmpty(q.Element("PhoneNumber").Value) ? q.Element("PhoneNumber").Value : " "
};
ContactList con = null;
SaveContactList = new List<ContactList>();
foreach (var c in data)
{
con = new ContactList();
con.DisplayName = c.DisplayName;
con.Address = c.Address;
con.Email = c.Email;
con.PhoneNumber = c.PhoneNumber;
SaveContactList.Add(con);
}
Here I have store all contact in SaveContactList. Now I want to save all these contact. How can I save these contact ?

If you are trying to save them to Windows Phone Phonebook - there is no way to save all contacts at a time.
You can only save them 1 by 1, you may use foreach
Sample to save contact:
var phoneCallTask = new PhoneCallTask
{
DisplayName = ContactName.Text,
PhoneNumber = phonetext.Text
};
phoneCallTask.Show();

Related

How can I retrieve Id of inserted entity using Entity framework Core?

I have a concern since as I am new to using EntityFramework Core, that if I add an object, that I still do not have the id generated by the database, sending the object to it in the transaction, I would add it automatically, this is my code ,
public async Task<ServiceResult<Common.Entities.Company>> SaveCompany(Domain.Models.Company companyModel, Domain.Models.Administrator administratoModel)
{
ServiceResult<Common.Entities.Company> serviceResult = new ServiceResult<Common.Entities.Company>();
try
{
if (user == null && companyExistsRnc == false)
{
Common.Entities.Company myCompany = new Common.Entities.Company
{
CompanyId = companyModel.CompanyId, // The id has not been generated yet,
CompanyName = companyModel.CompanyName,
Rnc = companyModel.Rnc,
CountryId = companyModel.Country.CountryId,
Telephone = companyModel.Telephone,
PersonContact = companyModel.PersonContact,
Address = companyModel.Address,
PhotoPath = companyModel.PhotoPath,
IsActive = false,
};
await _companyRepository.SaveCompany(myCompany); // this is the method that I add the company object to the database and do the savechanges
Common.Entities.User myUser = new Common.Entities.User
{
FirstName = administratoModel.FirstName,
SecondName = administratoModel.SecondName,
FirstLastName = administratoModel.FirstLastName,
SecondLastName = administratoModel.SecondLastName,
GenderId = administratoModel.Gender.GenderId,
PhoneNumber = administratoModel.Telephone,
Email = administratoModel.Email,
UserName = administratoModel.Email,
IsActive = administratoModel.IsActive,
UserTypeId = (short)Common.Core.UserType.Administrator,
Company = myCompany, // here I send the my company object for when I do the savechanges, I think it will add it to me
};
await _userHelper.AddUserAsync(myUser, administratoModel.Password);
await _userHelper.AddUserToRoleAsync(myUser, Common.Core.UserType.Administrator.ToString());
Common.Entities.Administrator myAdministrator = new Common.Entities.Administrator
{
AdministratorId = administratoModel.AdministratorId,
FirstName = administratoModel.FirstName,
SecondName = administratoModel.SecondName,
FirstLastName = administratoModel.FirstLastName,
SecondLastName = administratoModel.SecondLastName,
GenderId = administratoModel.Gender.GenderId,
Email = administratoModel.Email,
Telephone = administratoModel.Telephone,
IsActive = true,
PhotoPath = administratoModel.PhotoPath,
UserTypeId = (short)Common.Core.UserType.Administrator,
Company = myCompany, // company object without the id
User = myUser, // user object without the id
};
await _administratorRepository.SaveAdministrator(myAdministrator);
serviceResult.Data = myCompany;
serviceResult.Message = "CompaƱia agregada!";
}
}
I am new to using entity framework core, and if in case I am wrong in what I am doing please indicate in which part I am doing it wrong, to correct, I await your comments and would appreciate the help,

Checking if a value exists in a NSDictionary for local notifications

So im using local notifications to send a daily notification to the user, once the notifcation is added i add an id in the userInfo - NSDictionary. The user can remove the medication at any time which will cancel the notification which is why i add the id into the NSDictionary.
var notification = new UILocalNotification();
Random rnd = new Random();
string stringid = rnd.Next(1, 1000000000).ToString();
notification.AlertBody = usermedid + "Please take " + dosage + " of " + medname;
stringid = notification.AlertBody;
App.BadgeCount = App.BadgeCount + 1;
notification.ApplicationIconBadgeNumber = App.BadgeCount;
notification.FireDate = NSDate.FromTimeIntervalSinceNow(60);
notification.RepeatInterval = NSCalendarUnit.Minute;
var userInfo = NSDictionary.FromObjectAndKey(new NSString("UsermeddosageID"),new NSString(usermeddosagetimeid));
notification.UserInfo = userInfo;
UIApplication.SharedApplication.ScheduleLocalNotification(notification);
The code is inserting the id into the NSDictionary but for some reason it wont read it in my IF Statement. Can anybody explain why my code isnt working ?? Any help appreciated..
var array = UIApplication.SharedApplication.ScheduledLocalNotifications;
foreach (var item in array)
{
var userinfo = item.UserInfo;
if (!userinfo.ContainsKey(new NSString(usermeddosagetimeid)))
{
UIApplication.SharedApplication.CancelLocalNotification(item);
}
}
If I understand right, if you want to cancel the notification which contains the key usermeddosagetimeid, the if Statement should be:
if (userinfo.ContainsKey(new NSString(usermeddosagetimeid)))
{
UIApplication.SharedApplication.CancelLocalNotification(item);
}
Instead of !userinfo.ContainsKey(new NSString(usermeddosagetimeid))
BTW, scheduledlocalnotifications is Deprecated since iOS 10, you can use the UNUserNotificationCenter class to schedule local notifications instead.

Modify "LocalizedName" for an Business-process-flow in Dynamics 365 (Version 9.0)

I need to unify the "display name" of an business-process-flow in our environment.
The standard BPF "Opportunity Sales Process", should be called "Opportunity Sales Process" regardless of the UI language of the use (e.g. "Vertriebsprozess Verkaufschance" is the "LocalizedName" for German users).
I have not found any way to change the "LocalizedName" value - the only option is see, is the direct update of the customizations.xml.
Is is possible to update the "LocalizedName" of an BPF via code?
IOrganizationService os; // todo - initialize
Its not clear what you're after :) If you're after updating entity metadata - that is doable:
var request = new RetrieveEntityRequest { LogicalName = "opportunitysalesprocess" };
var response = (RetrieveEntityResponse)os.Execute(request);
var label = response.EntityMetadata.DisplayName.LocalizedLabels
.First(l => l.LanguageCode == 1033);
label.Label = "Thats Not My Name";
os.Execute(new UpdateEntityRequest { Entity = response.EntityMetadata });
If you're after updating process name in grid of processes; it is:
var sec = new SetLocLabelsRequest
{
AttributeName = "name",
Labels = new LocalizedLabel[]
{
new LocalizedLabel
{
Label = "Thats not my name",
LanguageCode = 1033
}
},
EntityMoniker = new EntityReference("workflow",
new Guid("3E8EBEE6-A2BC-4451-9C5F-B146B085413A"))
};
var res = (SetLocLabelsResponse)os.Execute(sec);
Refer to
https://learn.microsoft.com/en-us/dotnet/api/microsoft.crm.sdk.messages.setloclabelsrequest?view=dynamics-general-ce-9
https://learn.microsoft.com/en-us/dotnet/api/microsoft.xrm.sdk.messages.updateentityrequest?view=dynamics-general-ce-9

Entity Framework cycle of data

I have an Account object, which has many Transactions related to it.
In one method, I get all transactions for a particular account.
var transactionlines = (from p in Context.account_transaction
.Include("account_transaction_line")
// .Include("Account")
.Include("account.z_account_type")
.Include("account.institution")
.Include("third_party")
.Include("third_party.z_third_party_type")
.Include("z_account_transaction_type")
.Include("account_transaction_line.transaction_sub_category")
.Include("account_transaction_line.transaction_sub_category.transaction_category")
.Include("z_account_transaction_entry_type")
.Include("account_transaction_line.cost_centre")
where p.account_id == accountId
&& p.deleted == null
select p).ToList();
This is meant to return me a list of transactions, with their related objects. I then pass each object to a Translator, which translates them into data transfer objects, which are then passed back to my main application.
public TransactionDto TranslateTransaction(account_transaction source)
{
LogUserActivity("in TranslateTransaction");
var result = new TransactionDto
{
Id = source.id,
Version = source.version,
AccountId = source.account_id,
// Account = TranslateAccount(source.account, false),
ThirdPartyId = source.third_party_id,
ThirdParty = TranslateThirdParty(source.third_party),
Amount = source.transaction_amount,
EntryTypeId = source.account_transaction_entry_type_id,
EntryType = new ReferenceItemDto
{
Id = source.account_transaction_entry_type_id,
Description = source.z_account_transaction_entry_type.description,
Deleted = source.z_account_transaction_entry_type.deleted != null
},
Notes = source.notes,
TransactionDate = source.transaction_date,
TransactionTypeId = source.account_transaction_type_id,
TransactionType = new ReferenceItemDto
{
Id = source.z_account_transaction_type.id,
Description = source.z_account_transaction_type.description,
Deleted = source.z_account_transaction_type.deleted != null
}
};
... return my object
}
The problem is:
An account has Transactions, and a Transaction therefore belongs to an Account. It seems my translators are being called way too much, and reloading a lot of data because of this.
When I load my transaction object, it's 'account' property has a'transactions' propery, which has a list of all the transactions associated to that account. Each transaction then has an account property... and those account peroprties again, have a list of all the transactions... and on and on it goes.
Is there a way I can limit the loading to one level or something?
I have this set:
Context.Configuration.LazyLoadingEnabled = false;
I was hoping my 'Includes' would be all that is loaded... Don't load 'un-included' related data?
As requested, here is my TranslateAccount method:
public AccountDto TranslateAccount(account p, bool includeCardsInterestRateDataAndBalance)
{
LogUserActivity("in TranslateAccount");
if (p == null)
return null;
var result =
new AccountDto
{
Id = p.id,
Description = p.description,
PortfolioId = p.institution.account_portfolio_id,
AccountNumber = p.account_number,
Institution = TranslateInstitution(p.institution),
AccountType = new ReferenceItemDto
{
Id = p.account_type_id,
Description = p.z_account_type.description
},
AccountTypeId = p.account_type_id,
InstitutionId = p.institution_id,
MinimumBalance = p.min_balance,
OpeningBalance = p.opening_balance,
OpeningDate = p.opening_date
};
if (includeCardsInterestRateDataAndBalance)
{
// Add the assigned cards collection
foreach (var card in p.account_card)
{
result.Cards.Add(new AccountCardDto
{
Id = card.id,
AccountId = card.account_id,
Active = card.active,
CardHolderName = card.card_holder_name,
CardNumber = card.card_number,
ExpiryDate = card.expiry
});
}
// Populate the current interest rate
result.CurrentRate = GetCurrentInterestRate(result.Id);
// Add all rates to the account
foreach (var rate in p.account_rate)
{
result.Rates.Add(
new AccountRateDto
{
Id = rate.id,
Description = rate.description,
Deleted = rate.deleted != null,
AccountId = rate.account_id,
EndDate = rate.end_date,
Rate = rate.rate,
StartDate = rate.start_date
});
}
result.CurrentBalance = CurrentBalance(result.Id);
}
LogUserActivity("out TranslateAccount");
return result;
}
The entity framework context maintains a cache of data that has been pulled out of the database. Regardless of lazy loading being enabled/disabled, you can call Transaction.Account.Transactions[0].Account.Transactions[0]... as much as you want without loading anything else from the database.
The problem is not in the cyclical nature of entity framework objects - it is somewhere in the logic of your translation objects.

Windows Azure Storage - Table not found

I'm trying to implement windows azure table storage...but I'm getting 'Table Not Found'
Here is my connection string(How post I xml here?)(sorry for links)
ServiceConfiguration.Cloud.cscfg:
http://pastebin.com/F9tuckfT
ServiceConfiguration.Local.cscfg:
http://pastebin.com/XZHEvv6g
and here there's a print screen from my windows azure portal
http://s20.postimage.org/nz1sxq7hp/print.png
The code(sorry for the longer code...but there's three pages...Login works, when I log in, go to main.aspx that call grid.aspx ...In grid.aspx I get the error "Table not found" All this code is important for the question.....) http://pastebin.com/RnuvvqsM
I have tried
private void popula()
{
var account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Conn"));
account.CreateCloudTableClient().CreateTableIfNotExist("fiscal");
var context = new CRUDManifestacoesEntities(account.TableEndpoint.ToString(), account.Credentials);
Hashtable ht = (Hashtable)ViewState["filtro"];
if (ht == null)
GridView1.DataSource = context.SelectConc(ViewState["x"].ToString());
else
GridView1.DataSource = context.SelectConc(ht);
GridView1.DataBind();
}
but it doesn't work too
Other error similar is when I try to add a USER in table
public string addusr(string nome, string cidade, string cpf, string email, string telefone)
{
try
{
if (nome.Length == 0)
return "f:Preencha o campo nome.";
if (cidade.Length == 0)
return "f:Preencha o campo cidade.";
if (cpf.Length == 0)
return "f:Preencha o campo cpf.";
if (!Valida(cpf))
return "f:CPF Invalido.";
if (email.Length == 0)
return "f:Preencha o campo email.";
Regex rg = new Regex(#"^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)#([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$");
if (!rg.IsMatch(email))
{
return "f:Email Invalido";
}
List<UserEntity> lst = new List<UserEntity>();
var _account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Conn"));
_account.CreateCloudTableClient().CreateTableIfNotExist("fiscal");
var _context = new CRUDUserEntities(_account.TableEndpoint.ToString(), _account.Credentials);
var account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Conn"));
account.CreateCloudTableClient().CreateTableIfNotExist("fiscal");
var context = new CRUDUserEntities(account.TableEndpoint.ToString(), account.Credentials);
UserClientEntity entity = new UserClientEntity() { nome = nome, cidade = cidade, cpf = cpf, email = email, telefone = telefone };
context.ADDUSociate(entity);
context.SaveChanges();
return "k";
}
I'm getting this error:
f:An error occurred while processing this request.| at System.Data.Services.Client.DataServiceContext.SaveResult.HandleBatchResponse()
at System.Data.Services.Client.DataServiceContext.SaveResult.EndRequest()
at System.Data.Services.Client.DataServiceContext.SaveChanges(SaveChangesOptions options)
at AzureTableLayer.CRUDUserEntities.ADDUSociate(UserClientEntity entity)
at mobile.Service1.addusr(String nome, String cidade, String cpf, String email, String telefone)
I believe that the two problems are related
EDIT: I have debugged and discovered that the StorageClient framework could not be loaded...
I'm getting this error Could not load file or assembly Microsoft.WindowsAzure.StorageClient, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
How to solve?
How are you trying to work with Table Storage? Trought the .NET SDK? PHP? Java? Node? ... Typically if you get this error it means that... the table does not exist.
Check the SDK you're using for a method similar to CreateIfNotExists in order to create the table before you start using it.
Edit:
The issue probably happens here:
var account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Conn"));
var context = new CRUDManifestacoesEntities(account.TableEndpoint.ToString(), account.Credentials);
Hashtable ht = (Hashtable)ViewState["filtro"];
if (ht == null)
GridView1.DataSource = context.SelectConc(ViewState["x"].ToString());
else
GridView1.DataSource = context.SelectConc(ht);
Add the following code after the var account = ... line:
account.CreateCloudTableClient().CreateTableIfNotExist("<name of your table>");
The API has been changed. you need to do it like this:
var key = CloudConfigurationManager.GetSetting("Setting1");
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(key);
var client = storageAccount.CreateCloudTableClient();
CloudTable table = client.GetTableReference(ContactTableName);
table.CreateIfNotExists();

Resources