Ejemplo n.º 1
0
        public TiqetProductUploadQueryResult Handle(TiqetProductUploadQuery query)
        {
            var tiqetProducts = _tiqetProductRepository.GetAll().Skip(query.SkipIndex).Take(query.TakeIndex).ToList();
            List <TiqetImageModel> tiqetImageModelList = new List <TiqetImageModel>();

            foreach (var currentProduct in tiqetProducts)
            {
                try
                {
                    TiqetImageModel tiqetImageModel  = new TiqetImageModel();
                    var             tiqetImage       = _tiqetProductImageRepository.GetByProductId(currentProduct.ProductId).FirstOrDefault();
                    var             tiqetEventDetail = _tiqetEventDetailMappingRepository.GetByProductId(currentProduct.ProductId);
                    var             eventDetail      = _eventDetailRepository.Get(tiqetEventDetail.EventDetailId);
                    var             eventId          = _eventRepository.Get(eventDetail.EventId);
                    tiqetImageModel.EventAltId = eventId.AltId;
                    tiqetImageModel.ImageLink  = tiqetImage.Large;
                    tiqetImageModelList.Add(tiqetImageModel);
                }
                catch (Exception e)
                {
                    continue;
                }
            }

            return(new TiqetProductUploadQueryResult
            {
                TiqetImagesList = tiqetImageModelList
            });
        }
