Exemplo n.º 1
0
        public IActionResult Post([FromBody] Image imageModel)
        {
            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    stream   = new MemoryStream(imageModel.ImageArray);
            var    guid     = Guid.NewGuid().ToString();
            var    file     = $"{guid}.jpg";
            string folder   = "wwwroot";
            var    response = FilesHelper.UploadImage(stream, folder, file);

            if (!response)
            {
                return(BadRequest());
            }
            else
            {
                Image image = new Image()
                {
                    ImageUrl  = file,
                    VehicleId = imageModel.VehicleId
                };
                _cWheelsDbContext.Images.Add(image);
                _cWheelsDbContext.SaveChanges();
                return(StatusCode(StatusCodes.Status201Created));
            }
        }
Exemplo n.º 2
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 vehicleObj = new Vehicle()
            {
                Title       = vehicle.Title,
                Description = vehicle.Description,
                Color       = vehicle.Color,
                Company     = vehicle.Company,
                Condition   = vehicle.Condition,
                DatePosted  = vehicle.DatePosted,
                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(vehicleObj);
            _cWheelsDbContext.SaveChanges();

            return(Ok(new { vehicleId = vehicleObj.Id, message = "Vehicle Added Successfully" }));
        }
        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));
        }
Exemplo n.º 4
0
 public void Post([FromBody] Vehicle vehicle)
 {
     _cWheelDbContext.Vehicles.Add(vehicle);
     _cWheelDbContext.SaveChanges();
 }
Exemplo n.º 5
0
 public IActionResult Post([FromBody] Vehicle vehicle)
 {
     _cWheelsDbContext.Vehicles.Add(vehicle);
     _cWheelsDbContext.SaveChanges();
     return(StatusCode(StatusCodes.Status201Created));
 }