public async Task <FacilityResponse> SaveAsync(Facility facility)
        {
            try
            {
                await _FacilityRepository.AddAsync(facility);

                await _UnitOfWork.CompleteAsync();

                return(new FacilityResponse(facility));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new FacilityResponse($"An error occurred when saving the facility: {ex.Message}"));
            }
        }
        public async Task <int> Handle(CreateFacilityCommand request, CancellationToken cancellationToken)
        {
            var facility = Domain.Models.Facility.NewFacility(
                securityContext.GetCurrentTenant(),
                request.Name,
                request.Description,
                request.StreetAddress,
                request.Latitude,
                request.Longitude,
                request.Images);

            facility.Id = await repository.AddAsync(facility);

            await repository.SaveChangesAsync(facility, context);

            return(facility.Id);
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("FacilityId,FacilityName,VenueId,SportId")] Facility facility)
        {
            if (facilityRepository.GetAllAsync().Where(f => f.SportId.Equals(facility.SportId) && f.VenueId.Equals(facility.VenueId)).Any(f => f.FacilityName == facility.FacilityName))
            {
                ModelState.AddModelError("FacilityName", "Facility for this sport already exists at this venue. Please enter another facility name.");
            }
            else if (ModelState.IsValid)
            {
                facility = await facilityRepository.AddAsync(facility);

                await auditLogger.log(GetUserId(), $"Created facility {facility.FacilityId}");

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["SportId"] = new SelectList(sportRepository.GetAllAsync(), "SportId", "SportName", facility.SportId);
            ViewData["VenueId"] = new SelectList(venueRepository.GetAllAsync(), "VenueId", "VenueName", facility.VenueId);
            return(View(facility));
        }