Esempio n. 1
0
 public MCustomer(int id, string fName, string lName, string address, string country,
     string phone, string email, ICollection<MLogInfo> logInfos,
     PType pType, MDiscountGroup discountGroup, string payStatus)
     : base(id, fName, lName, address, country, phone, email, logInfos, pType)
 {
     DiscountGroup = discountGroup;
     PaymentStatus = payStatus;
 }
Esempio n. 2
0
 public static DiscoutGroup buildDiscountGroup(MDiscountGroup mDiscountGroup)
 {
     return new DiscoutGroup()
     {
         Id = mDiscountGroup.ID,
         name = mDiscountGroup.Name,
         dgRate = mDiscountGroup.Discount
     };
 }
Esempio n. 3
0
 // delete LoginInfoes from arguments
 public int addNewRecord(string fName, string lName, string address, string country, string phone, string email, MDiscountGroup discountGroup, string payStatus)
 {
     using (TransactionScope transaction = new TransactionScope((TransactionScopeOption.Required)))
     {
         try
         {
             int newId = -1;
             using (ElectricCarEntities context = new ElectricCarEntities())
             {
                 try
                 {
                     int max;
                     try {
                         max = context.People.Max(cust => cust.Id);
                     } catch {
                         max = 0;
                     }
                     newId = max + 1;
                     context.People.Add(new Customer()
                     {
                         Id = newId,
                         fName = fName,
                         lname = lName,
                         address = address,
                         country = country,
                         phone = phone,
                         email = email,
                         // together and after customer creation add logInfo and include returned
                         // person Id in there
                         // LoginInfoes = DLogInfo.buildLogInfos(logInfos),
                         // TODO: change to enum
                         pType = PType.Customer.ToString(),
                         payStatus = null,
                         // TODO: not considering putting the ICollection<Booking> Bookings on Customer record creation
                         // TODO: dgId or DiscountGroup, using dgId
                         dgId = discountGroup.ID,
                         // DiscoutGroup = DDiscountGroup.buildDiscountGroup(discountGroup)
                     });
                     context.SaveChanges();
                 }
                 catch (Exception e)
                 {
                     throw new SystemException("Cannot add new Customer record " +
                         " with an error " + e.Message);
                 }
             }
             transaction.Complete();
             return newId;
         }
         catch (TransactionAbortedException e)
         {
             throw new SystemException("Cannot finish transaction for adding Customer " +
                " with an error " + e.Message);
         }
     }
 }
Esempio n. 4
0
 public void updateRecord(int id, string fName, string lName, string address, string country, string phone, string email, ICollection<MLogInfo> logInfos, MDiscountGroup discountGroup, string payStatus)
 {
     using (TransactionScope transaction = new TransactionScope((TransactionScopeOption.Required)))
     {
         try
         {
             using (ElectricCarEntities context = new ElectricCarEntities())
             {
                 try
                 {
                     Customer cust = (Customer) context.People.Find(id);
                     cust.fName = fName;
                     cust.lname = lName;
                     cust.address = address;
                     cust.country = country;
                     cust.phone = phone;
                     cust.email = email;
                     // to be or not to be, cos LoginInfoes is 'virtual' in Customer EF model
                     cust.LoginInfoes = DLogInfo.buildLogInfos(logInfos, cust.LoginInfoes);
                     foreach (LoginInfo logInfo in cust.LoginInfoes)
                     {
                         logInfo.pId = cust.Id;
                         logInfo.Person = cust;
                     }
                     cust.dgId = discountGroup.ID;
                     cust.payStatus = payStatus;
                     context.SaveChanges();
                 }
                 catch (Exception e)
                 {
                     throw new SystemException("Cannot update Customer record " + id
                         + " with message " + e.Message);
                 }
             }
             transaction.Complete();
         }
         catch (TransactionAbortedException e)
         {
             throw new SystemException("Cannot finish transaction for updating Customer " +
                " with an error " + e.Message);
         }
     }
 }