public IActionResult Create(ExperienceCreateViewModel experienceCreateVM)
        {
            if (ModelState.IsValid)//
            {
                var product = new Product
                {
                    ProductName = experienceCreateVM.ProductName,
                    CategoryID  = int.Parse(experienceCreateVM.CategoryID)
                };

                var addedProduct = _productRepository.AddProduct(product);

                string uniqueFileName = PhotoHelper.SaveImageAndReturnUniqueFileName(experienceCreateVM.Photo, _hostingEnvironment, "images/products");

                var experience = new Experience
                {
                    ProductID      = addedProduct.ProductID,
                    Evaluation     = experienceCreateVM.Evaluation,
                    Describe       = experienceCreateVM.Describe,
                    Recommendation = experienceCreateVM.Recommendation,
                    UserName       = User.FindFirst(ClaimTypes.Name).Value,
                    PhotoPath      = uniqueFileName,
                    Date           = DateTime.Now
                };


                var addedExperience = _experienceRepository.AddExperience(experience);
                return(RedirectToAction("details", new { experienceID = addedExperience.ExperienceID }));
            }

            return(View());
        }
Ejemplo n.º 2
0
        public async Task CreateAsync_WithCorrectInput_ShouldReturnEntity()
        {
            await this.SeedData(this.context);

            string testUserId     = this.context.Users.First().Id;
            int    testLocationId = this.context.Locations.First().Id;

            var input = new ExperienceCreateViewModel()
            {
                Title       = "Test",
                Description = "Description of test",
                AuthorId    = testUserId,
                LocationId  = testLocationId,
            };

            var resultId = await this.experienceService.CreateAsync(input);

            Assert.True(resultId == 3, "Create method does not work correctly");
        }
        public async Task <int> CreateAsync(ExperienceCreateViewModel input)
        {
            var experience = new Experience()
            {
                Title       = input.Title,
                Description = input.Description,
                AuthorId    = input.AuthorId,
                Guide       = input.Guide,
                Intensity   = input.Intensity,
                DateOfVisit = input.DateOfVisit,
                LocationId  = input.LocationId,
            };

            await this.experienceRepository.AddAsync(experience);

            var result = await this.experienceRepository.SaveChangesAsync();

            return(experience.Id);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create(ExperienceCreateViewModel input)
        {
            if (!this.ModelState.IsValid)
            {
                this.ViewBag.Messages = new[] {
                    new AlertViewModel("danger", "Warning!", "You have entered invalid data!"),
                };
                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            var experienceId = await this.experiencesService.CreateAsync(input);

            if (input.Images != null)
            {
                input.Images.ExperienceId = experienceId;
                var path = this.env.WebRootPath;
                await this.imagesService.AddImagesAsync(input.Images, path);
            }

            return(this.Redirect($"/Experiences/List?locationId={input.LocationId}&status=success"));
        }