public GetInfoViewModel() { SaveIntoDB = new Command(async() => { using (AppDbContext dbContext = new AppDbContext()) { User deletedUser = await dbContext.Users.FirstOrDefaultAsync(); if (deletedUser != null) { dbContext.Users.Remove(deletedUser); } await dbContext.Users.AddAsync(new User { Name = "ali", Number = TelephoneNumber.StartsWith("+98") ? TelephoneNumber : "+98" + TelephoneNumber }); await dbContext.SaveChangesAsync(); await Page.DisplayAlert("ثبت", "شماره مورد نظر با موفقیت ثبت گردید", "باشه!"); } }); GoBackToHomePage = new Command(async() => { await Navigation.PopAsync(false); }); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="output"></param> /// <returns></returns> public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { if (TelephoneNumber.IsEmpty()) { output.TagName = "span"; output.Attributes.RemoveAll("telephone"); return; } // Check to see if the number start with + ? if (!TelephoneNumber.StartsWith("+")) { output.TagName = "span"; output.Attributes.RemoveAll("telephone"); return; } // Remove space hyphen and (0) TelephoneNumber = TelephoneNumber.Replace("-", "").Replace(" ", "").Replace("(0)", ""); // Find non-numeric character and chop it off int index = 1; while (index < TelephoneNumber.Length) { if (!(TelephoneNumber[index] >= '0' && TelephoneNumber[index] <= '9')) { TelephoneNumber = TelephoneNumber.Substring(0, index); } index++; } // Telephone link output.TagName = "a"; output.Attributes.RemoveAll("telephone"); output.Attributes.SetAttribute("href", $"tel:{TelephoneNumber}"); await base.ProcessAsync(context, output); }