Example #1
0
        /// <summary>
        /// Retreives the details for a specified customer
        /// </summary>
        /// <param name="username">The customers name</param>
        /// <returns>A packet to send to the console to display the data</returns>
        public Packet <Customer> GetCustomerDetailsByNamePacket(string username)
        {
            Customer          customer;
            Packet <Customer> msg = new Packet <Customer> {
                Text = "", Status = PacketStatus.NULL
            };


            using (var ctx = new VendorContext())
            {
                CustomerService cServ = new CustomerService(ctx);
                customer = cServ.FindByUsername(username);
            }
            if (customer != null)
            {
                msg.Text   = $"Username: {customer.Username} | email: {customer.Email} | # of Orders: {customer.OrderHistory.Count}";
                msg.Status = PacketStatus.Pass;
            }
            else
            {
                msg.Text   = "A user wasn't found with that name, please try again";
                msg.Status = PacketStatus.Invalid;
            }

            return(msg);
        }
 /// <summary>
 /// Returns a list of all the Customers found within the DB
 /// </summary>
 /// <returns>List of Customers</returns>
 public List <Customer> FindAll()
 {
     using (var ctx = new VendorContext())
     {
         return(ctx.Customers.ToList());
     }
 }
Example #3
0
        internal void AddLocationsWithInventory()
        {
            AddSomeProducts();
            AddLocations();


            using (var ctx = new VendorContext())
            {
                ProductInventorieService pIServ = new ProductInventorieService(ctx);
                LocationService          lServ  = new LocationService(ctx);
                ProductService           pServ  = new ProductService(ctx);

                var prod1 = pServ.FindByName("Stimpak");
                var prod2 = pServ.FindByName("Buffout");
                var prod3 = pServ.FindByName("10mm");

                var loc1 = lServ.FindByName("The Mojave Wasteland");

                lServ.AddProductToInventory(loc1.LocationId, prod1.ProductId, 1);
                lServ.AddProductToInventory(loc1.LocationId, prod2.ProductId, 4);

                var loc2 = lServ.FindByName("The Capital Warehouse Store");
                lServ.AddProductToInventory(loc2.LocationId, prod3.ProductId, 1);
                lServ.AddProductToInventory(loc2.LocationId, prod2.ProductId, 4);
            }
        }
