コード例 #1
0
        public void newUserUI()
        {
            Console.WriteLine("Please enter your First Name, Last Name and Email");
            Console.WriteLine("First Name:");
            FirstName = GetUserInput();
            while (string.IsNullOrEmpty(FirstName))
            {
                Console.WriteLine("First Name can't be empty. Input your First Name");
                FirstName = GetUserInput();
            }
            Console.WriteLine("Last Name:");
            LastName = GetUserInput();
            while (string.IsNullOrEmpty(LastName))
            {
                Console.WriteLine("Last Name can't be empty. Input your First Name");
                LastName = GetUserInput();
            }
            Console.WriteLine("Email:");
            string Email = GetUserInput();

            while (string.IsNullOrEmpty(LastName))
            {
                Console.WriteLine("Last Name can't be empty. Input your First Name");
                LastName = GetUserInput();
            }
            Library.Customer newCustomer = new Library.Customer(FirstName, LastName, Email);

            storeRepo.AddCustomer(newCustomer);
        }
コード例 #2
0
        public ActionResult AddOrder(int Id)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Library.Customer customer = CustomerRepo.GetCustomerById(Id);
                    OrderRepo.AddOrder(new Lib.Order
                    {
                        CustomerId = customer.Id,
                        StoreId    = customer.StoreId,
                        TimePlaced = DateTime.Now
                    });

                    var order = OrderRepo.GetAllOrders().Last();
                    var inv   = StoreRepo.GetInventoryProducts(StoreRepo.GetInventory(customer.StoreId));
                    foreach (Lib.Product item in inv)
                    {
                        OrderRepo.AddProduct(order.Id, item);
                    }

                    return(RedirectToAction("Index", "Cart",
                                            new { @id = order.Id }));
                }
            }
            catch
            {
                return(RedirectToAction(nameof(Index)));
            }
            return(RedirectToAction(nameof(Index)));
        }
コード例 #3
0
        /// <summary>
        /// Finds customer from db to be updated, then switch values with the input'd customer values
        /// </summary>
        /// <param name="customer"></param>
        public void UpdateCustomer(Library.Customer customer)
        {
            Customers entity        = dbcontext.Customers.Find(customer.CustomerId);
            Customers modelToEntity = Mapper.MapCustomer(customer);

            dbcontext.Entry(entity).CurrentValues.SetValues(modelToEntity);
        }
コード例 #4
0
        public ActionResult Edit(int id, [Bind("FirstName,LastName,Id")] CustomerViewModel viewCustomer, IFormCollection collection)
        {
            // get the current id from tempdata to ensure the user hasn't modified the id that the page put out
            int tdId = (int)TempData.Peek("Customer");

            if (tdId != id && tdId != viewCustomer.Id)
            {
                // *ER add error message
                return(RedirectToAction(nameof(Index)));
            }

            // check the modelstat
            if (!ModelState.IsValid)
            {
                return(View(viewCustomer));
            }

            try
            {
                var customer = new Library.Customer(viewCustomer.FirstName, viewCustomer.LastName, viewCustomer.Id);
                _customerRepository.Update(customer);
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                ModelState.AddModelError("", "There was a problem updating the Customer");
                return(View(viewCustomer));
            }
        }
コード例 #5
0
        public void MostOrders()
        {
            float high = 0;
            float temp = 0;

            Library.Customer best = new Library.Customer();

            var customerRepo = new CustomerRepository(_dbContext);

            var customers = customerRepo.GetAll().ToList();
            var orders    = GetAllOrders();

            foreach (Library.Customer c in customers)
            {
                foreach (Library.Order o in orders.Where(ord => ord.CustomerId == c.Id))
                {
                    temp++;
                }

                if (temp > high)
                {
                    high = temp;
                    best = c;
                }

                temp = 0;
            }

            Console.WriteLine($"{best.FirstName + ' ' + best.LastName} had" +
                              $" the most orders with: {high}");
            Console.WriteLine();
        }
コード例 #6
0
        public void HighestSumTotal()
        {
            float high = 0;
            float temp = 0;

            Library.Customer best = new Library.Customer();

            var customerRepo = new CustomerRepository(_dbContext);

            var customers = customerRepo.GetAll().ToList();
            var orders    = GetAllOrders();

            foreach (Library.Customer c in customers)
            {
                foreach (Library.Order o in orders.Where(ord => ord.CustomerId == c.Id))
                {
                    var items    = GetOrderItems(o.Id).ToList();
                    var products = GetOrderProducts(items);

                    var orderTotal = OrderTotal(o.Id);

                    temp += orderTotal;
                }

                if (temp > high)
                {
                    high = temp;
                    best = c;
                }
            }

            Console.WriteLine($"{best.FirstName + ' ' + best.LastName} had" +
                              $" the highest \"Order Total\" sum: ${high}");
        }
