Ejemplo n.º 1
0
        public void CreateAdvert(AdvertisementViewModel viewModel)
        {
            var cloudinary = CloudinaryInitialization.Initialize();

            if (viewModel.AdvertImage.Name == null)
            {
                throw new Exception("Image not found, Please add an image");
            }

            var uploadParams = new ImageUploadParams()
            {
                File = new FileDescription(viewModel.AdvertImage.FileName, viewModel.AdvertImage.OpenReadStream()),
            };

            var uploadResult = cloudinary.Upload(uploadParams);

            if (uploadResult.Error != null)
            {
                throw new Exception(uploadResult.Error.Message);
            }

            var advert = new Advert()
            {
                AdvertName          = viewModel.AdvertName,
                AdvertCompany       = viewModel.AdvertCompanyOrBrand,
                AdvertLink          = viewModel.AdvertLink,
                AdvertImageLocation = uploadResult.SecureUrl.AbsoluteUri,
            };

            DbContext.Adverts.Add(advert);
            DbContext.SaveChanges();
        }
Ejemplo n.º 2
0
        public void CreateUser(RegisterModel.InputModel viewModel, string userId)
        {
            var cloudinary = CloudinaryInitialization.Initialize();

            if (viewModel.ProfileImage.Name == null)
            {
                throw new Exception("Image not found, Please add an image");
            }

            var uploadParams = new ImageUploadParams()
            {
                File = new FileDescription(viewModel.ProfileImage.FileName, viewModel.ProfileImage.OpenReadStream()),
            };

            var uploadResult = cloudinary.Upload(uploadParams);

            if (uploadResult.Error != null)
            {
                throw new Exception(uploadResult.Error.Message);
            }

            var applicationUser = _dbContext.Users.FirstOrDefault(identityUser => identityUser.Id == userId);

            var user = new User()
            {
                FirstName         = viewModel.FirstName,
                LastName          = viewModel.LastName,
                Age               = viewModel.Age,
                ApplicationUserId = userId,
                ApplicationUser   = applicationUser,
                Resume            = null,
                ImageLocation     = uploadResult.SecureUrl.AbsoluteUri
            };

            _dbContext.ApplicationUsers.Add(user);
            _dbContext.SaveChanges();
        }