Example #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var existingRecord = await DataContext.HomeReviewFeatures.FirstOrDefaultAsync(r => r.Title == Title);

            var sortOrder = await DataContext.HomeReviewFeatures.MaxAsync(r => (int?)r.SortOrder) ?? -1;

            if (existingRecord is null)
            {
                existingRecord = new Data.Models.HomeReviewFeature {
                    Title             = Title,
                    FeatureCategoryId = FeatureCategory.Id,
                    SortOrder         = sortOrder + 1,
                };

                DataContext.Add(existingRecord);
                await DataContext.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Example #2
0
        public IActionResult OnGet(int?id)
        {
            if (id is not null)
            {
                Feature = DataContext.HomeReviewFeatures.Find(id);
            }

            if (Feature is null)
            {
                return(NotFound());
            }

            return(Page());
        }