public async Task <ActionResult <Counter> > AddCounter([FromBody] CounterBinding binding,
                                                               CancellationToken cancellationToken)
        {
            var dbCounter = await _context.Counters
                            .AsNoTracking()
                            .Where(o => o.Type == binding.Type)
                            .SingleOrDefaultAsync();

            if (dbCounter != null)
            {
                return(BadRequest($"Counter with Type: {binding.Type} already created"));
            }

            var counter = new Counter()
            {
                Id     = Guid.NewGuid(),
                Type   = binding.Type,
                Amount = binding.Amount
            };


            _context.Counters.Add(counter);
            await _context.SaveChangesAsync(cancellationToken);

            return(Ok(counter));
        }
Example #2
0
        public async Task <ActionResult <Admin> > CreateTestAdmin()
        {
            var count = await _context.Admins.CountAsync();

            if (count > 0)
            {
                return(BadRequest("Admin exists"));
            }

            var admin = new Admin()
            {
                Id         = Guid.NewGuid(),
                FirstName  = "Ñàçîíîâ",
                MiddleName = "Èâàí",
                LastName   = "Âàñèëüåâè÷",
                Login      = "******",
                Password   = "******",
                Phone      = "+79225401010",
                Role       = AdminRole.Admin
            };

            _context.Admins.Add(admin);
            await _context.SaveChangesAsync();

            return(Ok(admin));
        }
        public async Task <ActionResult <NewsPost> > CreateNewsPost(
            [FromBody] CreateNewsBinding binding,
            CancellationToken cancellationToken)
        {
            var newsPost = new NewsPost()
            {
                Id         = Guid.NewGuid(),
                CreateDate = DateTime.Now,
                Title      = binding.Title,
                Text       = binding.Text,
                Type       = binding.Type
            };

            _context.NewsPosts.Add(newsPost);

            await _context.SaveChangesAsync(cancellationToken);

            return(Ok(newsPost));
        }