Esempio n. 1
0
        public IHttpActionResult PostAccount(AccountViewModel newAccount)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Account account = Mapper.Map<AccountViewModel, Account>(newAccount);
            db.Accounts.Add(account);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = account.Id }, new { data = account });
        }
Esempio n. 2
0
        public IHttpActionResult PutAccount(int id, AccountViewModel newAccount)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != newAccount.Id)
            {
                return BadRequest();
            }

            Account account = Mapper.Map<AccountViewModel, Account>(newAccount);
            db.Entry(account).State = EntityState.Modified;

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

            return StatusCode(HttpStatusCode.NoContent);
        }