コード例 #7
0
 public static DataAccess.Customer Map(Library.Customer customer) => new DataAccess.Customer
 {
     CustomerId      = customer.Id,
     FirstName       = customer.FirstName,
     LastName        = customer.LastName,
     DefaultLocation = customer.DefaultLocation
 };
コード例 #8
0
 public CustomerViewModel(Library.Customer customer, Library.Location store)
 {
     Id       = customer.Id;
     FullName = customer.FirstName + ' ' + customer.LastName;
     Birthday = customer.Birthday;
     Store    = store;
 }
コード例 #9
0
        // GET: Customers/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Library.Customer customer = Repo.SearchCustomersById((int)id);

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

            CustomerViewModel model = new CustomerViewModel
            {
                Id                = customer.CustId,
                FirstName         = customer.FName,
                LastName          = customer.LName,
                DateOfBirth       = customer.DateOfBirth,
                PrefLocNavigation = Repo.SearchLocationsById(customer.Loc)
            };

            return(View(model));
        }
コード例 #10
0
 public void EditCustomer(Library.Customer customer)
 {
     if (_db.Customer.Find(customer.CustomerId) != null)
     {
         _db.Customer.Update(CustomerMapper.Map(customer));
     }
 }
コード例 #11
0
 public ActionResult Create(Models.Customer newCustomer)
 {
     try
     {
         if (ModelState.IsValid)
         {
             Library.Customer newCustomerMapped = ManualMapper.ManMap2(newCustomer);
             //var newCustomerMapped2 = ManualMapper.ManMap(newCustomerMapped);
             Repo.InsertCustomer(newCustomerMapped);
         }
         else
         {
             return(View());
         }
         return(RedirectToAction(nameof(Index)));
     }
     catch (ArgumentException ex)
     {
         ModelState.AddModelError("Id", ex.Message);
         return(View());
     }
     catch
     {
         return(View());
     }
 }
コード例 #12
0
 public static Entities.Customer Map(Library.Customer customer) => new Entities.Customer
 {
     CustomerId             = customer.CustomerId,
     FirstName              = customer.FirstName,
     LastName               = customer.LastName,
     DefaultStoreNavigation = Map(customer.DefaultStore)
 };
