public async Task ShouldGetVenueById()
        {
            CreateVenues();

            VenueService    venueService    = new VenueService(_dbContext, _mainEventProvider);
            SecurityService securityService = new SecurityService(_dbContext, _userManager, _roleManager);
            VenueController venueController = new VenueController(venueService, securityService);

            SetUser(venueController, _createdUser2.Entity.Id);

            ActionResult <VenueVm> result1 = await venueController.GetVenueAsync(1);

            VenueVm returnedVenue1 = result1.Value;

            Assert.AreEqual(1, returnedVenue1.Id);
            Assert.AreEqual("Venue 1", returnedVenue1.Name);
            Assert.AreEqual("Venue gate 123", returnedVenue1.Address);
            Assert.AreEqual("1236", returnedVenue1.PostalCode);
            Assert.AreEqual("12345678", returnedVenue1.ContactPhone);
            Assert.AreEqual("*****@*****.**", returnedVenue1.ContactEMail);

            ActionResult <VenueVm> result2 = await venueController.GetVenueAsync(2);

            VenueVm returnedVenue2 = result2.Value;

            Assert.AreEqual(2, returnedVenue2.Id);
            Assert.AreEqual(_venueName2, returnedVenue2.Name);
            Assert.AreEqual(_venueAddress2, returnedVenue2.Address);
            Assert.AreEqual(_postalCode2, returnedVenue2.PostalCode);
            Assert.AreEqual(_contactPhone2, returnedVenue2.ContactPhone);
            Assert.AreEqual(_contactEMail2, returnedVenue2.ContactEMail);
        }
        public async Task ShouldUpdateVenue()
        {
            string newVenueName    = "Venue name ";
            string newVenueAddress = "Testing gate 216";

            VenueService    venueService    = new VenueService(_dbContext, _mainEventProvider);
            SecurityService securityService = new SecurityService(_dbContext, _userManager, _roleManager);
            VenueController venueController = new VenueController(venueService, securityService);

            CreateUser();
            CreateVenues();
            SetUser(venueController, _createdUser.Entity.Id);

            VenueVm venueVm = new VenueVm {
                Id = 2, Name = newVenueName, Address = newVenueAddress, PostalCode = _postalCode2, ContactEMail = _contactEMail2, ContactPhone = _contactPhone2, OrganizerId = 2
            };

            await venueController.UpdateVenueAsync(venueVm);

            // Check that only one has been changed
            Venue venue2 = _dbContext.Venues.Find(2);

            Assert.AreEqual(newVenueName, venue2.Name);
            Assert.AreEqual(newVenueAddress, venue2.Address);
        }
        public async Task ShouldCreateVenue()
        {
            string venueName3    = "Venue name 3";
            string venueAddress3 = "Testing gate 215";


            VenueService    venueService    = new VenueService(_dbContext, _mainEventProvider);
            SecurityService securityService = new SecurityService(_dbContext, _userManager, _roleManager);
            VenueController venueController = new VenueController(venueService, securityService);

            CreateUser();
            CreateVenues();
            SetUser(venueController, _createdUser2.Entity.Id);


            VenueVm venueVm = new VenueVm {
                Name = venueName3, Address = venueAddress3, PostalCode = "0258", ContactEMail = "*****@*****.**", ContactPhone = "1234578", OrganizerId = 2
            };

            await venueController.CreateVenueAsync(venueVm);

            ActionResult <List <VenueListVm> > result = await venueController.GetVenuesAsync();

            List <VenueListVm> venues = (List <VenueListVm>)((OkObjectResult)result.Result).Value;
            Venue createdVenue        = _dbContext.Venues.Find(3);

            Assert.AreEqual(3, venues.Count);
            Assert.That(venues, Has.Exactly(1).Matches <VenueListVm>(venue => venue.Id == createdVenue.Id &&
                                                                     venue.Name == createdVenue.Name &&
                                                                     venue.Address == createdVenue.Address
                                                                     ));
        }
Example #4
0
        public async Task <ActionResult> UpdateVenueAsync(VenueVm venueVm)
        {
            await _venueService.UpdateVenueAsync(venueVm);

            Log.Information("Venue {@venueVm} updated", venueVm);
            return(Ok());
        }
Example #5
0
        public async Task <VenueVm> UpdateVenueAsync(VenueVm venue)
        {
            var result = await _venueService.UpdateVenueAsync(venue).ConfigureAwait(false);

            _cache.Remove(nameof(GetAllVenuesAsync));

            return(result);
        }
