Beispiel #1
0
        public async Task <ActionResult <FromTo> > GetRateToUsd(string from, string to)
        {
            if (!norm(ref from))
            {
                return(BadRequest($"From {from}  have been 3 letter length"));
            }
            if (!norm(ref to))
            {
                return(BadRequest($"To {to} have been 3 letter length"));
            }
            RateToUsd _from = await Svc.Get(from, true);

            RateToUsd _to = await Svc.Get(from, true);

            if (_from == null)
            {
                return(NotFound($"Code {from} not found"));
            }
            if (_to == null)
            {
                return(NotFound($"Code {to} not found"));
            }
            if (_from == null || _to.Rate == 0)
            {
                return(NotFound());
            }

            return(new FromTo()
            {
                From = _from, To = _to
            });
        }
        public async Task <IActionResult> PutRateToUsd(string code, RateToUsd rateToUsd)
        {
            code = code.ToUpper();
            if (code != rateToUsd.Code)
            {
                return(BadRequest());
            }

            _context.Entry(rateToUsd).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RateToUsdExists(code))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #3
0
        public async Task <IActionResult> DeleteRateToUsd(string code)
        {
            RateToUsd rateToUsd = await Context.RateToUsd.FindAsync(code);

            if (rateToUsd != null)
            {
                Context.RateToUsd.Remove(rateToUsd);
                await Context.SaveChangesAsync();
            }

            if (!Svc.Delete(code))
            {
                return(NotFound());
            }


            return(Ok());
        }
        public async Task <ActionResult <RateToUsd> > PostRateToUsd(RateToUsd rateToUsd)
        {
            _context.Rates.Add(rateToUsd);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (RateToUsdExists(rateToUsd.Code))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetRateToUsd", new { code = rateToUsd.Code }, rateToUsd));
        }