Пример #1
0
        private async Task <int> UpdateEventLocationGoalValue(string eventId, string locationId, int value)
        {
            EventModel eventObj = await _eventRestService.GetEvent(eventId);

            if (eventObj != null)
            {
                EventLocationModel eventLocation = eventObj.EventLocations?.Find(p => p.Id == locationId);
                if (eventLocation != null && eventObj.IsEventActive)
                {
                    eventLocation.GoalStatus += value;
                    try
                    {
                        var result = await _eventRestService.UpdateEvent(eventObj);

                        if (result == HttpStatusCode.OK)
                        {
                            return(eventLocation.GoalStatus);
                        }
                        else if (result == HttpStatusCode.PreconditionFailed)
                        {
                            await UpdateEventLocationGoalValue(eventId, locationId, value); //Etag error, retrying...
                        }
                        else
                        {
                            _logger.LogError($"UpdateEventLocationGoalValue: {result}");
                            return(-1);
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.LogError($"UpdateEventLocationGoalValue: {e.Message}");
                        return(-1);
                    }
                }
            }
            else
            {
                _logger.LogError($"The event {eventId} wasn't found.");
            }
            return(-1);
        }
Пример #2
0
        public async Task <bool> UpdateEventGeneralSettings(string eventId, string eventName, bool isEventActive)
        {
            EventModel eventObj = await _eventRestService.GetEvent(eventId);

            if (eventObj != null)
            {
                bool needUpdateActiveStatus = eventObj.IsEventActive != isEventActive;

                //Update parameters
                eventObj.EventName     = eventName;
                eventObj.IsEventActive = isEventActive;

                try
                {
                    var result = await _eventRestService.UpdateEvent(eventObj);

                    if (result == HttpStatusCode.OK)
                    {
                        if (needUpdateActiveStatus)
                        {
                            if (!await PushMessageToQueue(new EventActiveStateChangedMessage()
                            {
                                EventId = eventObj.Id, EventActiveState = eventObj.IsEventActive
                            }))
                            {
                                _logger.LogError($"PushMessages: Error while pushing to queue for Event Active State.");
                            }
                        }
                        return(true);
                    }
                    else if (result == HttpStatusCode.PreconditionFailed)
                    {
                        return(await UpdateEventGeneralSettings(eventId, eventName, isEventActive)); //Etag error, retrying...
                    }
                    else
                    {
                        _logger.LogError($"UpdateEvent: {result}");
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    _logger.LogError($"UpdateEvent: {e.Message}");
                    return(false);
                }
            }
            return(false);
        }
Пример #3
0
        private async Task <EventModel> UpdateEventSentimentValue(string eventId, string note, string sentiment)
        {
            EventModel eventObj = await _eventRestService.GetEvent(eventId);

            if (eventObj.IsEventActive)
            {
                EventSentimentModel eventSentiment = GetEventSentiment(eventObj, sentiment);
                eventSentiment.Value++;
                eventObj.LastNote = note;

                UpdateSentimentValuesPercentage(eventObj);

                try
                {
                    var result = await _eventRestService.UpdateEvent(eventObj);

                    if (result == HttpStatusCode.OK)
                    {
                        return(eventObj);
                    }
                    else if (result == HttpStatusCode.PreconditionFailed)
                    {
                        await UpdateEventSentimentValue(eventId, note, sentiment); //Etag error, retrying...
                    }
                    else
                    {
                        _logger.LogError($"UpdateEventSentimentValue: {result}");
                        return(null);
                    }
                }
                catch (Exception e)
                {
                    _logger.LogError($"UpdateEventSentimentValue: {e.Message}");
                    return(null);
                }
            }
            return(null);
        }