Example #6
0
 public static Venue Extend(this Venue original, VenueVm venue)
 => new Venue
 {
     Id      = original.Id,
     Name    = venue.Name,
     Address = venue.Address,
     MapUrl  = venue.MapUrl
 };
Example #7
0
        public async Task <VenueVm> UpdateVenueAsync(VenueVm venue)
        {
            venue.EnsureIsValid();
            var original = await _venueProvider.GetVenueOrDefaultAsync(venue.Id).ConfigureAwait(false);

            var res = await _venueProvider.SaveVenueAsync(original.Extend(venue)).ConfigureAwait(false);

            return(res.ToVm());
        }
Example #8
0
 public static Venue Extend(this Venue original, VenueVm venue)
 {
     return(new Venue
     {
         Id = original.Id,
         ExportId = venue.Id,
         Name = venue.Name,
         City = venue.City,
         Address = venue.Address,
         MapUrl = venue.MapUrl
     });
 }
Example #9
0
        public async Task <ActionResult> CreateVenueAsync(VenueVm venueVm)
        {
            var userId     = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var organizers = await _securityService.GetOrganizersUserIsAdminAtAsync(userId);

            if (!organizers.Any(a => a.Id == venueVm.OrganizerId))
            {
                return(Forbid());
            }

            await _venueService.CreateVenueAsync(venueVm);

            Log.Information("Venue {@venueVm} saved to db", venueVm);
            return(Ok());
        }
Example #10
0
        public async Task <VenueVm> UpdateVenueAsync(VenueVm venue)
        {
            venue.EnsureIsValid();

            var original = await _venueProvider.GetVenueOrDefaultAsync(venue.Id).ConfigureAwait(false);

            original.ExportId = venue.Id;
            original.Name     = venue.Name;
            original.City     = venue.City;
            original.Address  = venue.Address;
            original.MapUrl   = venue.MapUrl;
            await _unitOfWork.SaveChangesAsync();

            return(original.ToVm());
        }
Example #11
0
        public async Task <VenueVm> AddVenueAsync(VenueVm venue)
        {
            venue.EnsureIsValid();

            var original = await _venueProvider.GetVenueOrDefaultAsync(venue.Id).ConfigureAwait(false);

            if (original != null)
            {
                throw new FormatException($"Данный {nameof(venue.Id)} \"{venue.Id}\" уже занят");
            }

            var entity = new Venue {
                Id = venue.Id
            }.Extend(venue);
            var res = await _venueProvider.SaveVenueAsync(entity).ConfigureAwait(false);

            return(res.ToVm());
        }
Example #12
0
        public static VenueVm EnsureIsValid(this VenueVm venue)
        {
            // todo: implement full validation
            if (string.IsNullOrWhiteSpace(venue.Name))
            {
                throw new FormatException(nameof(venue.Name));
            }

            if (string.IsNullOrWhiteSpace(venue.Address))
            {
                throw new FormatException(nameof(venue.Address));
            }

            if (venue.City != venue.Id.GetCity())
            {
                throw new FormatException(nameof(venue.City));
            }

            return(venue);
        }
Example #13
0
        /// <summary>
        /// Update specific venue
        /// </summary>
        /// <param name="venueVm"></param>
        public async Task UpdateVenueAsync(VenueVm venueVm)
        {
            var existingVenue = _dbContext.Venues.Where(a => a.Id == venueVm.Id).SingleOrDefault();

            if (existingVenue == null)
            {
                throw new HttpException(HttpStatusCode.NotFound, $"Fant ingen lokaler med navn: {venueVm.Name}");
            }

            existingVenue.Id           = venueVm.Id;
            existingVenue.Name         = venueVm.Name;
            existingVenue.Address      = venueVm.Address;
            existingVenue.PostalCode   = venueVm.PostalCode;
            existingVenue.OrganizerId  = venueVm.OrganizerId;
            existingVenue.ContactName  = venueVm.ContactName;
            existingVenue.ContactEMail = venueVm.ContactEMail;
            existingVenue.ContactPhone = venueVm.ContactPhone;

            _dbContext.Update <Venue>(existingVenue);
            await _dbContext.SaveChangesAsync();
        }
