public async Task <IActionResult> AddThought(ThoughtViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            _logger.LogInformation("Adding thought!");
            var distinctTags = model.Tags.Split(',').Distinct();

            model.Tags = string.Join(",", distinctTags);
            var thought = new Thought
            {
                Content       = model.Content,
                CreatedAt     = DateTime.Now,
                Tags          = model.Tags,
                TagsDelimiter = ',',
                Views         = 0
            };
            await _context.Thoughts.AddAsync(thought);

            await _context.SaveChangesAsync();

            _logger.LogInformation("Thought added!", thought);
            return(RedirectToAction("GetSpecificThought", "Home", new { id = thought.Id }));
        }
        public ThoughtsViewModel GetThoughtsList()
        {
            List <ThoughtDto> thoughtDtoList = thoughtService.GetThoughts().ToList();
            ThoughtsViewModel viewModel      = new ThoughtsViewModel()
            {
                ThoughtsList = new List <ThoughtViewModel>()
            };

            foreach (var thoughtDto in thoughtDtoList)
            {
                var thought = new ThoughtViewModel()
                {
                    ThoughtId           = thoughtDto.ThoughtId,
                    UserId              = thoughtDto.User.UserId,
                    Description         = thoughtDto.Description,
                    CreatedDateTime     = thoughtDto.CreatedDateTime,
                    SortId              = thoughtDto.SortId,
                    PriorityId          = thoughtDto.Priority?.PriorityId ?? 0,
                    TimeFrameId         = (int)thoughtDto.Timeframe.TimeframeType,
                    TimeFrameDateString = thoughtDto.Timeframe.DateString,
                    TimeFrameTimeString = thoughtDto.Timeframe.TimeString,
                    TimeFrameWeekString = thoughtDto.Timeframe.WeekString,
                    TimeFrameDueString  = thoughtDto.Timeframe.DueString
                };
                viewModel.ThoughtsList.Add(thought);
            }
            return(viewModel);
        }
        public void CanChangeThoughtText()
        {
            ThoughtViewModel thought = _cloudViewModel.Thoughts.Single();

            thought.Text = "New thought";
            thought      = _cloudViewModel.Thoughts.Single();
            Assert.AreEqual("New thought", thought.Text);
        }
Exemple #4
0
        public ThoughtViewModel GetThoughts(int currentPage, int pageSize)
        {
            var model = new ThoughtViewModel {
                TotalThoughts = _context.Thoughts.Count(t => !t.IsDeleted), CurrentPage = currentPage, PageSize = pageSize
            };

            model.Thoughts = _context.Thoughts.OrderByDescending(t => t.Id).Where(t => !t.IsDeleted).Skip(model.PageSize * (currentPage - 1)).Take(model.PageSize).ToList();
            return(model);
        }
        public IActionResult AddThought()
        {
            var model = new ThoughtViewModel();

            return(View(model));
        }
        public void InitialThoughtIsMyThought()
        {
            ThoughtViewModel thought = _cloudViewModel.Thoughts.Single();

            Assert.AreEqual("My thought", thought.Text);
        }