Esempio n. 1
0
        public void CreateEventEditionFromStagingDb(DWStaging.Edition stagingEdition, DateTime eventStartDate, DateTime eventEndDate)
        {
            using (var scope = new TransactionScope())
            {
                var existingEvent = _unitOfWork.EventRepository.Get(x => x.MasterCode == stagingEdition.EventMasterCode);
                int eventId;

                if (existingEvent == null)
                {
                    var newEvent = EditionServiceHelper.PrepareNewEvent(stagingEdition);

                    if (!SaveNewEvent(newEvent, stagingEdition))
                    {
                        return;
                    }

                    eventId = newEvent.EventId;
                }
                else
                {
                    eventId = existingEvent.EventId;
                }

                var axId = Convert.ToInt32(stagingEdition.EventBEID);

                // TODO: Make it faster
                var lastEdition = _editionServices.GetLastEdition(eventId, Utility.Constants.DefaultValidEditionStatusesForCed, Utility.Constants.ValidEventTypesForCed);

                var newEdition = EditionServiceHelper.PrepareNewEdition(axId, eventId, stagingEdition, eventStartDate, eventEndDate, lastEdition);

                EditionTranslationEntity newEditionTranslation = null;

                if (!SaveNewEdition(newEdition, stagingEdition))
                {
                    return;
                }

                UpdateStartDateDiffFieldsOfNewEdition(newEdition.EditionId);

                if (lastEdition != null)
                {
                    foreach (var editionTranslation in lastEdition.EditionTranslations)
                    {
                        newEditionTranslation = EditionServiceHelper.PrepareNewEditionTranslation(newEdition, stagingEdition, editionTranslation);

                        EditionServiceHelper.CopyEditionImages(newEdition.EditionId, newEdition.EditionName, editionTranslation, newEditionTranslation);

                        var newEditionTranslationId = SaveEditionTranslation(newEditionTranslation, stagingEdition);

                        if (!(newEditionTranslationId > 0))
                        {
                            continue;
                        }

                        newEditionTranslation.EditionTranslationId = newEditionTranslationId;

                        _editionServiceHelper.CopySocialMediaAccounts(lastEdition.EditionId, editionTranslation.LanguageCode, newEditionTranslation);
                    }
                }
                else
                {
                    // Add a new EditionTranslation (en-gb)
                    newEditionTranslation = EditionServiceHelper.PrepareNewEditionTranslation(newEdition, stagingEdition, null);

                    var newEditionTranslationId = SaveEditionTranslation(newEditionTranslation, stagingEdition);
                }

                scope.Complete();

                if (Utility.Constants.ValidEventTypesForCed.Contains(newEdition.EventTypeCode))
                {
                    var newEditionEntity = Mapper.Map <Edition, EditionEntity>(newEdition);
                    SendNotificationEmailForEditionCreation(newEditionEntity, newEditionTranslation, GetEmailTemplateForEditionCreation(newEditionEntity));
                }
            }
        }