public async Task <IActionResult> PutCounsellors(int id, Counsellors counsellors)
        {
            if (id != counsellors.Id)
            {
                return(BadRequest());
            }

            _context.Entry(counsellors).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CounsellorsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Rank,Group,GroupSize")] Counsellors counsellors)
        {
            if (ModelState.IsValid)
            {
                _context.Add(counsellors);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(counsellors));
        }
Exemple #3
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Group")] Pathfinders pathfinders)
        {
            if (ModelState.IsValid)
            {
                _context.Add(pathfinders);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(pathfinders));
        }
        public async Task <ActionResult> StoreComment(ContactRequest request)
        {
            Contact contact = new Contact()
            {
                Id           = Guid.NewGuid().ToString(),
                RequestDate  = DateTime.Now,
                Sentiment    = null,
                EmailAddress = request.EmailAddress,
                Name         = request.Name,
                Surname      = request.Surname,
                Comment      = request.Comment
            };

            if (request.ContactType == ContactType.Comment)
            {
                if (request.Comment == null || request.Comment.Length < 5)
                {
                    throw new Exception("Comment length must be greater than 4 characters.");
                }
                var sentiment = await _sentimentAnalysisService.Analyze(request.Comment, "en");

                contact.Sentiment = new Sentiment()
                {
                    Id        = Guid.NewGuid().ToString(),
                    ContactId = contact.Id,
                    Score     = decimal.Parse(sentiment.Score.ToString())
                };
                var entities = await _sentimentAnalysisService.Entities(request.Comment, "en");

                foreach (var entity in entities.Entities)
                {
                    TextEntity tE = new TextEntity()
                    {
                        Id          = Guid.NewGuid().ToString(),
                        SentimentId = contact.Sentiment.Id,
                        Name        = entity.Name,
                        Type        = entity.Type,
                        SubType     = entity.SubType ?? "N/A"
                    };
                    await _context.TextEntities.AddAsync(tE);

                    foreach (var match in entity.Matches)
                    {
                        TextEntityMatch teM = new TextEntityMatch()
                        {
                            Id           = Guid.NewGuid().ToString(),
                            Score        = Decimal.Parse(match.EntityTypeScore.ToString()),
                            TextEntityId = tE.Id
                        };
                        await _context.TextEntitiesMatch.AddAsync(teM);
                    }
                }
                var keyPhrases = await _sentimentAnalysisService.KeyPhrases(request.Comment, "en");

                foreach (string keyphrase in keyPhrases.KeyPhrases)
                {
                    var k = new KeyPhrase()
                    {
                        Id          = Guid.NewGuid().ToString(),
                        SentimentId = contact.Sentiment.Id,
                        Key         = keyphrase
                    };
                    await _context.KeyPhrases.AddAsync(k);
                }
            }
            await _context.Contacts.AddAsync(contact);

            await _context.SaveChangesAsync();

            return(Ok());
        }