Ejemplo n.º 1
0
 public IHttpActionResult GridData([FromBody] GridDataRequest request)
 {
     using (var context = new SampleDbContext(false))
     {
         return Ok(request.CreateGridDataResponse(context.SystemUsers.AsNoTracking()));
     }
 }
Ejemplo n.º 2
0
 public async Task<IHttpActionResult> GridData([FromBody] GridDataRequest request)
 {
     using (var context = new SampleDbContext(false))
     {
         return Ok(await Task.Run(() => request.CreateGridDataResponse(context.Orders.AsNoTracking())));
     }
 }
Ejemplo n.º 3
0
        public async Task<IHttpActionResult> CreateOrder([FromBody] Order order)
        {
            using (var context = new SampleDbContext(false))
            {
                context.Orders.Add(order);
                await context.SaveChangesAsync();

                return Ok(new
                {
                    Status = "OK"
                });
            }
        }
Ejemplo n.º 4
0
        public async Task<IHttpActionResult> Get(string id)
        {
            using (var context = new SampleDbContext(false))
            {
                var orderId = int.Parse(id);
                var order = await context.Orders.AsNoTracking().Where(o => o.OrderID == orderId).FirstOrDefaultAsync();

                if (order == null)
                    return NotFound();

                return Ok(order);
            }
        }
Ejemplo n.º 5
0
            public static void Configure(IAppBuilder app)
            {
                var authFunc =
                    new Func<OAuthGrantResourceOwnerCredentialsContext, Task<Security.UserAuthenticationResult>>((c) =>
                    {
                        var task = new Task<Security.UserAuthenticationResult>(() =>
                        {

                            using (var context = new SampleDbContext())
                            {
                                var user =
                                    context.SystemUsers.FirstOrDefault(
                                        u => u.Id == c.UserName && u.Password == c.Password);

                                if (user != null)
                                {
                                    var roles = user.Roles.ToArray();
                                    return Security.UserAuthenticationResult.CreateAuthorizedResult(user, roles);
                                }

                                return Security.UserAuthenticationResult.CreateErrorResult("Invalid credentials");
                            }

                        });

                        task.Start();
                        return task;
                    });

                var authServerOptions = new OAuthAuthorizationServerOptions()
                {
                    AllowInsecureHttp = true,
                    TokenEndpointPath = new PathString("/token"),
                    AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
                    Provider = new Security.BasicOAuthAuthorizationProvider(authFunc),
                    AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active,
                    AuthenticationType = "Bearer"
                };

                var bearerAuthOptions = new OAuthBearerAuthenticationOptions()
                {
                    AuthenticationType = authServerOptions.AuthenticationType,
                    AuthenticationMode = authServerOptions.AuthenticationMode,
                    AccessTokenFormat = authServerOptions.AccessTokenFormat,
                    AccessTokenProvider = authServerOptions.AccessTokenProvider,
                };

                // Token Generation
                app.UseOAuthAuthorizationServer(authServerOptions);
                app.UseOAuthBearerAuthentication(bearerAuthOptions);
            }
Ejemplo n.º 6
0
        public async Task<IHttpActionResult> DeleteOrder(string id)
        {
            using (var context = new SampleDbContext(false))
            {
                var orderId = int.Parse(id);
                var orderDb = await context.Orders.Where(o => o.OrderID == orderId).FirstOrDefaultAsync();

                if (orderDb == null)
                    return NotFound();

                context.Orders.Remove(orderDb);

                await context.SaveChangesAsync();

                return Ok(new
                {
                    Status = "OK"
                });
            }
        }
Ejemplo n.º 7
0
        public async Task<IHttpActionResult> UpdateOrder([FromBody] GridDataUpdateRow<Order> request)
        {
            using (var context = new SampleDbContext(false))
            {
                var order = await context.Orders.Where(o => o.OrderID == request.Old.OrderID).FirstOrDefaultAsync();

                if (order == null)
                    return NotFound();

                order.Amount = request.New.Amount;
                order.CustomerName = request.New.CustomerName;
                order.IsShipped = request.New.IsShipped;
                order.ShippedDate = request.New.ShippedDate;
                order.ShipperCity = request.New.ShipperCity;

                await context.SaveChangesAsync();

                return Ok(new
                {
                    Status = "OK"
                });
            }
        }
Ejemplo n.º 8
0
 public async Task<IHttpActionResult> GetCities()
 {
     using (var context = new SampleDbContext(false))
     {
         return
             Ok(
                 await
                     context.Orders.AsNoTracking()
                         .Select(x => x.ShipperCity)
                         .Distinct()
                         .OrderBy(x => x)
                         .ToListAsync());
     }
 }