Beispiel #1
0
        public async Task <IActionResult> DeleteBatchEntryAsync(int id)
        {
            try
            {
                var entriesQuery = _queryFactory.CreateBatchEntriesQuery();
                var entryDto     = await entriesQuery.ExecuteAsync(id).ConfigureAwait(false);

                if (entryDto != null)
                {
                    var cmd = _commandsFactory.CreateBatchEntriesCommand();
                    await cmd.DeleteAsync(entryDto).ConfigureAwait(false);
                }
                return(Ok());
            }
            catch (Exception)
            {
                return(StatusCode(500));

                throw;
            }
        }
        /// <summary>
        /// Main Landing Page for Journals
        /// </summary>
        public async Task <IActionResult> Index()
        {
            ViewData["Title"]    = _localizer["PageTitle"];
            ViewData["PageDesc"] = _localizer["PageDesc"];

            var submittedBy = await UserManagerAgent.GetUserAsync(User).ConfigureAwait(false);

            var varietiesQuery = _recipeQueryFactory.CreateVarietiesQuery();
            var vList          = await varietiesQuery.ExecuteAsync().ConfigureAwait(false);

            var entriesQuery = _journalQueryFactory.CreateBatchEntriesQuery();

            var getBatchesQuery = _journalQueryFactory.CreateBatchesQuery();
            var batchesDto      = await getBatchesQuery.ExecuteByUserAsync(submittedBy.Id).ConfigureAwait(false);

            foreach (var b in batchesDto)
            {
                var entriesDto = await entriesQuery.ExecuteByFKAsync(b.Id.Value).ConfigureAwait(true);

                b.Entries.AddRange(entriesDto.OrderByDescending(e => e.ActionDateTime).ThenByDescending(e => e.EntryDateTime));
                b.Variety.Literal = vList.FirstOrDefault(v => v.Id == b.Variety.Id).Literal;
            }

            var journalModel = _modelFactory.CreateJournalModel();

            var batchItemsModel = _modelFactory.BuildBatchListItemModels(batchesDto);

            journalModel.Batches = batchItemsModel
                                   .OrderBy(r => r.BatchComplete)
                                   .ThenByDescending(r => r.Vintage)
                                   .ThenBy(r => r.Variety);

            // validate with User (ApplicationUser)
            var appUser = await UserManagerAgent.GetUserAsync(User).ConfigureAwait(false);

            journalModel.BatchJwt = await CreateJwtTokenAsync(appUser, 15).ConfigureAwait(false);

            return(View(journalModel));
        }
Beispiel #3
0
        public async Task <IActionResult> EditJournal(int id)
        {
            ViewData["Title"] = "Edit a Batch";

            var qry = _journalQueryFactory.CreateBatchesQuery();
            var dto = await qry.ExecuteAsync(id).ConfigureAwait(false);

            var entriesQuery = _journalQueryFactory.CreateBatchEntriesQuery();
            var entriesDto   = await entriesQuery.ExecuteByFKAsync(id).ConfigureAwait(true);

            var batchEntriesDto = entriesDto
                                  .OrderByDescending(e => e.ActionDateTime)
                                  .ThenByDescending(e => e.EntryDateTime).ToList();

            dto.Entries.AddRange(batchEntriesDto);

            var user = await UserManagerAgent.FindByIdAsync(dto.SubmittedBy).ConfigureAwait(false);

            var userVms = _mapper.Map <UserViewModel>(user);
            var model   = _modelFactory.CreateJournalViewModel(dto, userVms);

            return(View("UpdateJournal", model));
        }