Beispiel #1
0
        public IActionResult Post(Vehicle vehicle)
        {
            var userEmail = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email).Value;
            var user      = _cWheelsDBContext.Users.FirstOrDefault(u => u.Email == userEmail);

            if (user == null)
            {
                return(NotFound());
            }

            var vehObj = new Vehicle()
            {
                Title       = vehicle.Title,
                Description = vehicle.Description,
                Color       = vehicle.Color,
                Company     = vehicle.Company,
                Condition   = vehicle.Condition,
                DatePosted  = new DateTime(),
                Engine      = vehicle.Engine,
                Price       = vehicle.Price,
                Model       = vehicle.Model,
                Location    = vehicle.Location,
                CategoryId  = vehicle.CategoryId,
                IsFeatured  = false,
                IsHotAndNew = false,
                UserId      = user.Id,
            };

            _cWheelsDBContext.Vehicles.Add(vehObj);
            _cWheelsDBContext.SaveChanges();

            return(Ok(new { vehicleId = vehObj.Id, message = "Vehicle added successfully." }));
        }
Beispiel #2
0
        public IActionResult Register([FromBody] User user)
        {
            var userWithSameEmail = _cWheelsDBContext.Users.Where(u => u.Email == user.Email).SingleOrDefault();

            if (userWithSameEmail != null)
            {
                return(BadRequest("User with same email already exists!"));
            }

            var userObj = new User()
            {
                Name     = user.Name,
                Email    = user.Email,
                Password = SecurePasswordHasherHelper.Hash(user.Password)
            };

            _cWheelsDBContext.Users.Add(userObj);
            _cWheelsDBContext.SaveChanges();

            return(StatusCode(StatusCodes.Status201Created));
        }