public async Task <IActionResult> PutPlace(long id, Place place) { if (id != place.PlaceId) { return(BadRequest()); } _context.Entry(place).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PlaceExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutDocument(long id, Document document) { if (id != document.DocumentId) { return(BadRequest()); } _context.Entry(document).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DocumentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutUser(long id, User user) { if (id != user.UserId) { return(BadRequest()); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Currency> > PostCurrency(Currency currency) { _context.Currencies.Add(currency); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetCurrency), new { Id = currency.CurrencyId }, currency)); }
private async Task PushToDB(List <KeyValuePair <string, double> > RatesList) { _logger.LogInformation($"LOG: PushToDB - started"); _logger.LogInformation($"LOG: RatesList.Count: {RatesList.Count}"); Dictionary <string, long> CurrencyCodeIds = new Dictionary <string, long>(); List <string> currencyCodes = (from k in RatesList select k.Key).ToList(); _logger.LogInformation($"LOG: currencyCodes.Count: {currencyCodes.Count}"); var Currencies = await _context.Currencies.ToListAsync(); _logger.LogInformation($"LOG: Currencies.Count: {Currencies.Count}"); foreach (var currencyCode in currencyCodes) { CurrencyCodeIds.Add(currencyCode, Currencies.SingleOrDefault(c => c.Name == currencyCode).CurrencyId); } _logger.LogInformation($"LOG: CurrencyCodeIds.Count: {CurrencyCodeIds.Count}"); var ExchangeRates = await _context.ExchangeRates.ToListAsync(); _logger.LogInformation($"LOG: ExchangeRates.Count: {ExchangeRates.Count}"); foreach (var item in RatesList) { string baseCurrency = item.Key; var baseCurrencyRate = item.Value; long baseCurrencyId = CurrencyCodeIds[baseCurrency]; _logger.LogInformation($"LOG: baseCurrency: {baseCurrency} baseCurrencyRate: {baseCurrencyRate} baseCurrencyId: {baseCurrencyId}"); var ratesListTemp = new List <KeyValuePair <string, double> > (RatesList.Select (r => new KeyValuePair <string, double>(r.Key, r.Value / baseCurrencyRate))); _logger.LogInformation($"LOG: ratesListTemp.Count: {ratesListTemp.Count}"); foreach (var rate in ratesListTemp) { if (rate.Key != baseCurrency) { var SecondCurrencyId = CurrencyCodeIds[rate.Key]; if (ExchangeRates.Exists(r => r.FirstCurrencyId == baseCurrencyId && r.SecondCurrencyId == SecondCurrencyId)) { var rateToUpdate = await _context.ExchangeRates.SingleOrDefaultAsync(r => r.FirstCurrencyId == baseCurrencyId && r.SecondCurrencyId == SecondCurrencyId); rateToUpdate.Rate = rate.Value; } var exRate = new ExchangeRate(); exRate.FirstCurrencyId = baseCurrencyId; exRate.SecondCurrencyId = SecondCurrencyId; exRate.Rate = rate.Value; await _context.ExchangeRates.AddAsync(exRate); } } _logger.LogInformation($"LOG: context is about to be saved"); await _context.SaveChangesAsync(); } }
public async Task <IActionResult> CreateUser([FromBody] AuthData authData) { UserIdentity userIdentity = new UserIdentity() { Email = authData.Email, SecurityStamp = Guid.NewGuid().ToString(), UserName = authData.Username }; var result = await _userManager.CreateAsync(userIdentity, authData.Password); if (!result.Succeeded) { return(BadRequest()); //BadRequestObjectResult(Errors.Add); } //var identityId = userIdentity.I await _context.Users.AddAsync(new User { Username = userIdentity.UserName, Email = userIdentity.Email, CurrencyId = authData.CurrencyId, IdentityId = userIdentity.Id }); await _context.SaveChangesAsync(); return(new OkObjectResult("Account created")); }