Example #14
0
        /// <summary>
        /// Create a Venue.
        /// </summary>
        /// <param name="venueVm"></param>
        /// <returns>VenueVm</returns>
        public async Task CreateVenueAsync(VenueVm venueVm)
        {
            var existingVenue = await _dbContext.Venues.Where(a => a.Name == venueVm.Name && a.OrganizerId == venueVm.OrganizerId).SingleOrDefaultAsync();

            if (existingVenue != null)
            {
                throw new HttpException(HttpStatusCode.Conflict, $"Lokalet med navn: {venueVm.Name} eksisterer allerede");
            }

            var venue = new Venue
            {
                Name         = venueVm.Name,
                Address      = venueVm.Address,
                PostalCode   = venueVm.PostalCode,
                OrganizerId  = venueVm.OrganizerId,
                ContactName  = venueVm.ContactName,
                ContactPhone = venueVm.ContactPhone,
                ContactEMail = venueVm.ContactEMail
            };

            _dbContext.Venues.Add(venue);
            await _dbContext.SaveChangesAsync();
        }
Example #15
0
 public Task <VenueVm> UpdateVenue([FromBody] VenueVm venue)
 => _venueService.UpdateVenueAsync(venue);
Example #16
0
 public Task <VenueVm> AddVenue([FromBody] VenueVm venue)
 => _venueService.AddVenueAsync(venue);
Example #17
0
        public async Task <CompositeModel> GetMeetup([FromRoute] string meetupId, [FromBody] RandomConcatModel descriptor = null)
        {
            var meetup = await _meetupService.GetMeetupAsync(meetupId).ConfigureAwait(true);

            descriptor            = descriptor ?? new RandomConcatModel();
            descriptor.VenueId    = descriptor.VenueId;
            descriptor.Sessions   = descriptor.Sessions ?? new List <SessionVm>();
            descriptor.TalkIds    = descriptor.TalkIds ?? new List <string>();
            descriptor.SpeakerIds = descriptor.SpeakerIds ?? new List <string>();
            descriptor.FriendIds  = descriptor.FriendIds ?? new List <string>();

            if (meetup != null && descriptor.Sessions.Count == 0)
            {
                descriptor.Sessions = meetup.Sessions;
            }

            descriptor.TalkIds.AddRange(descriptor.Sessions.Select(x => x.TalkId).Where(x => !string.IsNullOrWhiteSpace(x)));

            // talks
            var talks = new Dictionary <string, TalkVm>();

            foreach (var talkId in descriptor.TalkIds.Distinct())
            {
                var talk = await _talkService.GetTalkAsync(talkId).ConfigureAwait(true);

                talks.Add(talkId, talk);
            }

            // speakers
            descriptor.SpeakerIds.AddRange(
                talks.Select(x => x.Value).SelectMany(x => x.SpeakerIds.Select(s => s.SpeakerId))
                );
            var speakers = new Dictionary <string, SpeakerVm>();

            foreach (var speakerId in descriptor.SpeakerIds.Distinct())
            {
                var speaker = await _speakerService.GetSpeakerAsync(speakerId).ConfigureAwait(true);

                speakers.Add(speakerId, speaker);
            }

            // friends
            if (meetup != null && descriptor.FriendIds.Count == 0)
            {
                descriptor.FriendIds.AddRange(meetup.FriendIds.Select(x => x.FriendId));
            }

            var friends = new List <Friend>();

            foreach (var friendId in descriptor.FriendIds.Distinct())
            {
                var friend = await _friendService.GetFriendAsync(friendId).ConfigureAwait(true);

                friends.Add(friend);
            }

            // name
            if (string.IsNullOrWhiteSpace(descriptor.Name))
            {
                descriptor.Name = meetup?.Name;
            }

            // venue
            descriptor.VenueId = descriptor.VenueId ?? meetup?.VenueId;
            VenueVm venue = null;

            if (!string.IsNullOrWhiteSpace(descriptor.VenueId))
            {
                venue = await _venueService.GetVenueAsync(descriptor.VenueId).ConfigureAwait(true);
            }

            // community
            if (string.IsNullOrWhiteSpace(descriptor.CommunityId))
            {
                descriptor.CommunityId = meetup?.CommunityId.ToString();
            }

            return(new CompositeModel
            {
                Id = meetup?.Id,
                Name = descriptor.Name,
                CommunityId = string.IsNullOrWhiteSpace(descriptor.CommunityId)
                    ? (Community?)null
                    : descriptor.CommunityId.GetCommunity(),
                Venue = venue,
                Sessions = descriptor.Sessions,
                Talks = talks,
                Speakers = speakers,
                Friends = friends
            });
        }