Ejemplo n.º 2
0
        protected override async Task <ICommandResult> Handle(UpdateProductCommand command)
        {
            UpdateProductCommandResult updateCommandResult = new UpdateProductCommandResult();

            try
            {
                List <string> imageLinks      = new List <string>();
                var           tiqetProduct    = _tiqetProductRepository.GetByProductId(command.productId);
                var           checkoutDetails = await SaveCheckoutDetails(command);

                var countryandvenuedetails = await UpdateCountryAndVenueDetails(tiqetProduct.GeoLocationLatitude, tiqetProduct.GeoLocationLongitude, tiqetProduct.VenueName, tiqetProduct.VenueAddress, command.ModifiedBy, tiqetProduct.CountryName, tiqetProduct.CityName);

                bool isImageUpload = false;
                // Saving/Updating Details to our Tables
                var events        = _eventRepository.GetByEventName(tiqetProduct.Tittle);
                var formattedSlug = FormatSlug(tiqetProduct.Tittle);
                if (events == null)
                {
                    events = _eventRepository.Save(new Event
                    {
                        AltId                  = Guid.NewGuid(),
                        Name                   = tiqetProduct.Tittle,
                        EventCategoryId        = 29,
                        EventTypeId            = EventType.Perennial,
                        Description            = null,
                        ClientPointOfContactId = 1,
                        FbEventId              = null,
                        MetaDetails            = null,
                        IsFeel                 = true,
                        EventSourceId          = EventSource.Tiqets,
                        TermsAndConditions     = "",
                        IsPublishedOnSite      = true,
                        PublishedDateTime      = DateTime.Now,
                        PublishedBy            = null,
                        TestedBy               = null,
                        Slug                   = formattedSlug,
                        ModifiedBy             = command.ModifiedBy,
                        IsEnabled              = true
                    });
                    isImageUpload = true;
                }
                else
                {
                    events.IsEnabled   = true;
                    events.Description = tiqetProduct.Summary;
                    events.Slug        = formattedSlug;
                    _eventRepository.Save(events);
                }
                if (isImageUpload || command.IsImageUpload)
                {
                    var productImages = _tiqetProductImageRepository.GetByProductId(tiqetProduct.ProductId);
                    foreach (var currentImage in productImages)
                    {
                        imageLinks.Add(currentImage.Large);
                    }
                }
                var last = _eventSiteIdMappingRepository.GetAll().OrderByDescending(p => p.CreatedUtc).FirstOrDefault();
                var eventSiteIdMapping = _eventSiteIdMappingRepository.GetByEventId(events.Id);
                if (eventSiteIdMapping == null)
                {
                    _eventSiteIdMappingRepository.Save(new Contracts.DataModels.EventSiteIdMapping
                    {
                        EventId    = events.Id,
                        SortOrder  = Convert.ToInt16(last.SortOrder + 1),
                        SiteId     = Site.feelaplaceSite,
                        ModifiedBy = command.ModifiedBy,
                        IsEnabled  = true
                    });
                }
                var getEventCategoryId = await GetCategoryId(tiqetProduct.ProductId);

                foreach (var categoryId in getEventCategoryId)
                {
                    var eventCategoryMapping = _eventCategoryMappingRepository.GetByEventIdAndEventCategoryId(events.Id, categoryId);
                    if (eventCategoryMapping == null)
                    {
                        _eventCategoryMappingRepository.Save(new Contracts.DataModels.EventCategoryMapping
                        {
                            EventId         = events.Id,
                            EventCategoryId = categoryId,
                            ModifiedBy      = command.ModifiedBy,
                            IsEnabled       = true
                        });
                    }
                    else
                    {
                        eventCategoryMapping.EventCategoryId = categoryId;
                        _eventCategoryMappingRepository.Save(eventCategoryMapping);
                    }
                }
                var eventDetail = _eventDetailRepository.GetByNameAndVenueId(tiqetProduct.Tittle, countryandvenuedetails.venueId);
                if (eventDetail == null)
                {
                    eventDetail = _eventDetailRepository.Save(new EventDetail
                    {
                        Name                  = tiqetProduct.Tittle,
                        EventId               = events.Id,
                        VenueId               = countryandvenuedetails.venueId,
                        StartDateTime         = DateTime.UtcNow,
                        EndDateTime           = DateTime.UtcNow.AddYears(1),
                        GroupId               = 1,
                        AltId                 = Guid.NewGuid(),
                        TicketLimit           = 10,
                        ModifiedBy            = command.ModifiedBy,
                        IsEnabled             = true,
                        MetaDetails           = "",
                        HideEventDateTime     = false,
                        CustomDateTimeMessage = "",
                        CreatedUtc            = DateTime.UtcNow,
                        CreatedBy             = command.ModifiedBy
                    });
                }
                else
                {
                    eventDetail.IsEnabled     = true;
                    eventDetail.StartDateTime = DateTime.UtcNow;
                    eventDetail.EndDateTime   = DateTime.UtcNow.AddYears(1);
                    eventDetail.ModifiedBy    = command.ModifiedBy;
                    _eventDetailRepository.Save(eventDetail);
                }
                var eventDeliveryType = _eventDeliveryTypeDetailRepository.GetByEventDetailId(eventDetail.Id).ToList();
                if (eventDeliveryType.Count() == 0)
                {
                    _eventDeliveryTypeDetailRepository.Save(new EventDeliveryTypeDetail
                    {
                        EventDetailId  = eventDetail.Id,
                        DeliveryTypeId = DeliveryTypes.MTicket,
                        Notes          = "<table><tr><td valign=''top''>1.&nbsp;</td><td valign=''top''>Ticket pickup location and timing will be announced in the “Customer Update” sectionof our website closer to the event. Please check that regularly.</td></tr><tr><td valign=''top''>2.&nbsp;</td><td valign=''top''>The following documents are compulsory for ticket pickup:<br /><table><tr>  <td valign=''top''>  a.&nbsp;  </td>  <td colspan=''2'' valign=''top''>  The card / bank account owner’s original Govt. issued photo ID, along with a clean,  fully legible, photocopy of the same ID  </td></tr><tr>  <td valign=''top''>  b.&nbsp;  </td>  <td colspan=''2'' valign=''top''>  When a debit or credit card has been used for purchase, we also need the original  debit/credit card, along with a clean, fully legible, photocopy of the same card  </td></tr><tr>  <td valign=''top''>  c.&nbsp;  </td>  <td colspan=''2'' valign=''top''>  If sending someone else on behalf of the card holder / bank account owner, then  we need numbers 2.a. and 2.b above (originals and photocopies as mentioned) along  with the following below. This is required even if the representative’s name has  been entered into the system when buying:  </td></tr><tr>  <td valign=''top''>  </td>  <td valign=''top''>  i.&nbsp;  </td>  <td>  An authorization letter with the name of the representative, signed by the card  holder/bank account owner  </td></tr><tr>  <td valign=''top''>  </td>  <td valign=''top''>  ii.&nbsp;  </td>  <td>  A Govt issued photo ID of the representative, along with a clean and legible photocopy  of the same photo identification  </td></tr></table></td></tr><tr><td valign=''top''>3.&nbsp;</td><td valign=''top''>Please note, absence of any one of the documents above can result in the tickets being refused at the ticket pickup window</td></tr>  </table>",
                        EndDate        = DateTime.UtcNow.AddYears(1),
                        ModifiedBy     = command.ModifiedBy,
                        IsEnabled      = true,
                        CreatedUtc     = DateTime.UtcNow
                    });
                }

                await GetVariantDetails(tiqetProduct.ProductId);
                await DisableAllEventTicketDetailMappings(tiqetProduct.ProductId);

                var variantdetails = _tiqetVariantDetailRepository.GetAllByProductId(tiqetProduct.ProductId);
                //if variants are not available at the moment disable it.
                if (variantdetails.Count() == 0)
                {
                    events.IsEnabled = false;
                    _eventRepository.Save(events);
                    eventDetail.IsEnabled = false;
                    _eventDetailRepository.Save(eventDetail);
                    updateCommandResult.success = false;
                    return(updateCommandResult);
                }
                foreach (var variantdetail in variantdetails)
                {
                    //eventTicketDetails and TicketCategories goes here
                    var ticketCategory = _ticketCategoryRepository.GetByName(variantdetail.Label);
                    if (ticketCategory == null)
                    {
                        ticketCategory = _ticketCategoryRepository.Save(new TicketCategory
                        {
                            Name       = variantdetail.Label,
                            ModifiedBy = command.ModifiedBy,
                            IsEnabled  = true
                        });
                    }
                    var eventTicketDetail = _eventTicketDetailRepository.GetByTicketCategoryIdAndEventDetailId(ticketCategory.Id, eventDetail.Id);
                    if (eventTicketDetail == null)
                    {
                        eventTicketDetail = _eventTicketDetailRepository.Save(new EventTicketDetail
                        {
                            EventDetailId    = eventDetail.Id,
                            TicketCategoryId = ticketCategory.Id,
                            ModifiedBy       = command.ModifiedBy,
                            IsEnabled        = true
                        });
                    }
                    else
                    {
                        eventTicketDetail.IsEnabled = true;
                        _eventTicketDetailRepository.Save(eventTicketDetail);
                    }

                    var eventTicketDetailMapping = await SaveToTiqetsEventTicketDetailMapping(variantdetail.Id, eventTicketDetail.Id, command);

                    var eventTicketAttribute = _eventTicketAttributeRepository.GetByEventTicketDetailId(eventTicketDetail.Id);
                    if (eventTicketAttribute == null)
                    {
                        eventTicketAttribute = _eventTicketAttributeRepository.Save(new EventTicketAttribute
                        {
                            EventTicketDetailId       = eventTicketDetail.Id,
                            SalesStartDateTime        = DateTime.UtcNow,
                            SalesEndDatetime          = DateTime.UtcNow.AddYears(1),
                            TicketTypeId              = TicketType.Regular,
                            ChannelId                 = Channels.Feel,
                            CurrencyId                = TiqetsConstant.CurrencyCode,
                            SharedInventoryGroupId    = null,
                            TicketCategoryDescription = "",
                            ViewFromStand             = "",
                            IsSeatSelection           = false,
                            AvailableTicketForSale    = Convert.ToInt32(variantdetail.MaxTicketsPerOrder),
                            RemainingTicketForSale    = Convert.ToInt32(variantdetail.MaxTicketsPerOrder),
                            Price = variantdetail.TotalRetailPriceInclVat,
                            IsInternationalCardAllowed = false,
                            IsEMIApplicable            = false,
                            ModifiedBy = command.ModifiedBy,
                            IsEnabled  = true
                        });
                    }
                    else
                    {
                        eventTicketAttribute.SalesStartDateTime     = DateTime.UtcNow;
                        eventTicketAttribute.SalesEndDatetime       = DateTime.UtcNow.AddYears(1);
                        eventTicketAttribute.AvailableTicketForSale = Convert.ToInt32(variantdetail.MaxTicketsPerOrder);
                        eventTicketAttribute.RemainingTicketForSale = Convert.ToInt32(variantdetail.MaxTicketsPerOrder);
                        eventTicketAttribute.Price = variantdetail.TotalRetailPriceInclVat;
                        _eventTicketAttributeRepository.Save(eventTicketAttribute);
                    }
                    var ticketFeeDetail = _ticketFeeDetailRepository.GetByEventTicketAttributeIdAndFeedId(eventTicketAttribute.Id, (int)FeeType.ConvenienceCharge);
                    if (ticketFeeDetail == null)
                    {
                        ticketFeeDetail = _ticketFeeDetailRepository.Save(new TicketFeeDetail
                        {
                            EventTicketAttributeId = eventTicketAttribute.Id,
                            FeeId       = (int)FeeType.ConvenienceCharge,
                            DisplayName = "Convienence Charge",
                            ValueTypeId = (int)ValueTypes.Percentage,
                            Value       = 5,
                            ModifiedBy  = command.ModifiedBy,
                            IsEnabled   = true
                        });
                    }
                }
                await DisableEventTicketDeails(tiqetProduct.ProductId);
                await SaveToEventDetailMapping(tiqetProduct.ProductId, eventDetail.Id);
                await SyncDaysAvailabilityAsync(command, eventDetail.Id, events.Id);

                updateCommandResult.IsImageUpload = imageLinks.Count() > 0 ? true : false;
                updateCommandResult.success       = true;
                updateCommandResult.ImageLinks    = imageLinks;
                updateCommandResult.EventAltId    = events.AltId;
                return(updateCommandResult);
            }
            catch (Exception e)
            {
                updateCommandResult.success       = false;
                updateCommandResult.IsImageUpload = false;
                _logger.Log(LogCategory.Error, new Exception("Failed to update Product Details", e));
                return(updateCommandResult);
            }
        }
