Beispiel #1
0
 /*
 public void updateCustomer(int id, string fname, string lname, string address, string country,
     string phone, string email, LogInfo logInfo, string payStatus, DiscountGroup discountGroup)
 {
     throw new NotImplementedException();
 }
 */
 public void updateCustomer(Customer customer)
 {
     CustomerCtr custCtr = new CustomerCtr();
     List<MLogInfo> mLogInfos = new List<MLogInfo>();
     foreach (LogInfo logInfo in customer.LogInfos)
     {
         mLogInfos.Add(new MLogInfo
         {
             ID = logInfo.ID,
             LoginName = logInfo.LoginName,
             Password = logInfo.Password
         });
     }
     custCtr.update(customer.ID, customer.FName, customer.LName, customer.Address, customer.Country,
         customer.Phone, customer.Email, mLogInfos, customer.DiscountGroup.ID, customer.PaymentStatus);
 }
Beispiel #2
0
 public List<Customer> getAllCustomers()
 {
     CustomerCtr custCtr = new CustomerCtr();
     List<MCustomer> mCusts = custCtr.getAll();
     List<Customer> custs = new List<Customer>();
     foreach (MCustomer mCust in mCusts)
     {
         List<LogInfo> logInfos = new List<LogInfo>();
         foreach (MLogInfo mLogInfo in mCust.LogInfos)
         {
             logInfos.Add(new LogInfo
             {
                 ID = mLogInfo.ID,
                 LoginName = mLogInfo.LoginName,
                 Password = mLogInfo.Password
             });
         }
         DiscountGroup discoGroup = new DiscountGroup
         {
             ID = mCust.DiscountGroup.ID,
             Name = mCust.DiscountGroup.Name,
             Discount = mCust.DiscountGroup.Discount
         };
         Customer cust = new Customer()
         {
             ID = mCust.ID,
             FName = mCust.FName,
             LName = mCust.LName,
             Address = mCust.Address,
             Country = mCust.Country,
             Phone = mCust.Phone,
             Email = mCust.Email,
             LogInfos = logInfos,
             PaymentStatus = mCust.PaymentStatus,
             DiscountGroup = discoGroup
         };
         custs.Add(cust);
     }
     return custs;
 }
Beispiel #3
0
        /*
        public void addCustmer(Customer customer)
        {
            CustomerCtr custCtr = new CustomerCtr();
            int newCust = custCtr.add(customer.FName, customer.LName, customer.Address, customer.Country, customer.Phone,
                customer.Email, customer.DiscountGroup.ID, customer.PaymentStatus);
            LogInfoCtr logInfoCtr = new LogInfoCtr();
            // email is used as login name for everyone

            logInfoCtr.add(customer.Email, customer.LogInfo.Password, newCust);
        }
        */
        public Customer getCustomer(int id)
        {
            CustomerCtr custCtr = new CustomerCtr();
            MCustomer mCust = null;
            try
            {
                mCust = custCtr.get(id, false);
            }
            catch (NullReferenceException)
            {
            }

            Customer cust = new Customer();
            if (mCust != null)
            {
                List<LogInfo> logInfos = new List<LogInfo>();
                foreach (MLogInfo mLogInfo in mCust.LogInfos)
                {
                    logInfos.Add(new LogInfo
                    {
                        ID = mLogInfo.ID,
                        LoginName = mLogInfo.LoginName,
                        Password = mLogInfo.Password
                    });
                }
                DiscountGroup discoGroup = new DiscountGroup
                {
                    ID = mCust.DiscountGroup.ID,
                    Name = mCust.DiscountGroup.Name,
                    Discount = mCust.DiscountGroup.Discount
                };
                cust.ID = mCust.ID;
                cust.FName = mCust.FName;
                cust.LName = mCust.LName;
                cust.Address = mCust.Address;
                cust.Country = mCust.Country;
                cust.Phone = mCust.Phone;
                cust.Email = mCust.Email;
                cust.LogInfos = logInfos;
                cust.PaymentStatus = mCust.PaymentStatus;
                cust.DiscountGroup = discoGroup;

            }
            return cust;
            //throw new SystemException("No Customer model was returned.");
        }
Beispiel #4
0
        public List<Booking> getAllBookings()
        {
            List<Booking> bookings = new List<Booking>();
            BookingCtr bCtr = new BookingCtr();
            List<MBooking> bs = bCtr.getAllBooking();
            if (bs.Count != 0)
            {
                foreach (MBooking b in bs)
                {
                    Booking bk = new Booking();
                    bk.Id = b.Id;
                    bk.createDate = b.createDate.Value.ToString("dd/MM/yyyy");
                    Customer cust = new Customer() { ID = b.customer.ID, name = b.customer.FName + " " + b.customer.LName };
                    bk.customer = cust;
                    bk.cId = b.customer.ID;
                    bk.payStatus = b.creaditCard;
                    bk.totalPrice = b.totalPrice.Value;
                    bk.tripStart = b.tripStart.Value.ToString("dd/MM/yyyy HH:mm");
                    if (b.bookinglines.Count != 0)
                    {
                        foreach (MBookingLine bl in b.bookinglines)
                        {
                            BookingLine l = new BookingLine();
                            l.price = bl.price.Value;
                            l.quantity = bl.quantity.Value;
                            l.time = bl.time.Value;
                            bk.bookinglines.Add(l);
                            BatteryType bt = new BatteryType();
                            bt.ID = bl.BatteryType.id;
                            bt.name = bl.BatteryType.name;
                            l.BatteryType = bt;
                            Station s = new Station();
                            s.Id = bl.Station.Id;
                            s.Name = bl.Station.name;
                            s.Address = bl.Station.address;
                            s.Country = bl.Station.country;
                            l.station = s;

                        }
                        bk.startStationId = b.bookinglines.First().Station.Id;
                    }
                    bookings.Add(bk);
                }
            }

            return bookings;
        }