/// <summary> /// Get or Add Authenciation Cache /// </summary> /// <param name="clientId">Spotify Client Id</param> /// <param name="clientSecret">Spotify Client Secret</param> /// <returns>Authentication Cache</returns> private static AuthenticationCache GetOrAddAuthenticationCache( string clientId, string clientSecret) { if (!_authenticationCaches.ContainsKey(clientId)) { AuthenticationCache authenticationCache = new AuthenticationCache( _authenticationClient, clientId, clientSecret); _authenticationCaches[clientId] = authenticationCache; } return(_authenticationCaches[clientId]); }
public IHttpActionResult OpenTable([FromUri] int tableId) { var connectionId = Request.GetConnectionId(); if (string.IsNullOrEmpty(connectionId)) { return(Unauthorized(Request.Headers.Authorization)); } var user = AuthenticationCache.GetUser(connectionId); if (user == null) { return(Unauthorized(AuthenticationHeaderValue.Parse(connectionId))); } var message = new OrderOpenMessage(connectionId) { TableId = tableId, State = new TableState { OcupiedByUserId = user.Id, OcupiedByUser = user.FullName, State = TableOcupation.Opened } }; _hub.SendAll(message); var order = _dbContext.FirstOrDefault <Order>(o => o.TableId == tableId && o.State == OrderState.Active) ?? new Order { State = OrderState.Opened, Created = DateTime.Now, Number = NumberGenerationFactory.GenerateNumber(_dbContext), TableId = tableId, UserId = user.Id }; order.Table = _dbContext.FirstOrDefault <Table>(table => table.Id == tableId); if (order.CustomerId.HasValue) { order.Customer = _dbContext.FirstOrDefault <Customer>(c => c.Id == order.CustomerId.Value); } if (order.Id != 0) { order.Items = _dbContext.Where <OrderItem>(oi => oi.OrderId == order.Id); } return(Ok(order)); }
public IHttpActionResult SaveOrder([FromBody] Order order) { var connectionId = Request.GetConnectionId(); if (string.IsNullOrEmpty(connectionId)) { return(Unauthorized(Request.Headers.Authorization)); } var user = AuthenticationCache.GetUser(connectionId); if (user == null || order.UserId != user.Id) { return(Unauthorized(AuthenticationHeaderValue.Parse(connectionId))); } if (order.Id == 0) { _orderRepository.Add(order); } else { _orderRepository.Save(order); } order.Table = _dbContext.FirstOrDefault <Table>(t => t.Id == order.TableId); var message = new OrderCreatedMessage(connectionId) { Order = order }; _hub.SendAll(message); return(Ok(order)); }