示例#1
0
        public async Task <IActionResult> Edit(int id, VenueEditInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            try
            {
                await this.venuesService.EditAsync(id, input);

                this.TempData["Success"] = EditSuccessMessage;
                return(this.Redirect("/Venues/Details/" + id));
            }
            catch (Exception e)
            {
                this.TempData["Error"] = e.Message;

                return(this.View(input));
            }
        }
        public async Task EditeAsyncWithDublicateNameShouldThrowArgumentException()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext        = new ApplicationDbContext(options);
            var cloudinary       = new Mock <ICloudinaryService>();
            var venuesRepository = new EfDeletableEntityRepository <Venue>(dbContext);
            var venuesService    = new VenuesService(venuesRepository, cloudinary.Object);
            var photo            = new Mock <IFormFile>();

            await venuesRepository.AddAsync(new Venue
            {
                Name     = "Port Varna",
                ImgUrl   = "https://res.cloudinary.com/nikolacgeorgiev/image/upload/v1587377702/venues_photos/Port_Varna_t44ryy.jpg",
                Country  = "Bulgaria",
                City     = "Varna",
                Address  = "Sq. Slaveykov 1",
                Capacity = 30000,
            });

            await venuesRepository.SaveChangesAsync();

            var id = await venuesService.CreateAsync("Rowing Canal", photo.Object, "Bulgaria", "Plovdiv", "Yasna Polyana", 70000);

            var venue = new VenueEditInputModel
            {
                Name     = "Port Varna",
                ImgUrl   = "https://res.cloudinary.com/nikolacgeorgiev/image/upload/v1587377745/venues_photos/Rowing_Canal_g5uvuq.jpg",
                Country  = "Bulgaria",
                City     = "Plovdiv",
                Address  = "Yasna Polyana",
                Capacity = 70000,
            };

            await Assert.ThrowsAsync <ArgumentException>(async() =>
            {
                await venuesService.EditAsync(id, venue);
            });
        }