public IHttpActionResult PostTradeAccount(TradeAccount tradeAccount)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.TradeAccounts.Add(tradeAccount);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (TradeAccountExists(tradeAccount.ID))
                {
                    return Conflict();
                }
                else
                {
                    throw;
                }
            }

            return CreatedAtRoute("DefaultApi", new { id = tradeAccount.ID }, tradeAccount);
        }
Esempio n. 2
0
        public static TradeAccount Create(string name, TradeAccountType type, string cellPhoneNumber, string bankAccount)
        {
            var ta = new TradeAccount()
            {
                Name = name, BankAccount = bankAccount, CellPhoneNumber = cellPhoneNumber
            };

            //ta.Types.Add(type);
            return(ta);
        }
        public IHttpActionResult PutTradeAccount(Guid id, TradeAccount tradeAccount)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != tradeAccount.ID)
            {
                return BadRequest();
            }

            db.Entry(tradeAccount).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TradeAccountExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }