Exemplo n.º 1
0
        public async Task <IActionResult> OpenSaleBox(double?ApertureValue)
        {
            if (_openBox.GetSaleBox() == null)
            {
                SaleBox box = await _saleBoxRepository.FindByHasOpenBoxAsync(_employeeLogin.GetEmployee().Id);

                if (box == null)
                {
                    SaleBox saleBox = new SaleBox();
                    saleBox.Opening         = DateTime.Now;
                    saleBox.ApertureValue   = (ApertureValue is null ? 0.0 : (double)ApertureValue);
                    saleBox.RegisterSalesId = _employeeLogin.GetEmployee().Id;

                    await _saleBoxRepository.InsertAsync(saleBox);

                    _openBox.SetBox(saleBox);
                    return(RedirectToAction(nameof(Box)));
                }
                else
                {
                    _openBox.SetBox(box);
                    return(RedirectToAction(nameof(Box)));
                }
            }
            return(RedirectToAction(nameof(Box)));
        }
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            _openBox = (OpenBox)context.HttpContext.RequestServices.GetService(typeof(OpenBox));

            if (_openBox.GetSaleBox() == null)
            {
                context.Result = new RedirectToActionResult("Box", "Sales", new { Area = "Employee" }, "#ClosedBox");
            }
        }