public WebContextData ShouldSendNotification(WebContextData data)
        {
            var storedWebOperationContext = new StoredWebOperationContext(data);
            var shouldContinue            = ShouldContinue(storedWebOperationContext);

            if (!shouldContinue)
            {
                storedWebOperationContext.ReturnStatusCode(HttpStatusCode.Forbidden, "");
            }
            return(data);
        }
        public WebContextData WhiteBoardV2UpdateSquare(Square square, int page, WebContextData data)
        {
            var storedWebOperationContext = new StoredWebOperationContext(data);
            var shouldContinue            = ShouldContinue(storedWebOperationContext);

            if (!shouldContinue)
            {
                storedWebOperationContext.ReturnStatusCode(HttpStatusCode.Forbidden, "");
                return(data);
            }

            _whiteboardV2Proxy.UpdateSquare(page, square);
            return(data);
        }
        public WebContextData WhiteBoardV2SaveChanges(int page, WebContextData data)
        {
            var storedWebOperationContext = new StoredWebOperationContext(data);
            var shouldContinue            = ShouldContinue(storedWebOperationContext);

            if (!shouldContinue)
            {
                storedWebOperationContext.ReturnStatusCode(HttpStatusCode.Forbidden, "");
                return(data);
            }

            _whiteboardV2Proxy.SaveChanges(page);
            return(data);
        }
        public WebContextData WhiteBoardV1AddItem(int item, int page, WebContextData data)
        {
            var storedWebOperationContext = new StoredWebOperationContext(data);
            var shouldContinue            = ShouldContinue(storedWebOperationContext);

            if (!shouldContinue)
            {
                storedWebOperationContext.ReturnStatusCode(HttpStatusCode.Forbidden, "");
                return(data);
            }

            _whiteboardV1.AddItem(item, page);
            return(data);
        }
        public void UpdateContext(WebContextData data)
        {
            if (WebOperationContext.Current != null)
            {
                WebOperationContext.Current.OutgoingResponse.Headers[HttpResponseHeader.SetCookie] = "";

                foreach (var cookie in data.CookiesOut.Keys)
                {
                    WebOperationContext.Current.OutgoingResponse.Headers[HttpResponseHeader.SetCookie] = $"{cookie.ToLower()}={data.CookiesOut[cookie]}; path=/;";
                }

                WebOperationContext.Current.OutgoingResponse.StatusCode = data.StatusCode;

                WebOperationContext.Current.OutgoingResponse.StatusDescription = data.StatusMessage;
            }
        }
        public GetSquaresV2 WhiteBoardV2GetSquares(int page, WebContextData data)
        {
            var storedWebOperationContext = new StoredWebOperationContext(data);
            var shouldContinue            = ShouldContinue(storedWebOperationContext);

            if (!shouldContinue)
            {
                storedWebOperationContext.ReturnStatusCode(HttpStatusCode.Forbidden, "");
                return(new GetSquaresV2 {
                    Data = data
                });
            }

            return(new GetSquaresV2 {
                Data = data, Squares = _whiteboardV2Proxy.GetSquares(page)
            });
        }
        public WebContextData Logout(WebContextData data)
        {
            var storedWebOperationContext = new StoredWebOperationContext(data);
            var shouldContinue            = ShouldContinue(storedWebOperationContext);

            if (!shouldContinue)
            {
                storedWebOperationContext.ReturnStatusCode(HttpStatusCode.Forbidden, "");
                return(data);
            }

            var sessionId = GetSessionId(storedWebOperationContext);

            Debug.Assert(sessionId != null, $"{nameof(sessionId)} != null");
            _authentication.Logout(sessionId.Value);
            return(data);
        }
        public GetItemsV1 WhiteBoardV1GetItems(int page, WebContextData data)
        {
            var storedWebOperationContext = new StoredWebOperationContext(data);
            var shouldContinue            = ShouldContinue(storedWebOperationContext);

            if (!shouldContinue)
            {
                storedWebOperationContext.ReturnStatusCode(HttpStatusCode.Forbidden, "");
                return(new GetItemsV1 {
                    Data = data
                });
            }

            return(new GetItemsV1 {
                Data = data, Items = _whiteboardV1.GetItems(page)
            });
        }
        public WebContextData Login(string userName, string password, WebContextData data)
        {
            var storedWebOperationContext = new StoredWebOperationContext(data);

            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
            {
                storedWebOperationContext.ReturnStatusCode(HttpStatusCode.BadRequest, "Wrong userName/password");
                return(data);
            }

            var sessionId = _authentication.Login(userName, password);

            if (sessionId == null)
            {
                storedWebOperationContext.ReturnStatusCode(HttpStatusCode.NotFound, "User not exists or wrong userName/password");
                return(data);
            }

            storedWebOperationContext.AddCookie("sessionId", sessionId.Value.ToString());
            return(data);
        }
        public InsertSquareV2 WhiteBoardV2InsertSquare(int left, int top, int page, WebContextData data)
        {
            var storedWebOperationContext = new StoredWebOperationContext(data);
            var shouldContinue            = ShouldContinue(storedWebOperationContext);

            if (!shouldContinue)
            {
                storedWebOperationContext.ReturnStatusCode(HttpStatusCode.Forbidden, "");
                return(new InsertSquareV2 {
                    Data = data
                });
            }

            var square = new Square {
                Id = Guid.NewGuid(), Left = left, Top = top
            };

            _whiteboardV2Proxy.UpdateSquare(page, square);
            return(new InsertSquareV2 {
                Data = data, Id = square.Id
            });
        }
 public StoredWebOperationContext(WebContextData data)
 {
     _data = data;
 }