Example #1
0
 public TaskServices(IUnitOfWork unitOfWork, IEditionHelper editionHelper, IEmailNotificationHelper emailNotificationHelper)
     : base(unitOfWork)
 {
     _unitOfWork                 = (UnitOfWork)unitOfWork;
     _editionServices            = new EditionServices(unitOfWork);
     _editionTranslationServices = new EditionTranslationServices(unitOfWork);
     _eventServices              = new EventServices(unitOfWork);
     _eventDirectorServices      = new EventDirectorServices(unitOfWork);
     _editionServiceHelper       = new EditionServiceHelper(unitOfWork);
     _editionHelper              = editionHelper;
     _emailNotificationHelper    = emailNotificationHelper;
 }
Example #2
0
        public void UpdateEventEditionFromStagingDb(EditionEntity existingEdition, DWStaging.Edition stagingEdition, DateTime eventStartDate, DateTime eventEndDate)
        {
            using (var scope = new TransactionScope())
            {
                var existingEvent    = existingEdition.Event;
                var eventFromStaging = EditionServiceHelper.PreUpdateExistingEvent((EventEntity)existingEvent.Clone(), stagingEdition);

                // IF MASTERCODE HAS CHANGED:
                if (existingEvent.MasterCode != eventFromStaging.MasterCode)
                {
                    // DELETE THIS WRONGLY UPDATED EDITION FROM CED
                    _editionServices.DeleteEdition(existingEdition.EditionId);
                }
                else
                {
                    var diffOnEvent = GetDiffOnEvent(existingEvent, eventFromStaging);

                    var editionFromStaging = EditionServiceHelper.PreUpdateExistingEdition((EditionEntity)existingEdition.Clone(), stagingEdition, eventStartDate, eventEndDate);
                    var diffOnEdition      = existingEdition.Compare <EditionEntity, StagingDbComparableAttribute>(editionFromStaging);

                    var existingEditionTranslation = existingEdition.EditionTranslations.Single(x =>
                                                                                                x.EditionId == existingEdition.EditionId &&
                                                                                                x.LanguageCode.ToLower() == LanguageHelper.GetBaseLanguageCultureName());
                    var editionTranslationFromStaging = EditionServiceHelper.PreUpdateExistingEditionTranslation((EditionTranslationEntity)existingEditionTranslation.Clone(), stagingEdition);
                    var diffOnEditionTranslation      = existingEditionTranslation.Compare <EditionTranslationEntity, StagingDbComparableAttribute>(editionTranslationFromStaging);

                    if (diffOnEvent.Any())
                    {
                        try
                        {
                            _eventServices.UpdateEvent(existingEvent.EventId, eventFromStaging, Constants.AutoIntegrationUserId, true);
                        }
                        catch (Exception exc)
                        {
                            var extraInfo = "Error on UpdateEvent() | EventId=" + existingEvent.EventId + " | StagingEditionEventBEID=" + stagingEdition.EventBEID;
                            var log       = CreateInternalLog(exc, extraInfo);
                            ExternalLogHelper.Log(log, LoggingEventType.Error);
                            return;
                        }
                    }

                    if (diffOnEditionTranslation.Any() || diffOnEdition.Any() || diffOnEvent.Any())
                    {
                        try
                        {
                            var startDateChanged = diffOnEdition.SingleOrDefault(x => x.Prop.ToLower().Contains("startdate")) != null;

                            if (startDateChanged)
                            {
                                // UPDATE STARTDATE DIFF for CURRENT EDITION
                                SetEditionStartDateDiff(editionFromStaging);
                            }

                            _editionServices.UpdateEdition(existingEdition.EditionId, editionFromStaging, Constants.AutoIntegrationUserId, true);

                            if (startDateChanged)
                            {
                                // UPDATE STARTDATE DIFF for NEXT EDITION
                                UpdateNextEditionStartDateDiff(existingEdition);
                            }

                            var eventTypeChanged = diffOnEdition.SingleOrDefault(x => x.Prop.ToLower().Contains("eventtype")) != null;
                            if (eventTypeChanged)
                            {
                                if (!Utility.Constants.ValidEventTypesForCed.Contains(existingEdition.EventTypeCode) &&
                                    Utility.Constants.ValidEventTypesForCed.Contains(editionFromStaging.EventTypeCode) &&
                                    editionFromStaging.StartDate > DateTime.Now)
                                {
                                    SendNotificationEmailForEditionCreation(editionFromStaging, editionTranslationFromStaging, GetEmailTemplateForEditionCreation(editionFromStaging));
                                }
                            }

                            StartNotificationProcessForEditionNameUpdate(existingEdition, existingEditionTranslation, diffOnEdition);
                            StartNotificationProcessForEditionLocationUpdate(existingEdition, existingEditionTranslation, diffOnEdition);
                        }
                        catch (Exception exc)
                        {
                            var extraInfo = "Error on editionServices.UpdateEdition() | EditionId=" + existingEdition.EditionId + " | StagingEditionEventBEID=" + stagingEdition.EventBEID;
                            var log       = CreateInternalLog(exc, extraInfo);
                            ExternalLogHelper.Log(log, LoggingEventType.Error);
                            return;
                        }
                    }

                    if (diffOnEditionTranslation.Any())
                    {
                        try
                        {
                            _editionTranslationServices.UpdateEditionTranslation(editionTranslationFromStaging, Constants.AutoIntegrationUserId, true);
                        }
                        catch (Exception exc)
                        {
                            var extraInfo = "EditionTranslationId=" + existingEditionTranslation.EditionTranslationId + " | StagingEditionEventBEID=" + stagingEdition.EventBEID;
                            var log       = CreateInternalLog(exc, extraInfo);
                            ExternalLogHelper.Log(log, LoggingEventType.Error);
                            return;
                        }
                    }
                }

                scope.Complete();
            }
        }