Example #4
0
        /// <summary>
        /// Retreives a list of all registered users in the DB into a Packet.  Formats a the list of customers
        /// in the Text response of the packet and also stores it as a list in the DataList property.
        /// </summary>
        /// <returns></returns>
        public Packet <Customer> GetCustomerList()
        {
            Packet <Customer> packet = new Packet <Customer>();

            using var ctx = new VendorContext();
            CustomerService cServ     = new CustomerService(ctx);
            List <Customer> customers = cServ.FindAll();

            if (customers.Count == 0)
            {
                packet.Text   = "No Customers were found";
                packet.Status = PacketStatus.Pass;
            }
            else
            {
                packet.DataList = customers;

                packet.Text += "List of Customers:\n";
                // Loop through each customer and create a List of their names
                foreach (var customer in customers)
                {
                    packet.Text += $"{customer.Username}\n";
                }

                packet.Status = PacketStatus.Pass;
            }

            return(packet);
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StoriesRepository" /> class.
        /// </summary>
        /// <param name="repositoryContext">The repository context.</param>
        /// <param name="mapper">The mapper.</param>
        /// <param name="sortHelper">The sort helper.</param>
        /// <param name="dataShaper">The data shaper.</param>

        public ServiceRepository(VendorContext repositoryContext, IMapper mapper, ISortHelper <ServiceResponse> sortHelper,
                                 IDataShaper <ServiceResponse> dataShaper) : base(repositoryContext)
        {
            this.mapper     = mapper;
            this.sortHelper = sortHelper;
            this.dataShaper = dataShaper;
        }
Example #6
0
 static DbTransactionHolder()
 {
     Context            = new VendorContext();
     DefaultDbEquipment = new List <EquipmentElement>();
     LargeDbEquipment   = new List <EquipmentElement>();
     SetDefaultEquipmentLists();
     UpdateDatabase += () => Console.WriteLine("Begin Updating Database");
 }
 /// <summary>
 /// Returns a list of all known locations
 /// </summary>
 /// <returns></returns>
 public List <Location> GetAllLocations()
 {
     using (var ctx = new VendorContext())
     {
         LocationService locationService = new LocationService(ctx);
         return(locationService.FindAll());
     }
 }
        /// <summary>
        /// Returns a list of products
        /// </summary>
        /// <returns></returns>
        public List <Product> GetProductList()
        {
            using (var ctx = new VendorContext())
            {
                ProductService productService = new ProductService(ctx);

                return(productService.FindAll());
            }
        }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StoriesRepository" /> class.
 /// </summary>
 /// <param name="repositoryContext">The repository context.</param>
 /// <param name="mapper">The mapper.</param>
 /// <param name="sortHelper">The sort helper.</param>
 /// <param name="dataShaper">The data shaper.</param>
 public SubscriptionOffersRepository(
     VendorContext repositoryContext,
     IMapper mapper,
     ISortHelper <SubscriptionOfferResponse> sortHelper,
     IDataShaper <SubscriptionOfferResponse> dataShaper)
     : base(repositoryContext)
 {
     this.mapper     = mapper;
     this.sortHelper = sortHelper;
     this.dataShaper = dataShaper;
 }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CategoryDetailsRepository" /> class.
 /// </summary>
 /// <param name="repositoryContext">The repository context.</param>
 /// <param name="mapper">The mapper.</param>
 /// <param name="sortHelper">The sort helper.</param>
 /// <param name="dataShaper">The data shaper.</param>
 public CategoryDetailsRepository(
     VendorContext repositoryContext,
     IMapper mapper,
     ISortHelper <CategoryDetailsResponse> sortHelper,
     IDataShaper <CategoryDetailsResponse> dataShaper)
     : base(repositoryContext)
 {
     this.mapper     = mapper;
     this.sortHelper = sortHelper;
     this.dataShaper = dataShaper;
 }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VendorQuestionAsnwerRepository" /> class.
 /// </summary>
 /// <param name="repositoryContext">The repository context.</param>
 /// <param name="mapper">The mapper.</param>
 /// <param name="sortHelper">The sort helper.</param>
 /// <param name="dataShaper">The data shaper.</param>
 public VendorQuestionAsnwerRepository(
     VendorContext repositoryContext,
     IMapper mapper,
     ISortHelper <VendorQuestionAnswerResponse> sortHelper,
     IDataShaper <VendorQuestionAnswerResponse> dataShaper)
     : base(repositoryContext)
 {
     this.mapper     = mapper;
     this.sortHelper = sortHelper;
     this.dataShaper = dataShaper;
 }
        // TODO implement the following
        // get, add, update, set customer

        /// <summary>
        /// Searches for and retrieves a product entity via name.
        /// </summary>
        /// <param name="productName">The name of the desired product to retrieve</param>
        /// <returns>Product with matching name</returns>
        public Product FindProductByName(string productName)
        {
            Product product;

            using (var ctx = new VendorContext())
            {
                ProductService productService = new ProductService(ctx);
                product = productService.FindByName(productName);
            }

            return(product);
        }
Example #13
0
        /// <summary>
        /// Retrieves Customer from the DB with a specified first name
        /// </summary>
        /// <param name="firstName">The name to search for</param>
        /// <returns>A Customer with the matching firstName or NULL if none is found</returns>
        public Customer FindCustomerByUsername(string username)
        {
            Customer customer;

            using (var ctx = new VendorContext())
            {
                CustomerService cServ = new CustomerService(ctx);
                customer = cServ.FindByUsername(username);
            }

            return(customer);
        }
        // TODO implement the following
        // get, add, update, set customer

        /// <summary>
        /// Retrieves data of a Location specified by it's name using the DataAccess functionality
        /// </summary>
        /// <param name="locationName">Name of the desired location to retrieve</param>
        /// <returns>The data of the desired Location</returns>
        public Location GetLocationByName(string locationName)
        {
            Location location;

            using (var ctx = new VendorContext())
            {
                LocationService locationService = new LocationService(ctx);
                location = locationService.FindByName(locationName);
            }

            return(location);
        }
        /// <summary>
        /// Retrieves a list of Orders that a customer has made
        /// </summary>
        /// <param name="username">Name of the Customer the order was made from</param>
        /// <returns>A list of Orders made from a specifed Customer</returns>
        public List <Order> FindOrdersByCustomerName(string username)
        {
            List <Order> customerOrders;

            using (var ctx = new VendorContext())
            {
                OrderService orderService = new OrderService(ctx);
                customerOrders = orderService.FindOrdersByCustomersName(username);
            }

            return(customerOrders);
        }
        /// <summary>
        /// Update's the inventory record of the amount of a Location's specific product
        /// </summary>
        /// <param name="location">The Location who's inentory will be updated</param>
        /// <param name="product">The product that will be added/removed from the location</param>
        /// <param name="quantity">The new quantity of the prouct that the current location will carry.</param>
        /// <returns></returns>
        public ProductInventory UpdateInventory(Location location, Product product, int quantity)
        {
            ProductInventory productInventory;

            using (var ctx = new VendorContext())
            {
                ProductInventorieService pIS = new ProductInventorieService(ctx);
                productInventory = pIS.UpdateInventory(location, product, quantity);
            }

            return(productInventory);
        }
        /// <summary>
        /// Retrieves the inventory of a Product from a certain Location
        /// </summary>
        /// <param name="location">The Location used to find the inventory</param>
        /// <param name="product">The Product used to find the inventory</param>
        /// <returns></returns>
        public ProductInventory GetProductInventory(Location location, Product product)
        {
            ProductInventory productInventory;

            using (var ctx = new VendorContext())
            {
                ProductInventorieService pIS = new ProductInventorieService(ctx);
                productInventory = pIS.GetInventory(location, product);
            }

            return(productInventory);
        }
        /// <summary>
        /// Fetches the inventory of the specified location
        /// </summary>
        /// <param name="locationName">Location's name used to retrive inventory</param>
        /// <returns>List of a location's inventory</returns>
        public List <ProductInventory> RetrieveInventoryByLocationName(string locationName)
        {
            List <ProductInventory> locationInventory;

            using (var ctx = new VendorContext())
            {
                ProductInventorieService pIS = new ProductInventorieService(ctx);
                locationInventory = pIS.FindProductInventoryByLocationName(locationName);
            }

            return(locationInventory);
        }
Example #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReviewsRepository" /> class.
        /// </summary>
        /// <param name="repositoryContext">The repository context.</param>
        /// <param name="mapper">The mapper.</param>
        /// <param name="sortHelper">The sort helper.</param>
        /// <param name="dataShaper">The data shaper.</param>
        public AverageRatingRepository(
            VendorContext repositoryContext,

            IMapper mapper,
            ISortHelper <ReviewsResponse> sortHelper,
            IDataShaper <ReviewsResponse> dataShaper)
            : base(repositoryContext)
        {
            this.mapper     = mapper;
            this.sortHelper = sortHelper;
            this.dataShaper = dataShaper;
        }
        /// <summary>
        /// Retreives a list of Orders made from a specifed location
        /// </summary>
        /// <param name="locationName">Name of the location the order was made from</param>
        /// <returns>A list of Orders made from a specifed location</returns>
        public List <Order> FindOrdersByLocationName(string locationName)
        {
            List <Order> customerOrders;

            using (var ctx = new VendorContext())
            {
                OrderService orderService = new OrderService(ctx);
                customerOrders = orderService.FindOrdersByLocationName(locationName);
            }

            return(customerOrders);
        }
Example #21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReviewsRepository" /> class.
        /// </summary>
        /// <param name="repositoryContext">The repository context.</param>
        /// <param name="mapper">The mapper.</param>
        /// <param name="sortHelper">The sort helper.</param>
        /// <param name="dataShaper">The data shaper.</param>
        public ReplyCountRepository(
            VendorContext repositoryContext,

            IMapper mapper,
            ISortHelper <CommentReplyResponse> sortHelper,
            IDataShaper <CommentReplyResponse> dataShaper)
            : base(repositoryContext)
        {
            this.mapper     = mapper;
            this.sortHelper = sortHelper;
            this.dataShaper = dataShaper;
        }
Example #22
0
        internal void RemoveLocations()
        {
            Console.WriteLine("Removing Locations");

            using var ctx = new VendorContext();

            LocationService locServ = new LocationService(ctx);

            locServ.RemoveAll();

            Console.WriteLine("Locations Removed");
        }
Example #23
0
        internal void RemoveSomeProducts()
        {
            Console.WriteLine("Removing Products");

            using var ctx = new VendorContext();
            ProductService s = new ProductService(ctx);

            s.RemoveByName("Stimpak");
            s.RemoveByName("Buffout");
            s.RemoveByName("10mm");

            Console.WriteLine("Products Removed");
        }
Example #24
0
        internal void AddSomeProducts()
        {
            Console.WriteLine("Creating Products");
            using var ctx = new VendorContext();

            ProductService s = new ProductService(ctx);

            s.Create("Stimpak", "Aid");
            s.Create("Buffout", "Aid");
            s.Create("10mm", "Ammo");

            Console.WriteLine("Products Created");
        }
Example #25
0
        internal void RemoveCustomer(string username)
        {
            Console.WriteLine($"Removing {username}");

            using (var ctx = new VendorContext())
            {
                CustomerService cS = new CustomerService(ctx);

                cS.RemoveByUsername(username);
            }

            Console.WriteLine($"{username} has been removed");
        }
        /// <summary>
        /// Stores a record of an order a customer has just purchased.  Saves information on
        /// what location the order was made from and the product that was purchased
        /// </summary>
        /// <param name="customer">Customer that is being registered as the purchaser</param>
        /// <param name="locationName">The name of the location the order was taken from</param>
        /// <param name="productName">The name of the product that was purchased</param>
        /// <returns>The Order record that was just saved</returns>
        public Order RegisterOrder(Customer customer, string locationName, string productName, int quantitySold)
        {
            Order newOrder;


            using (var ctx = new VendorContext())
            {
                OrderService orderService = new OrderService(ctx);
                newOrder = orderService.Create(customer, locationName, productName, quantitySold);
            }

            return(newOrder);
        }
Example #27
0
        internal void AddLocations()
        {
            Console.WriteLine("Creating Locations");

            using var ctx = new VendorContext();

            LocationService locServ = new LocationService(ctx);

            locServ.Create("The Mojave Wasteland");
            locServ.Create("The Capital Warehouse Store");
            locServ.Create("Diamond City Goods");

            Console.WriteLine("Locations Created");
        }
Example #28
0
        private void UpdateFirstCustomer(string oldUsername, string username)
        {
            Console.WriteLine($"Updating Customer {oldUsername}");

            using var ctx = new VendorContext();
            CustomerService cs = new CustomerService(ctx);

            Customer moddedCust = cs.FindByUsername(oldUsername);

            moddedCust.Username = username;

            cs.UpdateCustomer(moddedCust);

            Console.WriteLine($"Updated Customer's Name from {oldUsername} to {username}");
        }
Example #29
0
        internal void CreateCustomer(string username)
        {
            Console.WriteLine("Creating Bill");

            using (var ctx = new VendorContext())
            {
                CustomerService cS = new CustomerService(ctx);

                cS.Create(new Customer
                {
                    Username = "******",
                    Email    = "Just Bill",
                });
            }

            Console.WriteLine("Bill Has Been Created");
        }
        /// <summary>
        /// Retrieves a list of Orders that a customer has made
        /// </summary>
        /// <param name="username">Name of the Customer the order was made from</param>
        /// <returns>A Packet with the list of orders made from the specified Customer</returns>
        public Packet <Order> RetrieveOrdersByCustomerNameFromPacket(string username)
        {
            List <Order> customerOrders;

            using (var ctx = new VendorContext())
            {
                OrderService orderService = new OrderService(ctx);
                customerOrders = orderService.FindOrdersByCustomersName(username);
            }

            return(new Packet <Order>
            {
                Text = "Customer Orders retreived.",
                Status = PacketStatus.Pass,
                DataList = customerOrders
            });
        }
Example #31
0
 public IEnumerable<Vendor.Contract.Vendor> Index()
 {
     VendorContext context = new VendorContext();
     return context.GetAsync().Result;
 }
Example #32
0
        public void Main(string[] args)
        {
            VendorContext context = new VendorContext();

            //for (int i = 3; i < 20; i++)
            //{
            //    Vendor.Contract.Vendor vendor = new Contract.Vendor()
            //    {
            //        ID = i.ToString(),
            //        Name = string.Format("TestAccount{0}", i),
            //        Description = "FirstDocDBAccount",
            //        Website = "wwww.TestAccount.Docdb",
            //        LastModifiedDate = System.DateTime.UtcNow,
            //        IsPreffered = false,
            //        BlockVendor = false,
            //        Email = "*****@*****.**",
            //        KeyWords = "test unittest",
            //        Addresses = new VendorAddress[]
            //    {
            //        new VendorAddress()
            //        {
            //            Address1 = "Address1",
            //            Address2 = "Address2",
            //            City = "Bellevue",
            //            Country = "USA",
            //            Id = 2,
            //            LastModifiedDate = DateTime.UtcNow,
            //            PhoneNumber = "444-444-5858",
            //            State = "WA",
            //            ZipCode = "98000"
            //        }
            //    }
            //    };

            //    //context.SaveAsync<Contract.Vendor>(vendor).Wait();
            //}

            Vendor.Contract.Vendor vendor = new Contract.Vendor()
            {
                ID = "21",
                Name = "fivedevs",//string.Format("TestAccount{0}", i),
                FullName = "Five devs and dash",
                Description = "FirstDocDBAccount",
                Website = "wwww.TestAccount.Docdb",
                LastModifiedDate = System.DateTime.UtcNow,
                IsPreffered = false,
                BlockVendor = false,
                Email = "*****@*****.**",
                KeyWords = "test unittest",
                Addresses = new VendorAddress[]
            {
                    new VendorAddress()
                    {
                        Address1 = "Address1",
                        Address2 = "Address2",
                        City = "Bellevue",
                        Country = "USA",
                        Id = 2,
                        LastModifiedDate = DateTime.UtcNow,
                        PhoneNumber = "444-444-5858",
                        State = "WA",
                        ZipCode = "98000"
                    }
            }
            };

            context.SaveAsync<Contract.Vendor>(vendor).Wait();
            //var item = context.GetAsync("1");
            var item = context.GetAsync();
            //context.UpdateAsync(vendor).Wait();
            var result = context.GetByNameAsync("Test");
        }