Пример #1
0
        public void Add(Sentiment sentiment)
        {
            using (SentimentAnalysisContext context = new SentimentAnalysisContext())
            {
                if (context.Sentiments.Any(s => s.Id == sentiment.Id))
                {
                    throw new SentimentException("An Sentiment with the same ID already exists.");
                }

                Exists(sentiment);

                Entities.Sentiment toAdd = Helper.Instance.ToSentimentEF(sentiment);
                context.Sentiments.Add(toAdd);
                context.SaveChanges();
                sentiment.Id = toAdd.Id;

                PhraseRepository      phraseRepository = new PhraseRepository();
                EntityAlarmRepository alarmRepository  = new EntityAlarmRepository();

                foreach (var phrase in Helper.Instance.GetPhrases(context.Phrases))
                {
                    try
                    {
                        phraseRepository.Modify(phrase.Id, phrase);
                    }
                    catch (AnalysisException) { }
                }

                foreach (var alarm in Helper.Instance.GetEntityAlarms(context.EntityAlarms).Where(a => a.Type == sentiment.Type && !a.IsEnabled()))
                {
                    alarmRepository.Modify(alarm.Id, alarm);
                }
            }
        }
Пример #2
0
        public Sentiment Get(int id)
        {
            using (SentimentAnalysisContext context = new SentimentAnalysisContext())
            {
                Entities.Sentiment sentiment = context.Sentiments.FirstOrDefault(s => s.Id == id);

                if (sentiment == null)
                {
                    throw new SentimentException("Sentiment not found.");
                }

                return(Helper.Instance.ToSentimentBL(sentiment));
            }
        }
Пример #3
0
        public void Delete(int?id)
        {
            if (!id.HasValue)
            {
                throw new SentimentException("You must select an Sentiment to delete.");
            }

            EntityAlarmRepository alarmRepository = new EntityAlarmRepository();

            using (SentimentAnalysisContext context = new SentimentAnalysisContext())
            {
                Entities.Sentiment toRemove = context.Sentiments.FirstOrDefault(s => s.Id == id);

                if (toRemove == null)
                {
                    throw new SentimentException("Sentiment not found.");
                }

                context.Sentiments.Remove(toRemove);
                context.SaveChanges();

                foreach (var phrase in context.Phrases.Where(p => p.Type != null && p.Type == toRemove.Type))
                {
                    phrase.Type = null;
                }

                foreach (var alarm in context.EntityAlarms.ToList())
                {
                    EntityAlarm toModify = Helper.Instance.ToEntityAlarmBL(alarm);

                    try
                    {
                        alarmRepository.Modify(alarm.Id, toModify);
                    }
                    catch { }
                }
            }
        }
Пример #4
0
 public BusinessLogic.DTO.Sentiment ToSentimentBL(Entities.Sentiment sentiment)
 {
     return(new BusinessLogic.DTO.Sentiment(sentiment.Id, sentiment.Type, sentiment.Word));
 }