public async Task <Unit> Handle(DeleteOrderCommand request, CancellationToken cancellationToken)
        {
            //check whether the order is assigned to any sale process
            IQueryable <SaleProcess> saleProcess = _context.SaleProcess.Where(x => x.OrderId.Equals(request.Order.Id.ToString()));

            //erase the order from the whole sale process
            if (saleProcess.Count() > 0)
            {
                foreach (SaleProcess process in saleProcess)
                {
                    process.OrderId = null;
                }
            }

            await _operationsRepository.Delete(request.Order.DateOrderOpened, request.Order.UserId);

            _context.Remove(request.Order);

            var success = await _context.SaveChangesAsync() > 0;

            if (success)
            {
                return(Unit.Value);
            }

            throw new Exception("Problem saving changes");
        }
        private async Task DowngradeLead(SaleProcess lastProcess, User user)
        {
            Operation previousOperation = lastProcess.Operation;

            await _operationsRepository.Delete(previousOperation.Date, user.Id);

            _context.SaleProcess.Remove(lastProcess);
        }
Esempio n. 3
0
        public ActionResult DeleteOperation(int id)
        {
            var operation = _operationsRepository.GetById(id);

            if (operation == null)
            {
                return(NotFound());
            }

            _operationsRepository.Delete(operation);
            _operationsRepository.SaveChanges();
            _notificationHub.Clients.All.SendAsync("SendMessage", "OperationDeleted");
            return(NoContent());
        }
        public async Task <Unit> Handle(AbandonLeadCommand request, CancellationToken cancellationToken)
        {
            IQueryable <SaleProcess> saleProcess = _context.SaleProcess.Where(x => x.ContactId == request.Lead.Id);

            foreach (SaleProcess process in saleProcess)
            {
                _context.SaleProcess.Remove(process);

                if (!request.KeepRecords)
                {
                    await _operationsRepository.Delete(process.Operation.Date, request.UserId);
                }
            }
            Console.WriteLine(request.SaveLead);
            if (request.SaveLead)
            {
                request.Lead.Status = "Inactive";
            }
            else
            {
                var userContact = await _context.UserContacts.FindAsync(request.UserId, request.Lead.Id);

                if (userContact != null)
                {
                    _context.UserContacts.Remove(userContact);
                }
                _context.Remove(request.Lead);
            }

            var success = await _context.SaveChangesAsync() > 0;

            if (success)
            {
                return(Unit.Value);
            }

            throw new Exception("Problem saving changes");
        }
 public ActionResult <Operations> DeleteOperaions(int id)
 {
     return(Ok(_IOperationsRepository.Delete(id)));
 }