Ejemplo n.º 3
0
        protected override async Task <ICommandResult> Handle(SyncTiqetProductsCommand command)
        {
            SyncTiqetProductsCommandResult result = new SyncTiqetProductsCommandResult();

            try
            {
                TagTypeResponseModel tagTypes = new TagTypeResponseModel();
                tagTypes = Mapper <TagTypeResponseModel> .MapFromJson((await SyncTagTypes()));

                //here skipIndex check is to avoid hitting the DB
                if (tagTypes.success && tagTypes.tag_types.Count() > 0 && command.SkipIndex == 0)
                {
                    var tiqetTagTypes     = _tiqetTagTypeRepository.GetByNames(tagTypes.tag_types.Select(s => s.name)).ToList();
                    var tiqetTagTypesList = AutoMapper.Mapper.Map <List <TiqetTagType> >(tiqetTagTypes);
                    foreach (TagType tagType in tagTypes.tag_types)
                    {
                        var currentTagType = tiqetTagTypesList.Where(s => s.Name == tagType.name).FirstOrDefault();
                        if (currentTagType == null)
                        {
                            currentTagType = _tiqetTagTypeRepository.Save(new TiqetTagType
                            {
                                Name       = tagType.name,
                                TypeId     = tagType.id,
                                IsEnabled  = true,
                                CreatedUtc = DateTime.UtcNow,
                                CreatedBy  = command.ModifiedBy
                            });
                        }
                    }
                    //Intially Disable all event Detail Mappings
                    _tiqetEventDetailMappingRepository.DisableAll();
                }

                TagResponseModel tags = new TagResponseModel();
                tags = Mapper <TagResponseModel> .MapFromJson((await SyncTags()));

                if (tags.success && tags.tags.Count() > 0 && command.SkipIndex == 0)
                {
                    var tiqetTags     = _tiqetTagRepository.GetByTagIds(tags.tags.Select(s => s.id));
                    var tiqetTagsList = AutoMapper.Mapper.Map <List <TiqetTag> >(tiqetTags);

                    foreach (Tag tag in tags.tags)
                    {
                        var currentTag = tiqetTagsList.Where(s => s.TagId == tag.id).FirstOrDefault();
                        if (currentTag == null)
                        {
                            currentTag = _tiqetTagRepository.Save(new TiqetTag
                            {
                                Name       = tag.name,
                                TagId      = tag.id,
                                TagTypeId  = tag.type_id,
                                IsEnabled  = true,
                                CreatedUtc = DateTime.UtcNow,
                                CreatedBy  = command.ModifiedBy
                            });
                        }
                    }
                }

                AllProductResponseModel allProductsList = new AllProductResponseModel();
                allProductsList = Mapper <AllProductResponseModel> .MapFromJson((await GetProductList(command.PageNumber)));

                if (allProductsList.success && allProductsList.products.Count > 0)
                {
                    foreach (Product productData in allProductsList.products.Skip(command.SkipIndex).Take(command.TakeIndex))    // this is done to sync the products in batch wise
                    {
                        var tiqetsProducts = _tiqetProductRepository.GetByProductId(productData.id);
                        if (tiqetsProducts == null)
                        {
                            tiqetsProducts = _tiqetProductRepository.Save(new Contracts.DataModels.Tiqets.TiqetProduct
                            {
                                ProductId            = productData.id,
                                Tittle               = productData.title,
                                SaleStatus           = productData.sale_status,
                                Inclusions           = productData.whats_included,
                                Language             = productData.language,
                                CountryName          = productData.country_name,
                                CityName             = productData.city_name,
                                ProductSlug          = productData.product_slug,
                                Price                = Convert.ToDecimal(productData.price),
                                SaleStatuReason      = productData.sale_status_reason,
                                VenueName            = productData.venue.name,
                                VenueAddress         = productData.venue.address,
                                Summary              = productData.summary,
                                TagLine              = productData.tagline,
                                PromoLabel           = productData.promo_label,
                                RatingAverage        = productData.ratings.average.ToString(),
                                GeoLocationLatitude  = productData.geolocation.lat.ToString(),
                                GeoLocationLongitude = productData.geolocation.lng.ToString(),
                                IsEnabled            = true,
                                CreatedUtc           = DateTime.UtcNow,
                                CreatedBy            = command.ModifiedBy
                            });
                        }

                        var tiqetsImages = _tiqetProductImageRepository.GetByProductId(tiqetsProducts.ProductId);
                        if (tiqetsImages.Count() == 0 && productData.images != null && productData.images.Count() > 0)
                        {
                            foreach (Image images in productData.images)
                            {
                                var image = _tiqetProductImageRepository.Save(new TiqetProductImage
                                {
                                    ProductId  = tiqetsProducts.ProductId,
                                    Small      = images.small,
                                    Medium     = images.medium,
                                    Large      = images.large,
                                    IsEnabled  = true,
                                    CreatedUtc = DateTime.UtcNow,
                                    CreatedBy  = command.ModifiedBy
                                });
                            }
                        }

                        var tiqetProductMappings = _tiqetProductTagMappingRepository.GetByProductId(tiqetsProducts.ProductId);
                        if (tiqetProductMappings.Count() == 0)
                        {
                            var tiqetProductTags     = _tiqetTagRepository.GetByTagIds(productData.tag_ids);
                            var tiqetProductTagsList = AutoMapper.Mapper.Map <List <TiqetTag> >(tiqetProductTags);
                            foreach (var tiqetIds in productData.tag_ids)
                            {
                                bool isCategory     = false;
                                var  isCategoryType = tiqetProductTagsList.Where(s => s.TagId == tiqetIds).FirstOrDefault();
                                if (isCategoryType != null && isCategoryType.TagTypeId == TiqetsConstant.CategoryId)
                                {
                                    isCategory = true;
                                }
                                var tiqetProductTagMapping = _tiqetProductTagMappingRepository.Save(new TiqetProductTagMapping
                                {
                                    ProductId      = tiqetsProducts.ProductId,
                                    TagId          = tiqetIds,
                                    IsEnabled      = true,
                                    IsCategoryType = isCategory,
                                    CreatedUtc     = DateTime.UtcNow,
                                    CreatedBy      = command.ModifiedBy
                                });
                            }
                        }
                    }
                }

                result.RemainingProducts = allProductsList.pagination.total - (command.SkipIndex + command.TakeIndex);

                if (command.GetProducts)
                {
                    var getEnabledProducts = _tiqetProductRepository.GetAll().Where(s => s.IsEnabled);
                    result.tiqetProducts = AutoMapper.Mapper.Map <List <Contracts.Models.Tiqets.TiqetProduct> >(getEnabledProducts);
                }
                return(result);
            }
            catch (Exception e)
            {
                _logger.Log(LogCategory.Error, new Exception("Failed to Sync Products", e));
                return(null);
            }
        }