コード例 #13
0
        // GET: Order
        public ActionResult Index(int Id)
        {
            if (CustomerRepo.ContainsId(Id))
            {
                ViewBag.customerId = Id;
                Library.Customer            customer    = CustomerRepo.GetCustomerById(Id);
                IEnumerable <Lib.Inventory> libInv      = StoreRepo.GetInventory(customer.StoreId);
                IEnumerable <Lib.Product>   libProducts = StoreRepo.GetInventoryProducts(libInv);

                IEnumerable <InventoryViewModel> ivm = libProducts.Select(x => new InventoryViewModel
                {
                    Id           = x.Id,
                    Name         = x.Name,
                    Price        = (decimal)x.Price,
                    Quantity     = libInv.First(i => i.ProductId == x.Id && i.StoreId == customer.StoreId).Quantity,
                    StoreName    = StoreRepo.GetStoreById(customer.StoreId).Name,
                    CustomerName = customer.FirstName + ' ' + customer.LastName
                });
                return(View(ivm));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
コード例 #14
0
 public static Entities.Customer Map(Library.Customer customer) => new Entities.Customer
 {
     Id          = customer.Id,
     FirstName   = customer.FirstName,
     LastName    = customer.LastName,
     PhoneNumber = customer.PhoneNumber,
     PurOrder    = customer.PurOrder.Select(Map).ToList()
 };
コード例 #15
0
 public static Customer Map(Library.Customer customer) => new Customer
 {
     Id        = customer.Id,
     FirstName = customer.FirstName,
     LastName  = customer.LastName,
     Birthday  = customer.Birthday,
     StoreId   = customer.StoreId,
 };
コード例 #16
0
 public static Customer Map(Library.Customer customer) => new Customer
 {
     CustomerId        = customer.CustId,
     FirstName         = customer.FirstName,
     LastName          = customer.LastName,
     PhoneNumber       = customer.PhoneNumber,
     DefaultLocationId = customer.DefaultStoreId
 };
コード例 #17
0
        public Library.Customer GetCustomerById(int customerId)
        {
            using var context = new project0Context(_dbContext);
            var dbCustomer  = context.Customers.FirstOrDefault(o => o.CustomerId == customerId);
            var appCustomer = new Library.Customer(dbCustomer.CustomerId, dbCustomer.FirstName, dbCustomer.LastName, dbCustomer.Email);

            return(appCustomer);
        }
コード例 #18
0
 /// <summary>
 /// Maps a Customer object to an entry in the database
 /// </summary>
 /// <param name="customer"></param>
 /// <returns></returns>
 public static Model.Customer MapCustomerToDbEntry(Library.Customer customer)
 {
     return(new Model.Customer
     {
         FirstName = customer.FirstName,
         LastName = customer.LastName
     });
 }
コード例 #19
0
 public Entities.Customer ParseCreator(Library.Customer creator)
 {
     return(new Entities.Customer()
     {
         FirstName = creator.FirstName,
         LastName = creator.LastName,
         PhoneNumber = creator.PhoneNumber
     });
 }
コード例 #20
0
 public static Customer Map(Library.Customer customer) => new Customer
 {
     Id          = customer.ID,
     StoreId     = customer.StoreId,
     FirstName   = customer.FirstName,
     LastName    = customer.LastName,
     Address     = customer.Address,
     PhoneNumber = customer.PhoneNumber,
 };
コード例 #21
0
 public static Library.Order Map(Entities.Orders order, Library.Customer custom) => new Library.Order
 {
     Id         = order.OrderId,
     CustomerId = order.CustomerId,
     Recipient  = custom,
     LocationId = order.LocationId,
     Ordered    = Map(order.OrderLine).ToList(),
     ItemCount  = MapDic(order.OrderLine),
     PlacedTime = (DateTime)order.PurchaseDate
 };
コード例 #22
0
        //Map business model to EF
        //object data --> Entity

        public static Entities.Customer MapCustomerWithEF(Library.Customer Ocustomer)
        {
            return(new Entities.Customer
            {
                Cid = Ocustomer.ID,
                Names = Ocustomer.Names,
                Addresses = Ocustomer.Address,
                Phone = Ocustomer.Phone
            });
        }
コード例 #23
0
        public void Create(Library.Customer customer)
        {
            var cust = new Customer()
            {
                FirstName = customer.FirstName, LastName = customer.LastName
            };

            _context.Add(cust);
            _context.SaveChanges();
        }
コード例 #24
0
        public void Update(Library.Customer customer)
        {
            // get customer from db
            var dbCust = _context.Customers.First(c => c.Id == customer.Id);

            // update names
            dbCust.FirstName = customer.FirstName;
            dbCust.LastName  = customer.LastName;
            // save changes
            _context.SaveChanges();
        }
コード例 #25
0
        /* Customer mapping */

        public static Entities.Customers MapCustomer(Library.Customer model)
        {
            Entities.Customers result = new Entities.Customers
            {
                CustomerId = model.CustomerId,
                FirstName  = model.FirstName,
                LastName   = model.LastName,
            };

            return(result);
        }
コード例 #26
0
        public static Library.Customer MapCustomer(Entities.Customers dbmodel)
        {
            Library.Customer result = new Library.Customer
            {
                CustomerId = dbmodel.CustomerId,
                FirstName  = dbmodel.FirstName,
                LastName   = dbmodel.LastName,
            };

            return(result);
        }
コード例 #27
0
 public static Customer Map(Library.Customer customer) => new Customer
 {
     Userid        = customer.Userid,
     Username      = customer.Username,
     Deflocationid = customer.Deflocationid,
     Haveorder     = customer.Haveorder,
     Dateplaced    = customer.Dateplaced,
     // Deflocation = Map(customer.Deflocation),
     // History = Map(customer.History).ToList(),
     // Orderdetails = Map(customer.Orderdetails).ToList(),
 };
コード例 #28
0
        public void UpdateCustomerDb(Library.Customer customer)
        {
            using var context = new AquariumContext(_contextOptions);
            var dbCust = context.Customers
                         .Where(c => c.CustomerId == customer.CustomerId)
                         .FirstOrDefault();

            dbCust.FirstName = customer.FirstName;
            dbCust.LastName  = customer.LastName;
            dbCust.Email     = customer.Email;
            context.SaveChanges();
        }
コード例 #29
0
        public void AddToCustomerDb(Library.Customer customer)
        {
            using var context = new AquariumContext(_contextOptions);
            var newCust = new DataModel.Customer()
            {
                FirstName = customer.FirstName,
                LastName  = customer.LastName,
                Email     = customer.Email
            };

            context.Customers.Add(newCust);
            context.SaveChanges();
        }
コード例 #30
0
        // Get orders from the database
        public List <Library.Order> GetCustOrders(Library.Customer customer)
        {
            using var context = new AquariumContext(_contextOptions);
            var dbOrders = context.Orders
                           .Where(o => o.CustomerId == customer.CustomerId);
            var orders = new List <Library.Order>();

            foreach (var obj in dbOrders)
            {
                orders.Add(GetOrderById(obj.OrderId));
            }
            return(orders);
        }