예제 #1
0
        public IActionResult Delete([FromBody] int id)
        {
            if (id <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(id));
            }

            var cashOrder = _repository.Get(id);

            if (cashOrder == null)
            {
                throw new InvalidOperationException();
            }
            if (!cashOrder.CreatedToday && !_sessionContext.ForSupport)
            {
                throw new PawnshopApplicationException("Удалять можно только кассовые ордеры за сегодняшний день");
            }

            var count = _repository.RelationCount(id);

            if (count > 0)
            {
                throw new Exception("Невозможно удалить кассовый ордер, так как он привязан к другим документам");
            }

            _repository.Delete(id);
            return(Ok());
        }
예제 #2
0
        public IActionResult Cancel([FromBody] int id)
        {
            if (id <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(id));
            }

            var selling = _repository.Get(id);

            if (selling.Status != SellingStatus.Sold)
            {
                throw new PawnshopApplicationException("Не возможно отменить продажу у непроданного изделия");
            }

            if (!selling.CashOrderId.HasValue)
            {
                throw new PawnshopApplicationException("Не найден приходный кассовый ордер, отмена не возможна");
            }

            using (var transaction = _repository.BeginTransaction())
            {
                _cashOrderRepository.Delete(selling.CashOrderId.Value);

                selling.SellingCost = null;
                selling.SellingDate = null;
                selling.Status      = SellingStatus.InStock;
                selling.CashOrderId = null;

                _repository.Update(selling);

                transaction.Commit();
            }

            return(Ok());
        }
예제 #3
0
        public void ReceiveCancel([FromBody] int id)
        {
            if (id <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(id));
            }

            var model = _remittanceRepository.Get(id);

            if (model == null)
            {
                throw new InvalidOperationException();
            }
            if (model.Status != RemittanceStatusType.Received)
            {
                throw new PawnshopApplicationException("Невозможно отменять непринятые переводы");
            }
            if (model.CreateDate.Date != DateTime.Today)
            {
                throw new PawnshopApplicationException("Данное действие отмене не подлежит.");
            }

            if (model.ContractId.HasValue)
            {
                throw new PawnshopApplicationException("Невозможно отменить порожденный перевод");
            }

            using (var transaction = _remittanceRepository.BeginTransaction())
            {
                model.ReceiveUserId = null;
                model.ReceiveDate   = null;
                model.Status        = RemittanceStatusType.Sent;

                _orderRepository.Delete(model.SendOrderId.Value);
                _eventLog.Log(EventCode.CashOrderDeleted, EventStatus.Success, EntityType.CashOrder, model.SendOrderId.Value, null, null);
                model.SendOrderId = null;

                _orderRepository.Delete(model.ReceiveOrderId.Value);
                _eventLog.Log(EventCode.CashOrderDeleted, EventStatus.Success, EntityType.CashOrder, model.ReceiveOrderId.Value, null, null);
                model.ReceiveOrderId = null;

                _remittanceRepository.Update(model);

                transaction.Commit();
            }
        }
예제 #4
0
        public void Cancel([FromBody] InsuranceAction action)
        {
            ModelState.Validate();

            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }
            if (action.InsuranceId <= 0)
            {
                throw new ArgumentException();
            }

            if (action.ActionDate.Date != DateTime.Today)
            {
                throw new PawnshopApplicationException("Данное действие отмене не подлежит.");
            }

            var insurance = _insuranceRepository.Get(action.InsuranceId);

            using (var transaction = _actionRepository.BeginTransaction())
            {
                switch (action.ActionType)
                {
                case InsuranceActionType.Sign:
                    if (insurance.Status != InsuranceStatus.Signed)
                    {
                        throw new InvalidOperationException();
                    }
                    insurance.Status = InsuranceStatus.Draft;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                _orderRepository.Delete(action.OrderId);
                _eventLog.Log(EventCode.CashOrderDeleted, EventStatus.Success, EntityType.CashOrder, action.OrderId, null, null);
                _insuranceRepository.Update(insurance);
                _actionRepository.Delete(action.Id);

                transaction.Commit();
            }
        }