public bool OpenExchangeRates() { try { string BaseCurrency = "USD"; string AppId = configuration.GetValue <string>("OpenExchange_APIKey"); string ApiUrl = "https://openexchangerates.org/api/latest.json?app_id=" + AppId + "&base=" + BaseCurrency; using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(ApiUrl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.GetAsync(ApiUrl).Result; if (response.IsSuccessStatusCode) { var data = response.Content.ReadAsStringAsync(); //dynamic table = data.Result.ConvertFromJson<ExpandoObject>(); dynamic table = OptionConfigExtentions .ConvertFromJson <ExpandoObject>(data.Result);// data.Result.ConvertFromJson<ExpandoObject>(); var result = new Dictionary <string, double>(); dynamic rates = table.rates; foreach (var x in rates) { result.Add(x.Key, x.Value); } double ZARValue = result["ZAR"]; List <CurrencyHistory> Currencies = new List <CurrencyHistory>(); foreach (var item in result) { CurrencyHistory currency = new CurrencyHistory(); currency.ConversionRate = ZARValue / item.Value; currency.Code = item.Key; currency.DateTimeStamp = DateTime.UtcNow; Currencies.Add(currency); } Repository.AddMultiple(Currencies); //TO DO SEND EMAIL } return(true); } } catch (Exception) { return(false); } }
public string UploadMasjid(IFormFile file) { try { if (!IsSuperUser()) { return("Failed"); } if (ModelState.IsValid) { using (MemoryStream stream = new MemoryStream()) { file.CopyTo(stream); byte[] byteArray = stream.ToArray(); Stream stream2 = new MemoryStream(byteArray); var package = new ExcelPackage(stream2); var z = package.Workbook.Worksheets[1]; ExcelWorksheet Sheet = package.Workbook.Worksheets[1]; List <Masjid> Masjids = new List <Masjid>(); for (int i = 2; i <= Sheet.Dimension.End.Row; i++) { try { var M = new Masjid(); M.OldSiteId = Convert.ToInt32(Sheet.Cells[i, 1].Value.ToString()); if (M.OldSiteId == 1) { continue; } M.Name = Sheet.Cells[i, 2].Value.ToString(); M.Town = Sheet.Cells[i, 3].Value.ToString(); M.Country = Sheet.Cells[i, 4].Value.ToString(); M.Latitude = Convert.ToDouble(Sheet.Cells[i, 5].Value.ToString()); M.Longitude = Convert.ToDouble(Sheet.Cells[i, 6].Value.ToString()); //M.JuristMethod = (JuristicMethod)Enum.ToObject(typeof(JuristicMethod), (int)Sheet.Cells[i, 9].Value); string Ladies = Sheet.Cells[i, 10].Value.ToString(); if (Ladies == "Yes") { M.LadiesFacility = true; } else { M.LadiesFacility = false; } double Jummah = (double)Sheet.Cells[i, 11].Value; if (Jummah == 1) { M.JummahFacility = true; } else { M.JummahFacility = false; } M.Address = Sheet.Cells[i, 12].Value == null ? "" : Sheet.Cells[i, 12].Value.ToString(); M.Contact = Sheet.Cells[i, 13].Value == null ? "" : Sheet.Cells[i, 13].Value.ToString(); M.GeneralInfo = Sheet.Cells[i, 14].Value == null ? "" : Sheet.Cells[i, 14].Value.ToString(); M.TimeZoneId = "South Africa Standard Time"; Masjids.Add(M); } catch (Exception ex) { continue; } } Masjids = Masjids.OrderBy(s => s.OldSiteId).ToList(); Repository.AddMultiple(Masjids); package.Dispose(); } return("Successful"); } else { throw new Exception(); } } catch (Exception ex) { return("Fail" + ex.Message); } }
public string UploadRapidsoft(IFormFile file) { try { if (ModelState.IsValid) { List <SalaahTime> Times = new List <SalaahTime>(); ApplicationUser user = _userManager.GetUserAsync(User).Result; using (var reader = new StreamReader(file.OpenReadStream())) { var text = reader.ReadToEnd(); text = text.Replace("\"", ""); string[] lines = text.Split( new[] { Environment.NewLine }, StringSplitOptions.None ); bool SequenceFound = false; string MonthLinker = ""; foreach (var Line in lines) { if (Line == "" | Line == null) { break; } string[] z = Line.Split( new[] { ',' }, StringSplitOptions.None ); if (SequenceFound == true) { SalaahTime Time = new SalaahTime(); Time.Type = SalaahTimesType.DailyTime; Time.MasjidId = user.MasjidId; if (z[0] != "") { MonthLinker = z[0]; } string DT = z[1] + " " + MonthLinker; Debug.WriteLine(DT); DateTime myDate = DateTime.ParseExact(DT, "d MMMM yyyy", System.Globalization.CultureInfo.InvariantCulture); Time.TimeDate = myDate; Time.DayNumber = myDate.DayOfYear; Time.FajrAdhaan = StringToDateTime(z[10]); Time.FajrSalaah = StringToDateTime(z[11]); Time.DhuhrAdhaan = StringToDateTime(z[12]); Time.DhuhrSalaah = StringToDateTime(z[13]); Time.AsrAdhaan = StringToDateTime(z[14]); Time.AsrSalaah = StringToDateTime(z[15]); Time.IshaAdhaan = StringToDateTime(z[18]); Time.IshaSalaah = StringToDateTime(z[19]); if (z[2] == "Friday") { Time.JumuahAdhaan = StringToDateTime(z[12]); Time.JumuahSalaah = StringToDateTime(z[13]); } Times.Add(Time); } if (z[0] == "#####") { SequenceFound = true; } } List <SalaahTime> OldTimes = Repository .Find <SalaahTime>(s => s.MasjidId == "5f3e7169-ab20-4b34-bb27-2e86eefee2c1")//user.MasjidId) .ToList(); Times = Times.OrderBy(s => s.DayNumber).ToList(); CheckDbTimeChange(Times); Repository.AddMultiple(Times); Repository.DeleteMultiple(OldTimes); } return("Success"); } else { throw new Exception(); } } catch (Exception ex) { return("Fail" + ex.Message); } }
public void DBInit() { List <Models.TimeZone> TimeZones = Repository.GetAll <Models.TimeZone>().ToList(); if (TimeZones.Count < 1) { foreach (var Zone in TimeZoneInfo.GetSystemTimeZones()) { Models.TimeZone T = new Models.TimeZone(); T.Id = Zone.Id; T.DaylightName = Zone.DaylightName; T.DisplayName = Zone.DisplayName; T.StandardName = Zone.StandardName; T.SupportsDaylightSavingTime = Zone.SupportsDaylightSavingTime; T.DefaultUTCDifference = cCalculations.GetTimeZoneDifference(T.Id, DateTime.Now); TimeZones.Add(T); } Repository.AddMultiple(TimeZones); } List <Masjid> AllMasjids = Repository.GetAll <Masjid>().ToList(); //DB INIT if (AllMasjids.Count < 1) { Masjid s = new Masjid(); s.Id = "5f3e7169-ab20-4b34-bb27-2e86eefee2c1"; s.Name = "Masjid Muaadh bin Jabal - Crosby"; s.Town = "Johannesburg"; s.Country = "South Africa"; s.Latitude = -26.195149; s.Longitude = 27.990238; s.OldSiteId = 1; s.LadiesFacility = true; s.JummahFacility = true; s.Address = "114 Jamestown Avenue Crosby Johannesburg 2092"; s.Contact = "Ml R Joosub, Ml S Maanjra, Br Abdur Rasheed, Br Faizal Suffla, Br Basheer Seedat"; s.TimeZoneId = "South Africa Standard Time"; Repository.Add(s); } //// List <ApplicationUser> Users = Repository.GetAll <ApplicationUser>().ToList(); if (Users.Count < 1) { var OmairEmail = "*****@*****.**"; var user = new ApplicationUser { UserName = OmairEmail, Email = OmairEmail, Id = "513f1fe1-8e01-4c62-b332-ee8a0f7e2c29", FullName = "Omair Kazi", EmailConfirmed = true, ActiveStatus = UserStatus.Active, IsSuperUser = true, CreatedAt = new DateTime(2016, 1, 1), MasjidId = "5f3e7169-ab20-4b34-bb27-2e86eefee2c1" }; var Password = "******"; var result = _userManager.CreateAsync(user, Password).Result; } }