Beispiel #1
0
        public async Task <IActionResult> Post([FromBody] FaqQuestion question)
        {
            question.CreatedAt = DateTime.Now;
            await _context.FaqQuestions.AddAsync(question);

            await _context.SaveChangesAsync();

            return(Json(question));
        }
Beispiel #2
0
        public async Task Initialize()
        {
            var categories = new List <Category> {
                new Category {
                    Name = "Питание"
                },
                new Category {
                    Name = "Электронный журнал"
                },
                new Category {
                    Name = "Учебный процесс"
                },
                new Category {
                    Name = "Предложения и пожелания"
                },
                new Category {
                    Name = "Иное"
                },
            };

            var existingCategories = await _context.Categories.ToListAsync();

            var deleting = existingCategories.Where(ex => !categories.Select(c => c.Name).Contains(ex.Name)).ToList();

            var adding = categories.Where(c => !existingCategories.Select(ex => ex.Name).Contains(c.Name)).ToList();

            _context.Categories.RemoveRange(deleting);
            await _context.Categories.AddRangeAsync(adding);

            await _context.SaveChangesAsync();
        }