Ejemplo n.º 1
0
        public Trader AddTrader(TraderToAdd trader)
        {
            if (trader == null || trader.FirstName == null || trader.FirstName.Length == 0 || trader.FirstName.Length > 100 ||
                trader.LastName == null || trader.LastName.Length == 0 || trader.LastName.Length > 100 ||
                (trader.PhoneNumber != null && trader.PhoneNumber.Length > 50))
            {
                return(null);
            }

            return(tradersRepository.AddTrader(trader));
        }
Ejemplo n.º 2
0
        public Trader AddTrader(TraderToAdd trader)
        {
            var newTrader = context.Traders.Add(new Trader {
                FirstName = trader.FirstName,
                LastName  = trader.LastName, PhoneNumber = trader.PhoneNumber, Balance = trader.Balance
            });

            context.SaveChanges();

            return(newTrader);
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <string> > Add([FromBody] TraderToAdd trader)
        {
            var newTrader = tradersService.AddTrader(trader);

            if (newTrader != null)
            {
                return(new ActionResult <string>("New record added"));
            }
            else
            {
                //return BadRequest();
                return(new ActionResult <string>("Can't add record"));
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <string> > Post([FromBody] TraderToAdd trader)
        {
            Trader newTrader = null;

            if (trader == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            newTrader = contextProvider.Traders.Add
                            (new Trader()
            {
                FirstName = trader.FirstName, LastName = trader.LastName, Balance = trader.Balance, PhoneNumber = trader.PhoneNumber
            });

            if (newTrader != null)
            {
                try
                {
                    contextProvider.SaveChanges();
                }
                catch (Exception)
                {
                    return(BadRequest());
                }

                return("New trader added");
            }
            else
            {
                return(BadRequest());
            }
        }