예제 #1
0
        public async Task <IActionResult> AddTicket([FromBody] TicketView tv)
        {
            var oper = await _userManager.GetUserAsync(User);

            BusinessPoint bp = await _ctx.BusinessPoints
                               .Include(p => p.Owner)
                               .Where(p => p.Id == tv.BusinessPointId)
                               .SingleOrDefaultAsync();

            Ticket t = new Ticket {
                OperationDate = DateTime.Now, Amount = tv.Amount, Operator = oper, BusinessPoint = bp
            };

            _ctx.Tickets.Add(t);
            var result = await _ctx.SaveChangesAsync();

            if (result > 0)
            {
                decimal Amount = await _ctx.Tickets.Where(tt => tt.BusinessPoint.Id == bp.Id && tt.OperationDate.ToShortDateString() == DateTime.Now.ToShortDateString())
                                 .SumAsync(tt => tt.Amount);

                await _sc.GetChannel(bp.Owner.UserName).Writer.WriteAsync(new BusinessPointStats {
                    BusinessPointId = bp.Id, TotalAmount = Amount
                });

                return(CreatedAtAction(nameof(Get), new { id = t.Id }, tv));
            }
            return(BadRequest(tv));
        }
예제 #2
0
        private async Task Seed(IApplicationBuilder app)
        {
            using (var serviceScope = app.ApplicationServices.CreateScope())
            {
                // Get an instance of the DbContext from the DI container
                using (var context = serviceScope.ServiceProvider.GetService <ApplicationDbContext>())
                {
                    // perform database delete
                    if (await context.Database.EnsureCreatedAsync())
                    {
                        UserManager <ApplicationUser> um = serviceScope.ServiceProvider.GetService <UserManager <ApplicationUser> >();
                        RoleManager <IdentityRole>    rm = serviceScope.ServiceProvider.GetService <RoleManager <IdentityRole> >();
                        await rm.CreateAsync(new IdentityRole("Administrator"));

                        await rm.CreateAsync(new IdentityRole("Owner"));

                        await rm.CreateAsync(new IdentityRole("Operator"));

                        //Create trainer account
                        var user = new ApplicationUser {
                            UserName = "******", Email = "*****@*****.**"
                        };
                        var ir = await um.CreateAsync(user, "owner");

                        if (ir.Succeeded)
                        {
                            await um.AddToRoleAsync(user, "Owner");

                            await um.AddClaimAsync(user, new Claim(OpenIdConnectConstants.Claims.Subject, user.Id));
                        }
                        var oper = new ApplicationUser {
                            UserName = "******", Email = "*****@*****.**"
                        };
                        oper.Owner = user;
                        ir         = await um.CreateAsync(oper, "operator");

                        if (ir.Succeeded)
                        {
                            await um.AddToRoleAsync(oper, "Operator");

                            await um.AddClaimAsync(oper, new Claim(OpenIdConnectConstants.Claims.Subject, oper.Id));
                        }
                        var bp = new BusinessPoint {
                            Name = "Batut", Owner = user, Location = "Park", Price = 500, Duration = 15
                        };
                        context.Add(bp);
                        await context.SaveChangesAsync();
                    }
                }
            }
        }
예제 #3
0
        public async Task <IActionResult> Post([FromBody] BusinessPointView bpv)
        {
            var user = await _userManager.GetUserAsync(User);

            BusinessPoint bp = new BusinessPoint {
                Name     = bpv.Name,
                Location = bpv.Location,
                Price    = bpv.Price,
                Duration = bpv.Duration,
                Owner    = user
            };

            _ctx.Add(bp);
            var result = await _ctx.SaveChangesAsync();

            if (result > 0)
            {
                bpv.Id = bp.Id;
                return(CreatedAtAction(nameof(Get), new { id = bp.Id }, bpv));
            }
            return(BadRequest(bpv));
        }