Example #3
0
 bool IsEditionTranslationInfoCompleted(EditionTranslationEntity editionTranslationEntity, EditionInfoType infoType)
 {
     return(EditionServiceHelper.IsEditionInfoCompleted(editionTranslationEntity, infoType));
 }
Example #4
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));
                }
            }
        }
Example #5
0
        public ActionResult _Upload()
        {
            var entityId    = Convert.ToInt32(Request.Params["EntityId"]);
            var fileType    = Request.Params["FileType"].ToEnum <EditionFileType>();
            var langCode    = Request.Params["LanguageCode"];
            var isSaved     = true;
            var newFileName = "";

            var edition = EditionServices.GetEditionById(entityId);

            if (edition == null)
            {
                return(View("NotFound", new ErrorModel {
                    Message = Constants.EditionNotFound
                }));
            }
            if (edition.IsCancelled())
            {
                return(Json(new { success = false, message = Constants.WarningMessageEventCancelled }));
            }

            try
            {
                var file = Request.Files[0];

                if (file != null && file.ContentLength > 0)
                {
                    var fileName = Path.GetFileNameWithoutExtension(file.FileName);

                    // CHECK EXTENSION
                    var extension         = Path.GetExtension(file.FileName);
                    var allowedExtensions = fileType.GetAttribute <FileTypeAttribute>().AllowedExtensions;

                    if (!allowedExtensions.Contains(extension))
                    {
                        return(Json(new { success = false, message = Constants.InvalidFileExtension }));
                    }

                    newFileName = EditionServiceHelper.ComposeFileName(edition.EditionId, fileName, fileType, langCode, extension);

                    // The way of saving changes depending on fileType's Private property.
                    var result = fileType.GetAttribute <FileTypeAttribute>().Private
                        ? SaveFileToLocalDisk(fileType, newFileName, file)
                        : SaveFileToAzureStorage(fileType, newFileName, file);

                    switch (result.Result)
                    {
                    case OperationResult.AlreadyExists:
                        return(Json(new { success = false, message = Constants.FileAlreadyExistsWithTheSameName }));

                    case OperationResult.Failed:
                        return(Json(new { success = false, message = result.Message }));
                    }

                    // CREATE FILE
                    if (!SaveFileInfo(entityId, newFileName, fileType, extension, langCode))
                    {
                        return(Json(new { success = false, message = Constants.ErrorWhileSavingFile }));
                    }
                }
            }
            catch (Exception exc)
            {
                isSaved = false;

                var log = CreateInternalLog(exc);
                ExternalLogHelper.Log(log, LoggingEventType.Error);
            }

            if (!isSaved)
            {
                return(Json(new { success = false, message = Constants.ErrorWhileSavingFile }));
            }

            // UPDATE EDITION
            UpdateEditionUpdateInfo(edition);

            // UPDATE LOG
            var updatedFields = NotificationControllerHelper.GetUpdatedFieldsAsJson($"File ({fileType})", new List <Variance> {
                new Variance {
                    Prop = fileType.ToString()
                }
            });

            UpdateLogInMemory(edition, updatedFields);

            //UpdateLogInMemory(currentEdition, edition, currentEditionTranslation, editionTranslation);

            // UPDATEDCONTENT
            var currentFileForComparison = new FileEntity();
            var fileForComparison        = new FileEntity {
                FileName = newFileName
            };

            fileForComparison.SetFullUrl();
            var updatedContent = NotificationControllerHelper.GetUpdatedContent(currentFileForComparison, fileForComparison);

            PushEditionUpdateNotifications(edition, updatedContent);

            return(Json(new { success = true, message = Constants.FileSaved }));
        }