private async Task UpgradeLead(SaleProcess lastProcess, string upgradeTo, Contact contact, User user)
        {
            var newOperation = new Operation();

            switch (upgradeTo)
            {
            case "Opportunity":
                newOperation.Opportunity = true;
                break;

            case "Quote":
                newOperation.Quote = true;
                break;

            case "Invoice":
                newOperation.Invoice = true;
                break;
            }
            newOperation.Date = DateTime.Now;

            await _operationsRepository.Add(newOperation, user);

            var newProcess = new SaleProcess
            {
                Operation   = newOperation,
                OperationId = newOperation.Id,
                Contact     = contact,
                ContactId   = contact.Id,
                OrderId     = lastProcess.OrderId ?? null,
                Index       = lastProcess.Index + 1
            };

            await _context.SaleProcess.AddAsync(newProcess);
        }
        public async Task<Unit> Handle(StartSaleProcessCommand request, CancellationToken cancellationToken)
        {
            var user = await _userAccessor.GetLoggedUser();

            request.Contact.Status = "Lead";

            var operation = new Operation();
            operation.Lead = true;
            operation.Source = "Former Client";
            operation.Date = DateTime.Now;

            await _operationsRepository.Add(operation, user);

            var saleProcess = new SaleProcess
            {
                Contact = request.Contact,
                ContactId = request.Contact.Id,
                Operation = operation,
                OperationId = operation.Id,
                OrderId = null,
                Index = 0
            };

            _context.SaleProcess.Add(saleProcess);

            request.Contact.CurrentSale.Add(saleProcess);

            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);
        }
Пример #4
0
        private static void Seed(DataContext context)
        {
            var user = new User
            {
                Id          = "00000000-0000-0000-0000-000000000001",
                UserName    = "******",
                DisplayName = "Test User ",
                Email       = "@test",
                Level       = "mid"
            };

            context.Users.Add(user);

            for (int i = 10; i < 24; i++)
            {
                var contact = new Contact
                {
                    Id          = new Guid(i + "000000-0000-0000-0000-000000000000"),
                    Name        = "Test Contact " + i,
                    Status      = "Inactive",
                    Company     = i + " company",
                    Email       = i + "@test",
                    DateAdded   = DateTime.Now,
                    CurrentSale = new List <SaleProcess>()
                };

                var userContact = new UserContact
                {
                    Id        = Guid.NewGuid(),
                    ContactId = contact.Id,
                    UserId    = user.Id,
                    Contact   = contact,
                    User      = user
                };

                if (i % 2 == 0)
                {
                    contact.Status = "Lead";
                    contact.Source = "Web";

                    var saleProcess = new SaleProcess()
                    {
                        Contact     = contact,
                        ContactId   = new Guid(i + "000000-0000-0000-0000-000000000000"),
                        Operation   = new Operation(),
                        OperationId = Guid.NewGuid(),
                        OrderId     = null,
                        Index       = i,
                    };

                    if (i % 4 == 0)
                    {
                        var order = new Order
                        {
                            Id              = Guid.NewGuid(),
                            OrderNumber     = context.Orders.CountAsync().Result + 1,
                            Type            = true,
                            Product         = "Test product",
                            Amount          = i * 5,
                            Price           = i * 50,
                            DateOrderOpened = DateTime.Now,
                            Client          = contact,
                            ClientId        = contact.Id,
                            UserId          = user.Id,
                        };

                        context.Orders.Add(order);
                    }

                    contact.CurrentSale.Add(saleProcess);
                    context.SaleProcess.Add(saleProcess);
                }

                context.Contacts.Add(contact);
                context.UserContacts.Add(userContact);
            }

            context.SaveChanges();
        }
Пример #5
0
        public async Task <Unit> Handle(AddLeadCommand request, CancellationToken cancellationToken)
        {
            var contact = new Contact
            {
                Id              = Guid.NewGuid(),
                Name            = request.Contact.Name,
                Type            = "Client",
                Company         = request.Contact.Company,
                PhoneNumber     = request.Contact.PhoneNumber,
                DateAdded       = DateTime.Now,
                Email           = request.Contact.Email,
                Notes           = request.Contact.Notes,
                Status          = "Lead",
                Source          = request.Contact.Source,
                Premium         = false,
                SuccessfulDeals = 0
            };

            _context.Contacts.Add(contact);

            var userAccess = new UserContact
            {
                Id        = Guid.NewGuid(),
                User      = request.User,
                UserId    = request.User.Id,
                Contact   = contact,
                ContactId = contact.Id,
                DateAdded = request.Contact.DateAdded
            };

            _context.UserContacts.Add(userAccess);

            var operation = new Operation();

            operation.Lead   = true;
            operation.Source = request.Contact.Source;
            operation.Date   = contact.DateAdded;

            var saveOperation = await _operationsRepository.Add(operation, request.User);

            if (!saveOperation)
            {
                throw new Exception("Problem saving operation");
            }

            var saleProcess = new SaleProcess
            {
                Contact     = contact,
                ContactId   = contact.Id,
                Operation   = operation,
                OperationId = operation.Id,
                OrderId     = null,
                Index       = 0
            };

            _context.SaleProcess.Add(saleProcess);

            contact.CurrentSale.Add(saleProcess);

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

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

            throw new Exception("Problem saving changes");
        }