Beispiel #1
0
        public async Task <int> CreateListing(CreateListingRequest request, int userId)
        {
            Listing listing = new Listing
            {
                Title    = request.Title,
                About    = request.About,
                Currency = Currencies.GBP,
                UserId   = userId,
                Price    = request.Price,
                Created  = DateTime.Now,
                Status   = Models.Domain.Status.Open,
            };

            listing.Id = await _listingRepository.AddListing(listing);

            await _listingRepository.AddSearchTags(request.SearchTags, listing.Id);

            List <SearchTagType> searchTagTypes = await _listingRepository.GetRelatedSearchTagsForListing(listing.Id);

            ElasticListing elasticListing = (ElasticListing)listing;

            elasticListing.Tags = ElasticListing.SearchTagTypesToElasticTags(searchTagTypes);
            IndexResponse indexListing = await _elastic.IndexDocumentAsync(elasticListing);

            return(listing.Id);
        }
Beispiel #2
0
        public async Task <UserListingDto> AddListingCommand(AddListingDto addListingDto, string UserFullName,
                                                             string UserId)
        {
            try
            {
                var listing = new UserListings
                {
                    CountryRefId       = (int)addListingDto.ListingCountry,
                    ProvinceRefId      = (int)addListingDto.ListingProvince,
                    CityRefId          = (int)addListingDto.ListingCity,
                    ListingTypeRefId   = (int)addListingDto.ListingType,
                    CountryName        = EnumHelper.GetCountryEnumString((int)addListingDto.ListingCountry),
                    ProvinceName       = EnumHelper.GetProvinceEnumString((int)addListingDto.ListingProvince),
                    CityName           = EnumHelper.GetCityEnumString((int)addListingDto.ListingCity),
                    ListingName        = EnumHelper.GetListingEnumString((int)addListingDto.ListingType),
                    ListingDescription = addListingDto.ListingDescription,
                    ListingTitle       = addListingDto.ListingTitle,
                    Address            = addListingDto.Address,
                    Email           = addListingDto.Email,
                    PhoneNumber     = addListingDto.PhoneNumber,
                    FullName        = addListingDto.FullName,
                    OwnerId         = UserId,
                    ListingDate     = DateTime.Now,
                    LastUpdatedDate = DateTime.Now
                };

                var addListing = await _listingRepository.AddListing(listing);

                var newListing = new UserListingDto
                {
                    Address            = addListing.Address,
                    City               = EnumHelper.GetCityEnumString((int)addListing.CityRefId),
                    Country            = EnumHelper.GetCountryEnumString((int)addListing.CountryRefId),
                    Province           = EnumHelper.GetProvinceEnumString((int)addListing.ProvinceRefId),
                    Email              = addListing.Email,
                    FullName           = addListing.FullName,
                    PhoneNumber        = addListing.PhoneNumber,
                    LastUpdatedDate    = addListing.LastUpdatedDate,
                    ListingDate        = addListing.ListingDate,
                    ListingDescription = addListing.ListingDescription,
                    ListingTitle       = addListing.ListingTitle,
                    ListingType        = EnumHelper.GetListingEnumString((int)addListing.ListingTypeRefId),
                    UserListingId      = addListing.UserListingId,
                    OwnerId            = addListing.OwnerId,
                    ListingEnabled     = addListing.ListingEnabled
                };

                return(newListing);
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
Beispiel #3
0
        async public Task <IActionResult> AddNewListing(Listing newListing)
        {
            newListing.TimeOfPosting = DateTime.Now;
            var user = await userManager.GetUserAsync(User);

            newListing.UserID = user.Id;

            listingRepository.AddListing(newListing);

            return(RedirectToAction("Listings"));
        }
        public HttpResponseMessage PostListing(ListingDetailDTO listingDTO)
        {
            Listing listToAdd = mapper.CreateListingEntity(listingDTO);

            listToAdd = listingRepo.AddListing(listToAdd);
            var    response = Request.CreateResponse <ListingDetailDTO>(HttpStatusCode.Created, mapper.CreateListingDetailDTO(listToAdd));
            string uri      = Url.Link("DefaultApi", new { id = listToAdd.Id });

            response.Headers.Location = new Uri(uri);
            return(response);
        }
        public ActionResult <ListingDTO> AddListing(ListingDTO ldto)
        {
            var owner = GetOwner();

            try{
                Animal an = _aRepo.GetAnimal(ldto.AnimalID);

                if (an == null)
                {
                    throw new Exception("The specified animal could not be found");
                }

                if (an.Owner != owner)
                {
                    throw new InvalidListingException("You can't put up someone elses animal for sale or breeding.");
                }

                if (_listingRepo.AnimalIsInListing(an))
                {
                    throw new InvalidListingException("This animal is already in a listing");
                }

                Listing listing;

                if (ldto.BreedAmount == 0 && ldto.AdoptAmount == 0)
                {
                    listing = new Listing(an, ldto.IsAdoptable, ldto.IsBreedable);
                }
                else
                {
                    listing = new Listing(an, ldto.IsAdoptable, ldto.IsBreedable
                                          , ldto.AdoptAmount, ldto.BreedAmount);
                }

                _listingRepo.AddListing(listing);
                _listingRepo.SaveChanges();

                var list = _listingRepo.GetListingWithID(listing.ID);
                return(CreatedAtAction(nameof(GetListingWithID), new { id = listing.ID }
                                       , new ListingDTO(list)));
            }catch (Exception e) {
                ModelState.AddModelError("Error", e.Message);
                return(BadRequest(ModelState));
            }
        }
Beispiel #6
0
        public async Task AddListingAsync(ListingInputModel inputModel)
        {
            if (inputModel != null)
            {
                var listing = new Listing
                {
                    Car       = new Car(),
                    RepairJob = new RepairJob()
                };

                _listingRepository.TrackListing(listing);
                await MapListingValues(inputModel, listing);

                _carService.MapCarValues(inputModel.Car, listing.Car);
                _repairJobService.MapRepairJobValues(inputModel.RepairJob, listing.RepairJob);
                _mediaService.UpdateMediaCollection(inputModel.ImgNames, listing);

                listing.DateCreated     = DateTime.Today;
                listing.DateLastUpdated = DateTime.Today;

                _listingRepository.AddListing(listing);
            }
        }