コード例 #1
0
        public async Task <IActionResult> Update(Guid id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Record record = await _recordService.GetByIdAsync(id);

            User user = await _userManager.FindByIdAsync(record.UserId.ToString());

            RecordUpdateDTO recordViewDTO = _mapper.Map <RecordUpdateDTO>(record);

            recordViewDTO.DecryptedText = _aesCryptoProvider.DecryptValue(record.Text, user.CryptoKey, record.IvKey);

            recordViewDTO.AbilityToRemove = _checkingAbilityToRemove.Check(record.Created);

            return(View(recordViewDTO));
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: vadimBei/Diary2
        public async Task <IActionResult> Index(string searchString, DateTime startDate, DateTime endDate, int page = 1)
        {
            string currentUserName = HttpContext.User.Identity.Name;

            User user = await _userManager.FindByNameAsync(currentUserName);

            SearchModel search = new SearchModel(startDate, endDate);

            IEnumerable <Record> recordsByCurrentUser = await _searchService.RecordsByCurrentUserAcync(search);

            List <RecordViewDTO> decryptedRecords = new List <RecordViewDTO>();

            foreach (var record in recordsByCurrentUser)
            {
                string decriptedText = _aesCryptoProvider.DecryptValue(record.Text, user.CryptoKey, record.IvKey);

                if (decriptedText.Length > 200)
                {
                    decriptedText = decriptedText.Substring(0, 200);
                }


                var decryptedRecord = _mapper.Map <RecordViewDTO>(record);
                decryptedRecord.DecryptedText = decriptedText;

                decryptedRecord.AbilityToRemove = _checkingAbilityToRemove.Check(record.Created);

                decryptedRecords.Add(decryptedRecord);
            }

            //string search
            if (!string.IsNullOrEmpty(searchString))
            {
                decryptedRecords = decryptedRecords.Where(r => r.DecryptedText.Contains(searchString, StringComparison.OrdinalIgnoreCase)).ToList();

                if (decryptedRecords.Count == 0)
                {
                    return(PartialView("NoResults"));
                }
            }

            //number records on page
            int pageSize = 5;
            var count    = decryptedRecords.Count();

            var listToDisplay = decryptedRecords.Skip((page - 1) * pageSize).Take(pageSize).ToList();

            PagingModel pagingModel = new PagingModel(count, page, pageSize);

            IndexViewModel indexViewModel = new IndexViewModel
            {
                PagingModel    = pagingModel,
                RecordViewDTOs = listToDisplay,
                SearchModel    = search
            };

            if (listToDisplay.Count() == 0)
            {
                indexViewModel.DisplayPagination = false;
            }
            else
            {
                indexViewModel.DisplayPagination = true;
            }

            return(View(indexViewModel));
        }