Exemplo n.º 1
0
        public List<CustomerModel> GetAllCustomers()
        {
            var customerList = new List<CustomerModel>();

            try
            {
                using (var db = new TankshopDbContext())
                {
                    var dbCustomers = db.Customers.ToList();

                    foreach (var c in dbCustomers)
                    {
                        var p = db.People.Find(c.Email);
                        var customer = new CustomerModel()
                        {
                            Email = p.Email,
                            Firstname = p.Firstname,
                            Lastname = p.Lastname,
                            Address = p.Address,
                            Zipcode = p.Zipcode,
                            City = p.Postal.City,
                            CustomerId = c.CustomerId,
                            Orders = c.Orders.Select(o => new OrderModel()
                            {
                                CustomerId = o.CustomerId,
                                Date = o.Date,
                                OrderId = o.OrderId,
                                Orderlines = o.Orderlines.Select(l => new OrderlineModel()
                                {
                                    Count = l.Count,
                                    OrderId = l.OrderId,
                                    OrderlineId = l.OrderlineId,
                                    ProductId = l.ProductId,
                                    ProductName = l.Product.Name,
                                    ProductPrice = l.Product.Price
                                }).ToList()
                            }).ToList()
                        };
                        customerList.Add(customer);
                    }
                    return customerList;
                }
            }
            catch (Exception)
            {
                return customerList;
            }
        }
Exemplo n.º 2
0
        public CustomerControllerTest()
        {
            orderlineModel = new OrderlineModel()
            {
                Count = 1,
                OrderId = 1,
                OrderlineId = 1,
                ProductId = 1,
                ProductName = "Tank",
                ProductPrice = 500000
            };

            orderlineModels = new List<OrderlineModel>();
            orderlineModels.Add(orderlineModel);
            orderlineModels.Add(orderlineModel);
            orderlineModels.Add(orderlineModel);

            orderModel = new OrderModel()
            {
                CustomerId = 1,
                Date = new DateTime(2015, 1, 1),
                OrderId = 1,
                Orderlines = orderlineModels
            };

            orderModels = new List<OrderModel>();
            orderModels.Add(orderModel);
            orderModels.Add(orderModel);
            orderModels.Add(orderModel);

            customerModel = new CustomerModel()
            {
                CustomerId = 1,
                Email = "*****@*****.**",
                Firstname = "Ole",
                Lastname = "Olsen",
                Address = "Persveien 5",
                Zipcode = "0123",
                City = "Oslo",
                Orders = orderModels
            };

            userEmail = "*****@*****.**";
            anotherUserEmail = "*****@*****.**";
            adminEmail = "admin";
        }
Exemplo n.º 3
0
        public CustomerModel GetCustomer(string email)
        {
            using (var db = new TankshopDbContext())
            {
                try
                {
                    var dbPerson = GetPerson(email);
                    var customerId = db.Customers.FirstOrDefault(c => c.Email == email).CustomerId;

                    var orderRepo = new OrderRepo();

                    var customer = new CustomerModel()
                    {
                        CustomerId = customerId,
                        Email = dbPerson.Email,
                        Firstname = dbPerson.Firstname,
                        Lastname = dbPerson.Lastname,
                        Address = dbPerson.Address,
                        Zipcode = dbPerson.Zipcode,
                        City = dbPerson.City,
                        Orders = orderRepo.GetOrders(customerId)
                    };

                    return customer;
                }
                catch (Exception)
                {
                    return null;
                }
            }
        }