private AuctionCreatorDetailsModel SetAuctionCreatorDetails(AuctionDetailsModel details)
 {
     return(new AuctionCreatorDetailsModel
     {
         AuctionCreatorName = details.AuctionCreator.Name,
         AuctionCreatorAddress = details.AuctionCreator.ContactAddress,
         AuctionCreatorEmail = details.AuctionCreator.ContactEmail,
         AuctionCreatorPhone = details.AuctionCreator.ContactPhone,
         AuctionRequirements = details.Auction.Requirements
     });
 }
 private AboutAuctionDetailsModel SetAboutAuctionDetails(AuctionDetailsModel details, string auctionFormatName, Tuple <List <string>, List <AuctionDocumentModel> > auctionFiles)
 {
     return(new AboutAuctionDetailsModel
     {
         AuctionName = details.Auction.Name,
         AuctionStartingPrice = details.Auction.StartingPrice,
         AuctionValueAddedTax = details.Auction.ValueAddedTax ? "Ir" : "Nav",
         AuctionStartDate = details.Auction.StartDate,
         AuctionApplyTillDate = details.Auction.ApplyTillDate,
         AuctionEndDate = details.Auction.EndDate,
         AuctionFormat = auctionFormatName,
         AuctionExternalWebsite = details.Auction.AuctionExternalWebsite,
         ItemEvaluation = details.AuctionDetails.Evaluation,
         AuctionImageUrls = auctionFiles.Item1,
         AuctionDocuments = auctionFiles.Item2
     });
 }
        public async Task <AuctionDetailsResponseModel> DetailsAsync(AuctionDetailsRequestModel request)
        {
            // check if auction exists and only then do the full join
            bool auctionExists = await m_context.Auctions.AnyAsync(auct => auct.AuctionId == request.AuctionId).ConfigureAwait(true);

            if (auctionExists)
            {
                AuctionDetailsModel details = await(
                    from auct in m_context.Auctions
                    join aitem in m_context.AuctionItems on auct.AuctionId equals aitem.AuctionId
                    join adet in m_context.AuctionDetails on aitem.AuctionItemId equals adet.AuctionItemId
                    join acrea in m_context.AuctionCreators on auct.AuctionCreatorId equals acrea.AuctionCreatorId
                    where auct.AuctionId == request.AuctionId
                    select new AuctionDetailsModel
                {
                    Auction        = auct,
                    AuctionItem    = aitem,
                    AuctionDetails = adet,
                    AuctionCreator = acrea
                }
                    ).FirstOrDefaultAsync().ConfigureAwait(true);

                if (details.Auction.AuctionCategoryId == AuctionCategories.Item)
                {
                    return(await SetupItemAuctionDetailsAsync(details, request).ConfigureAwait(true));
                }

                if (details.Auction.AuctionCategoryId == AuctionCategories.Vehicle)
                {
                    return(await SetupVehicleAuctionDetailsAsync(details, request).ConfigureAwait(true));
                }

                if (details.Auction.AuctionCategoryId == AuctionCategories.Property)
                {
                    return(await SetupPropertyAuctionDetailsAsync(details, request).ConfigureAwait(true));
                }

                throw new WebApiException(HttpStatusCode.BadRequest, AuctionErrorMessages.MissingAuctionsInformation);
            }
            else
            {
                throw new WebApiException(HttpStatusCode.BadRequest, AuctionErrorMessages.IncorrectAuction);
            }
        }
        private async Task <AuctionDetailsResponseModel> SetupPropertyAuctionDetailsAsync(AuctionDetailsModel details, AuctionDetailsRequestModel request)
        {
            string auctionFormatName   = LoadAuctionFormatName(details.Auction.AuctionFormatId);
            string measurementTypeName = details.AuctionDetails.MeasurementTypeId.IsNotSpecified() ? null : LoadPropertyMeasurementTypeName(details.AuctionDetails.MeasurementTypeId.Value);
            string regionName          = details.AuctionDetails.RegionId.IsNotSpecified() ? null : LoadPropertyRegionName(details.AuctionDetails.RegionId.Value);

            Tuple <List <string>, List <AuctionDocumentModel> > auctionFiles = await LoadAuctionFilesAsync(request.AuctionId).ConfigureAwait(true);

            return(new AuctionDetailsResponseModel
            {
                AboutAuctionDetails = SetAboutAuctionDetails(details, auctionFormatName, auctionFiles),
                PropertyAuction = new PropertyAuctionDetailsModel
                {
                    PropertyCoordinates = details.AuctionDetails.Coordinates,
                    PropertyRegionName = regionName,
                    PropertyCadastreNumber = details.AuctionDetails.CadastreNumber.Value,
                    PropertyMeasurementValue = details.AuctionDetails.MeasurementValue.Value,
                    PropertyMeasurementTypeName = measurementTypeName,
                    PropertyAddress = details.AuctionDetails.Address,
                    PropertyFloorCount = details.AuctionDetails.FloorCount ?? null,
                    PropertyRoomCount = details.AuctionDetails.RoomCount ?? null
                },
                AboutAuctionCreator = SetAuctionCreatorDetails(details)
            });
        }
        private async Task <AuctionDetailsResponseModel> SetupItemAuctionDetailsAsync(AuctionDetailsModel details, AuctionDetailsRequestModel request)
        {
            string auctionFormatName = LoadAuctionFormatName(details.Auction.AuctionFormatId);
            string conditionName     = details.AuctionDetails.ConditionId.IsNotSpecified() ? null : LoadItemConditionName(details.AuctionDetails.ConditionId.Value);
            string companyTypeName   = details.AuctionDetails.CompanyTypeId.IsNotSpecified() ? null : LoadCompanyTypeName(details.AuctionDetails.CompanyTypeId.Value);

            Tuple <List <string>, List <AuctionDocumentModel> > auctionFiles = await LoadAuctionFilesAsync(request.AuctionId).ConfigureAwait(true);

            return(new AuctionDetailsResponseModel
            {
                AboutAuctionDetails = SetAboutAuctionDetails(details, auctionFormatName, auctionFiles),
                ItemAuction = new ItemAuctionDetailsModel
                {
                    ItemModel = details.AuctionDetails.Model,
                    ItemManufacturingYear = details.AuctionDetails.ManufacturingYear ?? null,
                    ItemConditionName = conditionName,
                    ItemStartingPrice = details.Auction.StartingPrice,
                    ItemVolume = details.AuctionDetails.Volume,
                    ItemCompanyType = companyTypeName
                },
                AboutAuctionCreator = SetAuctionCreatorDetails(details)
            });
        }
        private async Task <AuctionDetailsResponseModel> SetupVehicleAuctionDetailsAsync(AuctionDetailsModel details, AuctionDetailsRequestModel request)
        {
            string auctionFormatName = LoadAuctionFormatName(details.Auction.AuctionFormatId);
            string transmissionName  = details.AuctionDetails.TransmissionId.IsNotSpecified() ? null : LoadVehicleTransmissionName(details.AuctionDetails.TransmissionId.Value);
            string fuelTypeName      = details.AuctionDetails.FuelTypeId.IsNotSpecified() ? null : LoadVehicleFuelTypeName(details.AuctionDetails.FuelTypeId.Value);
            string dimensionName     = details.AuctionDetails.DimensionTypeId.IsNotSpecified() ? null : LoadVehicleDimensionTypeName(details.AuctionDetails.DimensionTypeId.Value);
            string inspectionActive  = details.AuctionDetails.InspectionActive.HasValue && details.AuctionDetails.InspectionActive.Value ? "Ir" : "Nav";


            Tuple <List <string>, List <AuctionDocumentModel> > auctionFiles = await LoadAuctionFilesAsync(request.AuctionId).ConfigureAwait(true);

            return(new AuctionDetailsResponseModel
            {
                AboutAuctionDetails = SetAboutAuctionDetails(details, auctionFormatName, auctionFiles),
                VehicleAuction = new VehicleAuctionDetailsModel
                {
                    VehicleMake = details.AuctionDetails.Make,
                    VehicleModel = details.AuctionDetails.Model,
                    VehicleManufacturingYear = details.AuctionDetails.ManufacturingYear.Value,
                    VehicleRegistrationNumber = details.AuctionDetails.RegistrationNumber,
                    VehicleIdentificationNumber = details.AuctionDetails.IdentificationNumber,
                    VehicleInspectionActive = inspectionActive,
                    VehicleTransmissionName = transmissionName,
                    VehicleFuelType = fuelTypeName,
                    VehicleDimensionValue = details.AuctionDetails.DimensionValue,
                    VehicleDimensionType = dimensionName,
                    VehicleEngineSize = details.AuctionDetails.EngineSize,
                    VehicleAxis = details.AuctionDetails.Axis
                },
                AboutAuctionCreator = SetAuctionCreatorDetails(details)
            });
        }