Example #1
0
        public async Task <int> AddListingPhotoAsync(ListingPhotoRequest request)
        {
            int count = _repository.ListingPhotoRepo.FindByCondition(x => x.ListingId == request.ListingId).ToList().Count;

            if (count >= 5)
            {
                return(0);
            }

            var listingPhoto = new ListingPhoto()
            {
                ListingId = request.ListingId,
                IsDefault = request.IsDefault
            };

            if (request.PhotoFile != null)
            {
                listingPhoto.PhotoUrl = await SaveFile(request.PhotoFile);
            }

            await _repository.ListingPhotoRepo.CreateAsync(listingPhoto);

            await _repository.SaveChangesAsync();

            return(listingPhoto.Id);
        }
Example #2
0
        public async Task <IActionResult> CreatePhoto(ListingPhotoRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index", "Listing"));
            }

            var result = await _listingsController.CreatePhoto(request);

            if (result == 1)
            {
                TempData["CreatePhotoStatus"] = "Success";
            }

            return(Redirect("/ListingDetail/Index/" + request.ListingId.ToString()));
        }
Example #3
0
        public async Task <int> CreatePhoto([FromForm] ListingPhotoRequest request)
        {
            var result = await _listingService.AddListingPhotoAsync(request);

            return(result);
        }