Ejemplo n.º 1
0
        public override IForm <AddCustomerForm> BuildForm()
        {
            async Task onProcessAddCustomer(IDialogContext context, AddCustomerForm state)
            {
                GenericRepository <Customer> db = new GenericRepository <Customer>(GetDatabase.GetContext());

                Customer customer = new Customer
                {
                    Company   = state.Company,
                    FirstName = state.FirstName,
                    LastName  = state.LastName,
                    Address   = state.Address,
                    Username  = state.Username,
                    Phone     = state.Phone,
                    Status    = state.Status,
                    Email     = state.Email,
                    AddedOn   = DateTime.Now
                };

                db.Add(customer);
                db.SaveChanges();
            }

            return(new FormBuilder <AddCustomerForm>()
                   .Field(nameof(Username))
                   .Field(nameof(Company))
                   .Field(nameof(FirstName))
                   .Field(nameof(LastName))
                   .Field(nameof(Address))
                   .Field(nameof(Phone))
                   .Field(nameof(Email))
                   .Field(nameof(Status))
                   .OnCompletion(onProcessAddCustomer)
                   .Build());
        }
Ejemplo n.º 2
0
        private List <Product> GetProducts(Customer customer)
        {
            var products = GetDatabase.GetContext().Customers
                           .Where(c => c.Id == customer.Id)
                           .SelectMany(c => c.SalledProducts)
                           .Select(cp => cp.Product)
                           .ToList();

            return(products);
        }
Ejemplo n.º 3
0
        public override IForm <GetInfoForm> BuildForm()
        {
            async Task onProcessGetInfo(IDialogContext context, GetInfoForm state)
            {
                var customer = GetDatabase.GetContext().Customers.Where(c => c.Username == state.ClientName)
                               .FirstOrDefault();

                StringBuilder sb = new StringBuilder();

                var      id        = customer.Id;
                var      username  = customer.Username;
                var      company   = customer.Company;
                var      firstName = customer.FirstName;
                var      lastName  = customer.LastName;
                var      address   = customer.Address;
                var      phone     = customer.Phone;
                var      email     = customer.Email;
                DateTime addedOn   = customer.AddedOn;
                var      status    = customer.Status;

                sb.AppendLine($"ID: {id};  ");
                sb.AppendLine($"Username: {username};   ");
                sb.AppendLine($"Company: {company};   ");
                sb.AppendLine($"Name: {firstName + " " + lastName};   ");
                sb.AppendLine($"Address: {address};   ");
                sb.AppendLine($"Phone: {phone};  ");
                sb.AppendLine($"Email: {email};  ");
                sb.AppendLine($"Added On: {addedOn};  ");
                sb.AppendLine($"Status: {status};  ");

                var customerProducts = GetDatabase.GetContext().CustomerProducts.ToList();

                var salProd = customerProducts.Where(p => p.CustomerId == customer.Id).ToList();

                var products = GetProducts(customer);

                for (int i = 0; i < products.Count; i++)
                {
                    sb.AppendLine($"Product {i + 1}: {products[i].Name}.    ");
                }


                await context.PostAsync(sb.ToString());
            }

            return(new FormBuilder <GetInfoForm>()
                   .Field(nameof(ClientName))
                   .OnCompletion(onProcessGetInfo)
                   .Build());
        }
Ejemplo n.º 4
0
        public override IForm <GetEmailForm> BuildForm()
        {
            async Task onProcessGetEmail(IDialogContext context, GetEmailForm state)
            {
                var customer = GetDatabase.GetContext().Customers.Where(c => c.Username == state.ClientName)
                               .FirstOrDefault();

                var id    = customer.Id;
                var email = customer.Email;
                await context.PostAsync($"Client with ID: {id};" + $" Email: {email}");
            }

            return(new FormBuilder <GetEmailForm>()
                   .Field(nameof(ClientName))
                   .OnCompletion(onProcessGetEmail)
                   .Build());
        }