Beispiel #1
0
        public async Task <IActionResult> SetBatchEntryCompleteAsync(int id, [FromBody] bool complete)
        {
            try
            {
                var entriesQuery = _queryFactory.CreateBatchesQuery();
                var entryDto     = await entriesQuery.ExecuteAsync(id).ConfigureAwait(false);

                if (entryDto != null)
                {
                    entryDto.Complete = complete;
                    var cmd = _commandsFactory.CreateBatchesCommand();
                    await cmd.UpdateAsync(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> Index(string id)
        {
            ViewData["Title"]    = _localizer["PageTitle"];
            ViewData["PageDesc"] = _localizer["PageDesc"];

            var getYeastQuery        = _yeastQueryFactory.CreateYeastsQuery();
            var getYeastPairs        = _yeastQueryFactory.CreateYeastPairQuery();
            var getCategoriesQuery   = _recipeQueryFactory.CreateCategoriesQuery();
            var getVarietiesQuery    = _recipeQueryFactory.CreateVarietiesQuery();
            var getRecipesQuery      = _recipeQueryFactory.CreateRecipesQuery();
            var getMaloCulturesQuery = _maloQueryFactory.CreateMaloCulturesQuery();
            var getJournalsQuery     = _journalQueryFactory.CreateBatchesQuery();

            // using TPL to parallel call gets
            List <Task> tasks = new List <Task>();

            var categoryTask = Task.Run(async() => await getCategoriesQuery.ExecuteAsync().ConfigureAwait(false));

            tasks.Add(categoryTask);
            var cList = await categoryTask.ConfigureAwait(false);

            var varietyTask = Task.Run(async() => await getVarietiesQuery.ExecuteAsync().ConfigureAwait(false));

            tasks.Add(varietyTask);
            var vList = await varietyTask.ConfigureAwait(false);

            var yeastTask = Task.Run(async() => await getYeastQuery.ExecuteAsync().ConfigureAwait(false));

            tasks.Add(yeastTask);
            var yList = await yeastTask.ConfigureAwait(false);

            var pairsTask = Task.Run(async() => await getYeastPairs.ExecuteAsync().ConfigureAwait(false));

            tasks.Add(pairsTask);
            var ypList = await pairsTask.ConfigureAwait(false);

            var recipeTask = Task.Run(async() => await getRecipesQuery.ExecuteAsync().ConfigureAwait(false));

            tasks.Add(recipeTask);
            var rList = await recipeTask.ConfigureAwait(false);

            var maloTask = Task.Run(async() => await getMaloCulturesQuery.ExecuteAsync().ConfigureAwait(false));

            tasks.Add(maloTask);
            var mList = await maloTask.ConfigureAwait(false);

            var journalTask = Task.Run(async() => await getJournalsQuery.ExecuteAsync().ConfigureAwait(false));

            tasks.Add(journalTask);
            var jList = await journalTask.ConfigureAwait(false);

            Task.WaitAll(tasks.ToArray());

            // build model
            var model = _modelFactory.CreateAdminModel(id);

            // make sure admin security role exist
            if (!await RoleManagerAgent.RoleExistsAsync(_appSettings.SecRole.Admin).ConfigureAwait(false))
            {
                ApplicationRole role = new ApplicationRole
                {
                    Name        = _appSettings.SecRole.Admin,
                    Description = "Perform all operations."
                };
                IdentityResult roleResult = await RoleManagerAgent.CreateAsync(role).ConfigureAwait(false);

                if (!roleResult.Succeeded)
                {
                    ModelState.AddModelError(string.Empty, "Error while creating role!");
                    return(View(model));
                }
            }

            // gather users data
            var users   = UserManagerAgent.Users.ToList();
            var userVms = _mapper.Map <List <UserViewModel> >(users);

            model.UsersViewModel.Users.Clear();
            model.UsersViewModel.Users.AddRange(userVms);

            foreach (var user in model.UsersViewModel.Users)
            {
                user.IsAdmin = await UserManagerAgent.IsInRoleAsync(user, _appSettings.SecRole.Admin).ConfigureAwait(false);

                user.IsLockedOut = await UserManagerAgent.IsLockedOutAsync(user).ConfigureAwait(false);
            }

            // gather roles data
            var roles = await RoleManagerAgent.Roles.OrderBy(r => r.Name).ToListAsync().ConfigureAwait(false);

            var roleVms = _mapper.Map <List <RoleViewModel> >(roles);

            model.RolesViewModel.Roles.Clear();
            model.RolesViewModel.Roles.AddRange(roleVms);

            // gather category / variety data
            model.CategoriesViewModel.Categories.Clear();
            model.CategoriesViewModel.Categories.AddRange(_modelFactory.CreateCategoryViewModel(cList));
            model.VarietiesViewModel.Varieties.Clear();
            model.VarietiesViewModel.Varieties.AddRange(_modelFactory.CreateVarietyViewModel(vList));

            // gather yeast data
            model.YeastsViewModel.Yeasts.Clear();
            model.YeastsViewModel.Yeasts.AddRange(_modelFactory.CreateYeastViewModel(yList));

            // gather malolactic data
            model.MaloCulturesViewModel.Cultures.Clear();
            model.MaloCulturesViewModel.Cultures.AddRange(_modelFactory.CreateMaloCultureViewModel(mList));

            // gather recipe data
            model.RecipesViewModel.Recipes.Clear();
            model.RecipesViewModel.Recipes.AddRange(_modelFactory.CreateRecipeViewModel(rList));

            // gather journal data
            model.JournalsViewModel.Journals.Clear();
            model.JournalsViewModel.Journals.AddRange(_modelFactory.CreateJournalViewModel(jList, userVms));

            return(View(model));
        }