public async Task <EditValutaDto> AddValuta(PostValutaDto postValutaDto) { var httpClient = _httpClientFactory.CreateClient("valute"); var url = $"09a14a921f6de3a3c311a083/pair/HRK/{postValutaDto.Naziv}"; var response = await httpClient.GetAsync(url); var responseStream = await response.Content.ReadAsStreamAsync(); var responseObject = await JsonSerializer.DeserializeAsync <KonverzijaValute>(responseStream); var korisnik = await _userManager.FindByNameAsync(postValutaDto.UserName); var valuta = new Valuta() { Naziv = postValutaDto.Naziv, AktivnoOd = postValutaDto.AktivnoOd, AktivnoDo = postValutaDto.AktivnoDo, Tecaj = responseObject.conversion_rate, SlikaValute = postValutaDto.SlikaValute, KorisnikId = korisnik.Id }; var role = _context.UserRoles .Where(u => u.UserId == korisnik.Id) .FirstOrDefault(); if (role.RoleId != 2) { throw new Exception("Izabrani korisnik nije u funkciji moderatora i ne može biti zadužen za valutu."); } _context.Add(valuta); await _context.SaveChangesAsync(); return(_mapper.Map <EditValutaDto>(valuta)); }
public static void SeedDatabase(ExchangeDbContext db) { /* Load default approvals */ using (var reader = new StreamReader("api/AdminTools/approved-unit-sets.csv")) { var(errors, unitSets) = EquivalenceUnitSetsReader.LoadEquivalencies(reader); if (errors != null) { Console.WriteLine(errors); return; } EquivalenceUnitSetsReader.UpdateEquivalenciesInDatabase(db, unitSets); } db.Add(new StudentApplication { SubmittedAt = DateTime.Now, LastUpdatedAt = DateTime.Now, StudentName = "Henry Hollingworth", StudentNumber = "21471423", Major1st = "Computer Science", ExchangeUniversityCountry = "Finalnd", ExchangeUniversityHref = "http://finalnd.com", ExchangeUniversityName = "Finland University", Status = StudentApplicationStatus.Incomplete, UnitSets = new UnitSet[] { new UnitSet { ExchangeUniversityCountry = "Finalnd", ExchangeUniversityHref = "http://finalnd.com", ExchangeUniversityName = "Finland University", IsContextuallyApproved = true, IsEquivalent = null, EquivalentUWAUnitLevel = UWAUnitLevel.Two, ExchangeUnits = new ExchangeUnit[] { new ExchangeUnit { Code = "MATH-HARD", Title = "The Hardest Math", Href = "http://hard-math.com" } }, UWAUnits = new UWAUnit[] { new UWAUnit { Code = "MATH-1001", Title = "Mathematics I", Href = "http://uwa-unit.com" }, new UWAUnit { Code = "MATH-1002", Title = "Mathematics II", Href = "http://uwa-unit.com" } }, Comments = "Very good!" } } }); db.Add(new StudentApplication { SubmittedAt = DateTime.Now, LastUpdatedAt = DateTime.Now, StudentName = "Josh Ellis", StudentNumber = "24579463", Major1st = "Computer Science", ExchangeUniversityCountry = "Finalnd", ExchangeUniversityHref = "http://finalnd.com", ExchangeUniversityName = "Holloween University", Status = StudentApplicationStatus.New, UnitSets = new UnitSet[] { new UnitSet { ExchangeUniversityCountry = "Finalnd", ExchangeUniversityHref = "http://finalnd.com", ExchangeUniversityName = "Finland University", IsContextuallyApproved = null, IsEquivalent = null, EquivalentUWAUnitLevel = null, ExchangeUnits = new ExchangeUnit[] { new ExchangeUnit { Code = "MATH-HARD", Title = "The Hardest Math", Href = "http://hard-math.com" } }, UWAUnits = new UWAUnit[] { new UWAUnit { Code = "MATH-1001", Title = "Mathematics I", Href = "http://uwa-unit.com" }, new UWAUnit { Code = "MATH-1002", Title = "Mathematics II", Href = "http://uwa-unit.com" } }, Comments = "Not a good choice" } } }); db.SaveChanges(); }