Exemple #1
0
        public IHttpActionResult PutPorfolioStock(int id, PorfolioStock porfolioStock)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != porfolioStock.StockId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #2
0
        public User Create(DBContext.User user, string password)
        {
            // validation
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("Password is required");
            }

            if (dbContext.Users.Any(x => x.UserName == user.UserName))
            {
                throw new AppException("UserName " + user.UserName + " is already taken");
            }

            //byte[] passwordHash, passwordSalt;
            //CreatePasswordHash(password, out passwordHash, out passwordSalt);

            //user.PasswordHash = passwordHash;
            //user.PasswordSalt = passwordSalt;

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            return(user);
        }